Possible Duplicate:
Why don't people indent C++ access specifiers/case statements?
I have a syntax question... not about the how, but rather the why. Many IDEs such as Eclipse and Qt Creator automatically indent a switch
like this:
Day randomDay = getRandomDay(); /* returns 'enum Day' */
switch (randomDay) {
default:
case Monday:
/* ... */
break;
case Tuesday:
/* ... */
break;
/* ... */
}
I've always found that this is inconsistent with general code indentation rules and I prefer to do this:
Day randomDay = getRandomDay(); /* returns 'enum Day' */
switch (randomDay) {
default:
case Monday:
/* ... */
break;
case Tuesday:
/* ... */
break;
/* ... */
}
Similarly, C++ class definitions are often indented like this:
class MyClass {
public:
/* ... */
}
As opposed to:
class MyClass {
public:
/* ... */
}
Why have some people chosen not to indent the case
statements?
Code styles are like assholes. Everyone has one but only few people like the ones of other people.
This applies here, too. Some people liked it and thus did it when writing the indentation logic for an IDE. Most good IDEs have an option to configure this behavior though.
A possible reason for this style is that it seems to be common to not indent labels - and cases are a special kind of labels.
This is purely a personal preference thing. Indenting levels, tabs vs. spaces, and curly-bracket placement are, and will always be, the topic of programmer flame wars.
Certain editors or IDEs have defaults which are setup according to "common" conventions among certain programmers in the target audience. If you don't like the defaults, there almost always a way to customize it.
If you are working on a team of programmers, you'll have to decide on certain conventions, otherwise, you'll end up reformatting eachother's code until the end of time!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With