Why is forced indentation of the code a bad thing? I mean, are there people who don't indent their code?
Name:
Anonymous2007-09-13 23:23 ID:yMqVHrFS
The problem with braces is you end up with two ways that blocks of code are delimited -- there's the visual delimiter, which humans recognize, and there's the "real" delimiter, which the computer does. This is redundant, and if you're not paying attention you can introduce subtle bugs that way.
for (i = 0, j = 2; i < 10; i++, j++) {
if (i == 4) {
printf("Oh my god, i is four.\n");
if (j == 3) {
printf("Zounds, j is three.\n");
}
for (k = 0; k < i; k++)
if (a[k] == j) {
printf("cocks\n");
}
}
}
Obviously this code doesn't do anything super-important, but it probably took a moment to figure out what it actually does when you look at the braces -- versus what it *should* do considering the indentation. Maybe the programmer missed a close brace at the top, the compiler complained, and he stuck it in the wrong place. Or maybe that 'if' really was supposed to be nested. Who knows.
The point I'm making here is, even if your language doesn't use indentation (which most don't), *you* are most likely still using it as a perceptual block delimiter, and that is a Bad Thing. When the language is interpreting the whitespace, that's GOOD because it means what you see is what you get.