Tuesday, 20 August 2013

Using curly braces to separate code in C++

Using curly braces to separate code in C++

One thing I really like about IDEs is the ability to "minimize" sections
of code, so that:
while(conditions){
// Really long code...
}
Can become:
while(conditions){ // The rest is hidden
My question is whether or not something like this would be acceptable
formatting
// Code
{
// More code
}
// Code
I understand that anything done inside the brackets would have that
limited scope, but I can also edit variables in the outer scope as well.
So, for a short, unnecessary example
int x = 1;
{ // Create new variable, add and output
int y = 2;
cout << x + y;
}
Would become:
int x = 1;
{ // Create new variable, add and output (The rest of the code is hidden)
So would this be acceptable, or shunned?
Thanks.

No comments:

Post a Comment