cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Microsoft
Microsoft

Commenting Code

Is there a way to add comments to a code set or a code line?

3 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: Commenting Code

There's no way to comment code directly in the formulas. One workaround that I've used for complex formulas is to break it down in components (using context variables), and use some If(false) statements that do nothing except to allow for some information to be added. For example, in the app below, the expression button used to calculate the roots for the equation is a little complicated:

ForumPost-App.png

I could have a single expression to calculate both roots, but that would be quite complex:

UpdateContext({
    root1: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) < 0, 0/0, (-Value(TextInputB.Text)+Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text))),
    root2: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) <= 0, 0/0, (-Value(TextInputB.Text)-Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text)))
})

If I break it down into sub-expressions, I can interpolate some "comments" to make it more readable:

If(false, "Save control values in variables for easier manipulation");
UpdateContext({a:Value(TextInputA.Text), b:Value(TextInputB.Text), c:Value(TextInputC.Text)});

If(false, "Calculate the value for the discriminant");
UpdateContext({delta: b*b - 4*a*c});

If(false, "Calculate the roots");
UpdateContext({
    root1: If(delta < 0, 0/0, (-b+Sqrt(delta))/(2*a)),
    root2: If(delta <= 0, 0/0, (-b-Sqrt(delta))/(2*a))
})

View solution in original post

Highlighted
Community Champion
Community Champion

Re: Commenting Code

Hi everybody,

I have learned another way you can include comments. Normally you chain actions with a semi-colon. But you could also write text where an action would go, then set it off with a semi-colon. It won't do anything, but it provides the comment you want.

 

Example:

"Add 1 to the current score each time you press the button";

Set(score,score+1)

 

Here's another example of it in practice: 
https://youtu.be/j30xOM5OmRE?t=7m57s

 

@Anonymous @CarlosFigueira @ManishM

Microsoft Employee
@8bitclassroom

View solution in original post

Highlighted
Super User II
Super User II

Re: Commenting Code

Great news, this was released yesterday

https://youtu.be/dnreydsFSHw

View solution in original post

11 REPLIES 11
Highlighted
Power Apps
Power Apps

Re: Commenting Code

There's no way to comment code directly in the formulas. One workaround that I've used for complex formulas is to break it down in components (using context variables), and use some If(false) statements that do nothing except to allow for some information to be added. For example, in the app below, the expression button used to calculate the roots for the equation is a little complicated:

ForumPost-App.png

I could have a single expression to calculate both roots, but that would be quite complex:

UpdateContext({
    root1: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) < 0, 0/0, (-Value(TextInputB.Text)+Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text))),
    root2: If(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text) <= 0, 0/0, (-Value(TextInputB.Text)-Sqrt(Value(TextInputB.Text)*Value(TextInputB.Text) - 4*Value(TextInputA.Text)*Value(TextInputC.Text)))/(2*Value(TextInputA.Text)))
})

If I break it down into sub-expressions, I can interpolate some "comments" to make it more readable:

If(false, "Save control values in variables for easier manipulation");
UpdateContext({a:Value(TextInputA.Text), b:Value(TextInputB.Text), c:Value(TextInputC.Text)});

If(false, "Calculate the value for the discriminant");
UpdateContext({delta: b*b - 4*a*c});

If(false, "Calculate the roots");
UpdateContext({
    root1: If(delta < 0, 0/0, (-b+Sqrt(delta))/(2*a)),
    root2: If(delta <= 0, 0/0, (-b-Sqrt(delta))/(2*a))
})

View solution in original post

Highlighted
Microsoft
Microsoft

Re: Commenting Code

@CarlosFigueira Thanks for the workaround solution Man Wink. It is time for the Dev team to add the ability to comment code in a direct way.

Highlighted
Anonymous
Not applicable

Re: Commenting Code

Something I've just started to use thanks to the new global var Set() function is e.g.

 

Set(c_icn_Save_Props_OnSelect,"### TODO: Some comment here ###")

 

 ... note the "c_" prefix for comments and a name to reflect the object/method (debatable usage esp. if object name is changed!) .

 

I can then review-and link to-all of my comments from one place (the Variables (Experimental) tab).

Highlighted
Anonymous
Not applicable

Re: Commenting Code

@CarlosFigueira thank for the workaround! That is very clever! 

 

One thing that worries me though, wouldn't these ifs add more load on the app when we are talking about complex apps with multiple screens and complicated formulas?

Highlighted
Community Champion
Community Champion

Re: Commenting Code

Hi everybody,

I have learned another way you can include comments. Normally you chain actions with a semi-colon. But you could also write text where an action would go, then set it off with a semi-colon. It won't do anything, but it provides the comment you want.

 

Example:

"Add 1 to the current score each time you press the button";

Set(score,score+1)

 

Here's another example of it in practice: 
https://youtu.be/j30xOM5OmRE?t=7m57s

 

@Anonymous @CarlosFigueira @ManishM

Microsoft Employee
@8bitclassroom

View solution in original post

Highlighted
Memorable Member
Memorable Member

Re: Commenting Code

@mr-dang

Thanks for sharing. I will definitely try that. However I just hope that all this workarounds for comments will not stop PG to implement proper comments in the code

Highlighted
Power Apps
Power Apps

Re: Commenting Code

Don't worry, it will not stop the team from implementing comments - it should be coming soon. Thanks for the feedback!

Highlighted
Memorable Member
Memorable Member

Re: Commenting Code

@CarlosFigueira

Thank you... We can't wait for it

Highlighted
Anonymous
Not applicable

Re: Commenting Code

@CarlosFigueira
Any news ?

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,368)