a companion discussion area for blog.codinghorror.com

Death to the Space Infidels!


#141

When working with other people, I use whatever convention there’s already in place. At my work, we have rules (tabs of width 4, space after keywords, camlCase, whatever) and I abide. If I want to work on an open source project, I will write in whatever style is in use. I don’t personnaly care for specifics as long as it’s easily legible ! I do have a personnal preference for a certain formating (which I use on my personnal projects when I write alone), but I adapt to the environment. The main point here is : uniformity ! Most coders are able to read most conventions as long as they’re sensible, but it’s easier for your brain (or what’s left of it) to have only one syntax to parse throughout a single project.

Then, I believe that most code editors can enforce a good deal of presentation rules (I might be wrong, I only work with Visual Studio), so people should use them ! Sure, it might be a pain in the ass to switch settings between project, but I think it’s for the greater good !


#142

That said, only a moron would use tabs to format their code.

Unsubscribed!


#143

Tabs for indentation, spaces for formatting. A very simple rule.

Tabs are 8 spaces. Fortunately, this simple rule makes easy to deal with heretics that set their editors to display tabs in less their 8 spaces. Unfortunately, ridiculous as it sounds, this simple rule is very hard to understand by most people. There was a flame on the vim mailing list about implementing native support for this in vim, but people found it hard to understand exactly what was it about and failed to see the advantages.


#144

So Jeff uses ‘spaces’ … that speaks volumes


#145

As for indent width, all kernel stuff I’ve worked on (*BSD, Linux, Mac OS X) uses 8 space tabs, so meh…

http://www.openbsd.org/cgi-bin/man.cgi?query=stylesektion=9


#146

USE TABS FOR INDENTION!

Why? Jeff likes indention of 2 spaces, I personally prefer 4, some prefer 8. Indention is a matter of personal taste. Why would you force your personal taste upon other programmers? That is moronic. Especially in a wold of open source projects with hundreds of programmers, why would a couple of people decide upon a style and force it upon so many other coders, no matter how much this style will hurt their eyes?

When using tabs, every not completely useless code editor allows you to configure how large tabs are on screen. You can make it everything from 1 to 16 spaces, whatever you like. The same piece of code, indented with tabs, can make a 2, 4 and 8 space indention fan happy, since it will have exactly that many indention within his/her favorite editor.

Also a space is just a space. When programming, you never know what meaning a space has in this file. A tab, when exclusively used for indention, has a meaning though. It means indent once and two tabs mean indent twice and so on.

I agree with Aram, though. If you must format (layout) something, use spaces. Why? Because you must not rely upon the fact that a tab is equally width for everyone in the world as it is for you. And an alignment that works nicely when tabs are 4 spaces breaks terribly when they are 2 or 8 spaces!

I always and exclusively code according to Cyrus’s 3rd option. I indent with tabs, that way everyone reading my code can have indention as big or small as pleases his/her eye. Nobody needs to like my style, change the config of your editor and have my code be presented in you favorite style. However, when I must align something, I cannot use tabs, so I use spaces. If you look at the Cyrus code sample in the post above… copy this to a file (and make tabs real tabs). Now change indention to 2 spaces, change it to 4, change it to 8. Indention changes each time, but the string is always nicely aligned below the int, isn’t it? If you make this example all spaces, you cannot change indention (you must read it, no matter how bad it looks to you). If you make it all tabs, changing indention width breaks the alignment and string won’t be aligned with int any longer. Using both does not give you the problems of both worlds as Jeff wrote, it gives you the BENEFITS of both worlds:

  1. Have indention your way, whatever pleases your eyes

  2. Have aligned text aligned, no matter how indention width changes.


#147

Is the code legible?

If yes, then stop willy waving about tabs vs spaces, and get on with something productive.
If no, then you probably have bigger problems to worry about than tabs vs spaces.


#148

We’re a team of 20 and I can’t recall any argument about spaces or tabs in the last 10 years.

Those arguments were in 1990s. Back then, many people were trying to use tabs=3. Then people fought because the defaults in editors were 4, and people still printed code, or looked at it at the command line where tabs=8. (I seem to recall that tabs=2 at Corel?)

Then Visual C++ took over the world, with tabs=4 and progressively everyone gave up.

