|
I'm sure this has been argued to death but the counter argument is invisible formatting changing behavior is a bad thing. Sure if you get your entire team to use spaces or the same tabs great but passing open source code around to lots of programmers some of which use tabs and some of which use spaces ends up leading to wasted debugging time when someone used a tab where they should have used a space or visa versa. On top of that I find it invaluable to be able to space out debugging code. Example void SomeFunc() {
int x = doSomething1(1, 2, 3, 4);
int y = doSomething1(4, 5, 6, 8);
int z = doSomething1(5, 6, 7, 9);
printf("xyz=%d,%d,%d", x, y, z);
int a = doSomething1(0, 2, 3, 4);
int b = doSomething1(1, 5, 6, 8);
int c = doSomething1(2, 6, 7, 9);
printf("abc=%d,%d,%d", a, b, c);
int d = doSomething1(6, 2, 3, 4);
int e = doSomething1(5, 5, 6, 8);
int f = doSomething1(7, 6, 7, 9);
printf("def=%d,%d,%d", d, e, f);
return x * y * z + a * b * c + d * e * f;
}
vs void SomeFunc() {
int x = doSomething1(1, 2, 3, 4);
int y = doSomething1(4, 5, 6, 8);
int z = doSomething1(5, 6, 7, 9);
printf("xyz=%d,%d,%d", x, y, z);
int a = doSomething1(0, 2, 3, 4);
int b = doSomething1(1, 5, 6, 8);
int c = doSomething1(2, 6, 7, 9);
printf("abc=%d,%d,%d", a, b, c);
int d = doSomething1(6, 2, 3, 4);
int e = doSomething1(5, 5, 6, 8);
int f = doSomething1(7, 6, 7, 9);
printf("def=%d,%d,%d", d, e, f);
return x * y * z + a * b * c + d * e * f;
}
On a long functions I find it much easier to see/find/delete the debug print lines by indenting them separate from the real logic but I can't do that on any language that enforces code blocks by indentation.Commenting out also because an issue void SomeFunc(int v) {
bool doit = v > 5;
if (doit)
{
DoSomething();
DoSomethingElse();
DoSomethingOther();
}
}
For testing I often want to comment out the if void SomeFunc(int v) {
bool doit = v > 5;
//if (doit)
{
DoSomething();
DoSomethingElse();
DoSomethingOther();
}
}
If I was in python I can't do that def SomeFunc(v):
doit = v > 5
#if doit
DoSomething()
DoSomethingElse()
DoSomethingOther()
Error! I have to format the whole function just to comment out a line for testing. Yes in this case I could put `if true` (then requiring two changes instead of one) but there are plenty of other cases where code blocks by indent make it really annoying to work with my code.So no, significant indentation is not a good thing. |
I guess you've developed a habit where you're completely OK with having incorrect indentation a lot of the time, whereas I can't stand it. Just because it's easier to read for you doesn't make it easier for everyone, especially beginners.