Christopher Benson-Manica wrote:
How do you indent your switch statements? My boss prefers
switch(x) {
case 1:
...
case 2:
...
default:
...
}
while I am steadfastly (stubbornly?) clinging to
switch(x) {
case 1:
...
case 2:
...
default:
...
}
I agree with your boss, who is obviously a person of skill and
importance. Most disagree with me and he. My argument is that
the case labels are really goto labels in disguise, and should be
easily discerned on reading. I will only indent case labels when
a nested case is in effect, i.e. I am maintaining two distinct
case indentation levels with switches. Thus the base level cases
are pulled out to the extreme left column.
To me, indentation is used to make finding the immediate
controlling statement easy, in this case the switch, where all the
decisions were made.
I will often have code snippets that look like:
switch (foo) {
case 0: bar(); break;
case 1: baz(); break;
default: punt(); break;
} /* switch */
If we are executing foo, and wonder why we got there, we just look
north and find the switch statement, unencumbered by meaningless
verbiage. For the particular case being executed, we look north
on the left hand column. All this is especially worthwhile IMO in
long complex switch statements, such as found in many state
machines.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!