Tabs=4 is the standard. It also makes it awesome fast to navigate the code with the arrow keys, which jump from tabs-to-tabs. You can tell right away when something’s been turned to spaces by mistake

Now code indentation is another matter. The one glitch we have is some people settling on what Visual Assist produces instead of the company standard.


#149

That said, only a moron would use tabs to format their code.

  • unless you happen to be programming in whitespace or Python.

maybe the python folks wanted to start a flamewar?
or force everyone to use whitespace in a particular way to avoid a war?


#150

I use tabs to allow people to specify what size they prefer the indentation at in their editor. Also tabs are less typing and quicker to work with. Spaces are for morons!


#151

Philip Leitch:
The place where I work currently has a developer (who is also the head of the development department), who will clean up the code of others.

That remembers me of a joke:
The radio-broadcast says there is one Geisterfahrer on my Autobahn. But that’s wrong, there are hundreds!

If the head of dev-department cleans up your code, you should worry, if you have not read the coding-guidelines. Or the head should instruct the clerks how to format right the first time.
It’s of no good use, if everyone uses its own style for formatting, a bad standard is even better than dozens of different good standards …


#152

ìChoose tabs, choose spaces, choose whatever layout conventions make sense to you and your team. It doesn’t actually matter which coding styles you pick. What does matter is that you, and everyone else on your team, sticks with those conventions and uses them consistently.î

Couldnít agree more. This really should not be a matter of debate, and letting it become so implies the team lacks the leadership or discipline necessary to ever complete a project.

Personally, whilst I can see the principle of using tabs for their flexibility, I really suspect that spaces are the best pragmatic option. Itís just so much easier to enforce a no tab standard.


#153

Hasn’t anybody heard of Ockham’s Razor?
Pluralities ought not be posited without necessity.

This space/tab plurality exists because some programmer thought it would be a good idea to write code using tab characters instead of spaces. The compiler, ignoring whitespace characters, was able to compile the code, and the programmer was none the wiser.

Then along came office productivity software which allowed text to be indented with the tab key, to mimic the typewriter. But rather than inserting four spaces, the tab key inserted a tab character into the document. And a host of other ASCII characters were created–the vertical tab, the tab stop, the carriage return, the line feed, the escape character, the delete character–some of which have given programmers much grief.

And so I say, to HEX with your ASCII character set. Programming is not letter-writing. If my IDE would edit documents as if every set of four spaces were a tab character, and if it would insert four spaces when I hit the tab key, I would use spaces rather than tabs in my code.


#154

when I print something out, I cannot see a tab vs a space.
I use ‘expand’ to convert tabs into spaces before I tinker with someone elses code (and I usually run it thru a pretty printer too).


#155

Using spaces to format code is like using opening Word and hitting the space bar a bunch of times to center something.


#156

It doesn’t actually matter which coding styles you pick [as long as your team agrees]

No.

Just forcing tabs (4 space width) on everybody would solve this problem forever. There hasn’t been any reason whatsoever to use spaces for 30 years. We have computers people. They can handle crap like formatting.


#157

Too much white space is a problem for graphical language programmers as well.


#158

Jeff argueing spaces over tabs is kind of a dumb thing to do, even worse than emacs vs vim.

I dont think the issue is only coding related. It was a dumb design decission in the early days.

Lets make the computers have an extra space thats bigger than the regular space of about 8 characters but implementation can decide on the final length. And lets make it have a smaller key and call it tab so it looks like a whole new feature


#159

Here are the results (with 28 votes) from my Survey Monkey survey [1]. Unsurprisingly, there was no clear winner! :slight_smile:

29% = indent 2 with spaces
29% = indent 4 with spaces
3% = indent 8 with tabs
29% = indent 4 with tabs
3% = indent 8 with tabs
7% = indent 4 with tabs, then align with spaces
3% = other (?!)

[1] http://www.surveymonkey.com/s.aspx?sm=CuOCMx8ZkrpzKrEsWp0YpQ_3d_3d


#160

Jeff:

Considering your past posts on efficiency in coding and space savings and normalization, I’m surprised that you didn’t consider the size difference of a file programmed.

Example: I recently took a small, ASP filewatcher program that used spaces, and entered tabs… Result: 1.38kb for spaces, 1.22kb for tabs…12% savings in file size. It’s not a big deal when you’re talking bytes but in enterprise software, it could make a difference.