Power Apps Guidelines For Improving Code Readability

Power Apps Guidelines For Improving Code Readability
Table Of Contents:
1. Apply Automatic Formatting
2. Use The WITH Function
3. Flatten Nested IF Functions
4. Have A Consistent Naming Convention For Controls & Variables
5. Join Text Strings And Variables
6. Choose Consistent Logical Operators
7. Remove IF Statements When The Result Is A True Or False Value
8. Simplify Logical Comparisons When Evaluating A Boolean
9. Substitute The Self Operator For The Current Control Name
10: Alphabetize Patch & UpdateContext Function Arguments




1. Apply Automatic Formatting

The formula bar’s format text command applies indentation, spacing and line-breaks to Power Apps code.   Well-formatted code has two benefits.  It is easier to read and quicker to spot mistakes. Use the format text command to achieve a consistent coding style throughout a canvas app. A consistent coding style makes it easier for developers to work together on an app.




2. Use The WITH Function

Power Apps With function makes long formulas more readable.  For example, this formula which does not use the With function calculates the monthly mortgage payment for a house:


The mortgage calculation formula cannot be interpreted at-a-glance. It takes effort to parse. Compare it to the Power Apps code example using the With function. The formula is now human-readable because any complexity moved into one-time variables.

Power Apps With function code example




3. Flatten Nested IF Functions

Nested IFs are when multiple IF functions are placed inside one other. The more levels a nested IF contains the harder it becomes to understand.  Use a flat structure whenever possible to improve code readability. 




4. Have A Consistent Naming Convention For Controls & Variables

Every control should follow a naming convention that includes the control type, the screen it is located on and the purpose of the control. Variables should also have a standard format that includes their scope and purpose.




5. Join Text Strings And Variables

Combining text can be done multiple ways in Power Apps: the & operator, the Concatenate function or $-String notation.  Choose one way of doing it and be consistent.




6. Choose Consistent Logical Operators

The logical operator And can be written 3 different ways: And, And(), &&.  There are often many ways to do the same thing in Power Apps code.  It’s OK to choose any option from the Power Apps code examples below but be consistent.




7. Remove IF Statements When The Result Is A True Or False Value

An IF statement that results in true or false is not necessary to write. Get rid of the IF statement and only write the logical comparison




8. Simplify Logical Comparisons When Evaluating A Boolean

A boolean value itself can be used as an argument to the IF function.  It is not necessary to write a logical comparison.




9. Substitute The Self Operator For The Current Control Name

The Self operator is a concise way to access properties of the current control. Use Self instead of the full control name to make code quicker to understand.




10. Alphabetize Patch & UpdateContext Function Arguments

When the Patch function have a large number of fields it takes more time to find and update them.  Use alphabetical order so the desired field can be quickly located.  This technique can also be applied to the UpdateContext function.





Questions?

If you have any questions about Power Apps Guidelines For Improving Code Readability please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments