The second one, I don't brace things unnecessarily but I don't like putting multiple statements on one line. I do for switches though because otherwise they can be really long. Example:
1 2 3 4 5 6 7
switch (expression) {
case one: statement; break;
case two: statement; break;
case three: statement; break;
case four: statement; break;
default: break;
}
I added a fourth, a variant on the third. It is really surprising me how many people are preferring the second - I would have though the first would be picked most since I learned that that was better from these very forums.
Not sure how the first would be better unless your talking about style wise, which probably is true because I see more people use that style then any other.
I'm still quite new compared to most but the only advantage I see from the first one is it minimizes the risk of forgetting to make it a compound/block statement when you add more statements to it. Which is kind of trivial and a easy fix, but I am sure it happens.
That is exactly why the first is preferred. While it is indeed a trivial and easy fix, do you think it is trivial and easy to find the cause of a bug as a result of that? ;)
;p true don't use getters and setter kids, and stay off drugs. Anyways ya it was just for example. Though I do see a large amount of people use them even though they defeat the purpose of encapsulation and OOP in general. Though I can't blame them because I still use them sometimes when the project is just something trivial that I am doing.
By the way, ¿what do you use to maintain that alignment?
I just manually space it - I haven't found an IDE that knows how to align it properly and I don't feel like writing a script for it myself because it's a rare task. The other issue is that it would be difficult for an IDE or script to align the related parts so things visually line up rather than just identifiers and syntax elements lining up.
Also, thanks for pointing out that typo (which was made obvious by the alignment, lol)