Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
CharByte7158yI do the second when I'm making the function, when I'm happy with it and it's working I change it to the first.
-
@LucaScorpion Both are standards in C and C++. You do what's already in the code base.
-
Incidentally, third type like the GNU people:
if (condition)
{
function(blah);
}
Indent 2 for curlies, 4 for body. -
Used to do the second one but after working on way too much Java is think I'm now the first
-
beverest358ydid the second, now I do the first. for some reason when I switched I felt like a wizard.
-
I use the first one... I just hate using a whole line for a single curly bracket. No need. Also it looks more clean, optimized and sensible.
-
Wabby10348yFormer.
However, for the sanity of my staff, I have recently started training myself to do the latter.
All this conforming to standards and best practices bullshit. -
johnc456708yLatter.
I find it makes matching up the braces easier if I'm looking for them at the same indentation. -
-bgm-3178yVisual Studio refactors to the latter one automatically when coding in C#/.NET mvc.
But when I'm not coding for work I'm the former. -
@Wabby How does this apply to best practices? It has absolutely no impact. It's a first world programmer bugbear.
-
Bikonja23868yDepends on which language I'm using, but if given he choice - latter because it's easier to see whether the if has a block in curly braces or just a one liner.
Imagine:
if (expression)
statement1;
statement2;
}
statement3;
in some bigger chunk of code (with the opening curly)... The indentation can easily fool you into thinking both 1 and 2 are gonna execute only if the expression is true... So I think the one line for the opening brace is worth it, otherwise I'd say go for:
if (expression) {
statement1; }
statement2;
to save the extra line for the closing curly, too.
Related Rants
I'm the former...
undefined
two types of people
syntax