Tag: tabs
You’re Doing It Wrong: Tabs
by Daniel on Nov.15, 2008, under Programming, Soapbox
This is likely the first in a series of You’re Doing It Wrong posts that I have rattling around my head.
Today, using Tabs to indent code. As i’m sure we’re all aware, the wonderful thing about tabs is that you can set how wide you want them to be displayed. I like a tab width of four, others like two, some like eight. And all the time that we indent our code with tabs then everyone can be catered for when it comes to their whitespace preferences.
Like most things, there is a dark side. When you start to turn to the dark side, you start use tab characters to create structured whitespace in amongst your code, that being non-tab characters, followed by tabs, followed by further non-tabs.
It’s a bit difficult for me to demonstrate this adequately on the bloggenator, so take a look at this example.
And now your work of art is ruined. Editors are trying to be too clever for our own good. Yeah it’s great if i’m the only one who’s working on the code, but what if someone else joins me on it? Or someone else takes over the project? Yeah sure you could say “their problem, not mine”, but it’s not very considerate is it?
By sticking to a rule of only using tabs at the beginning of a line, your code will have the same presentational layout whatever editor I, or anyone else want to use to view it.
When someone else eventually takes over my code, and it’ll happen, the last thing I want them to do is throw it all out. If they see bits of lines of code all over the place because they use eight spaces and you use two, it looks a mess. That gives them a bad impression of you’re coding competence, unjustly so, since if they tweaked their editor it would look good again.
Personally I use a variable-width font at work and a fixed width font at home. Don’t ask me why I do, i don’t know. The editor background on my work editor is white, at home it’s black! How whacky is THAT?!