Why space-indenting is bad

My belief

Me personally, I think, there should be as much freedom given to the people as possible. This also includes the programmers. When someone gives you a piece of code, it should only carry the information about the algorithm, not the visual layout of the code itself. This is because every single person in this world has a a different way of seeing things and what is considered to be aesthetic by one will certainly not be considered so by the others.

Who is to set the "correct" number?

Here comes the problem, if you decide to indent by spaces, how many space characters do you consider to be "one indent level"? Two? Four? You better convience the other space-indenters to use the same value or else, editing their code could be a real pain in the ass. With tabs you can specify you own favourive value and the other can do as well. No problem here.

Indent as a LOGICAL thing

Now that I've used the words "indent level", I hope you all agree that the whole indent stuff is done only to ease the programmer's job of seeing what's nested and what's not. Even the information on how much it's nested is important. You have a function declaration at indent-level 0. Then, all of it's code is exactly one level "deeper". If you use the "if" construct, all of the code which belongs to that "if" should be indented one more level. This may go on. Now you can see that we can assign a number specifying the "level-of-indent" to each line (0, 1, 2, ...). Looks like there's a need for some meta-character telling us how much to indent. Let's make it the tab! We can also use a single space but that kind of clears the difference between a "regular space" and the "indent space". Let's use double-space then... ...or the tripple-space? ...or n-space? Come on! Do you really think you're the best programmer ever to tell the others how many spaces to use?

Brain-dead cases

There may be some other reasons to use spaces, let me illustrate it with an example:

void SomeVeryVeryExtraLongFunctionName(int arg1,
                                       void arg2,
                                       long arg3)

What the hell is that? Sure, the only way to make it look like this on all machines is to use spaces, no question. But are you sure you want to use this shit anyway? First, using such a long name for a function (or variable) is a sign of bad design and no experience. If you still want to keep the name that long, what's so wrong about:

void SomeVeryVeryExtraLongFunctionName(int arg1,
        void arg2,
        long arg3)

...or even...

void SomeVeryVeryExtraLongFunctionName(
        int arg1,
        void arg2,
        long arg3)

Is there a special reason to keep the argument list together? Even when there is, is there a reason to keep the whole thing at the very right-hand part of the screen? I don't think so.

Now imagine you want to rename the function. I don't know how about you but I would rather shoot myself in the head than adjust ALL the spaces in the function declaration and ALL the spaces in the function calls.

Focus on yourself first

This reminds me of a friend of mine, who just laughs at the secretaries who don't know how to use tabs (or similar function) in Word to align text in the document. They just hold the spacebar until the cursor is "there", write the text, break line and hold down the spacebar again to get to the same position on the next line. This really IS stupid! The best part of this story is that this friend laughs at them while he does exactly the same stupid thing! He writes the code in the way I've shown above (the "fill the space with spaces to have all arguments aligned to the right" stupidity). The only difference is he does not use Word but Vim for that...

Conclusion

Let's make a conclusion here. Indent is a LOGICAL thing, not aesthetical. If the programmer is not comfortable with indentation at all, he can set tab-width to 0 and voila. No chance with spaces. The ammount of spaces per one indent should be left to each programmer's individuality. The VeryLongFunctionName case is a similar one. The argumets are sub-elements of the function and should therefore be indented one level more (if necessary, of course). What may seem as an eye-candy for someone may be disliked by the other. The problem with spaces is that they are just fixed and immutable and the visual comfort of the code author is enforced to the others. Not even talking about editing such code. It's a torture! Spaces are wrong, wrong, wrong...

Summary

Let's summarize the whole thing in a simple table (in order of importance):

tabs

spaces

note

freedom to change what the code looks like

yes

no

arguments about indent width

no

yes

saves keypresses when adding

yes

no

saves keypresses when deleting

yes

no

looks nice

no

yes

I would answer "yes" and "no" but taking the opinion of majority

Before you argue

Everyone has his very own and personal habits of writing the code. That's fine. I'm pretty sure there are lots of people who are going to start an argument right after reading this. I'm fine with that too but before you do so, please, HONESTLY try to go back in your memory and consider following things:

If answers are "no", please don't even try to discuss things, you gotta experience it. Believe me, I have good reasons to hate space-indents...

Final word

Wow! You've reached this point. Good! I'm always trying to be open-minded and always try to listen to the other side. I don't say I won't change my opinion in the future (even though it's unlikely) so feel free to educate me. But remember, shouting that I'm an idiot will just make me think that YOU are dumb.

Indent (last edited 2008-01-18 12:56:20 by localhost)