We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
push/pop syntax indent (Read 2712 times)
push/pop syntax indent
Oct 9th, 2006, 7:09pm
 
I was wondering (about 5 mins ago) if there would be some benefit to having the push/pop syntax indent (auto format) stuff between the 2 calls. I think it probably makes it easier to read the code.

pushMatrix();
 translate(100, 100);
 sphere(20);
popMatrix();

ira
Re: push/pop syntax indent
Reply #1 - Oct 9th, 2006, 8:31pm
 
You use a simple block to achieve this.

pushMatrix();
{
 translate(100, 100);
 sphere(20);
}
popMatrix();
Re: push/pop syntax indent
Reply #2 - Oct 9th, 2006, 11:40pm
 
This is a clever hack, but it doesn't seem like the best practice.
Re: push/pop syntax indent
Reply #3 - Oct 11th, 2006, 12:58pm
 
Ira wrote on Oct 9th, 2006, 11:40pm:
This is a clever hack, but it doesn't seem like the best practice.


it s not such a big deal to open another stack frame. i wouldn t consider it bad practice. besides writing readable code is always good practice Wink

the alternative is to hack the auto-format and THAT is a bad hack.
Re: push/pop syntax indent
Reply #4 - Oct 11th, 2006, 3:35pm
 
my concern would be that new coders might get confused by the use of the block in this context-looks close to a function now. Rather than hacking auto-format, I was thinking more on the line of incorporating the indent as part of 1.0
Re: push/pop syntax indent
Reply #5 - Oct 17th, 2006, 6:55pm
 
I recommend this formatting:

Code:
pushMatrix();
translate(100, 100);
sphere(20);
popMatrix();


This is the spacing I've seen in all the OpenGL Programming books I've read. You can separate the levels by adding a line space before the pushMatrix() and after the popMatrix().

I would never show my students the { } additional syntax. It's not consistent with what they know about functions and blocks.
Re: push/pop syntax indent
Reply #6 - Jan 5th, 2007, 7:42am
 
Sorry for digging up this old thread.

I've experimented with bracketing in matrix pushes, and the result is simply not a good way to go.

This is especially true if you ever needed to define a variable inside the block, then suddenly needed it after popMatrix(); What happens is the compiler will not find it, since the variable only existed in that block!

That is quite messy, as you can see..
Page Index Toggle Pages: 1