3

I'm working on a new programming language, which determines structure with indentation instead of braces in the manner of Python and CoffeeScript. Obviously placing lines indented with spaces next to lines indented with tabs will mess up that kind of syntax, so I'm disallowing that - any given source file must use one or the other, not both.

I'm wondering whether it would be better to mandate one or the other across the board just to eliminate the possibility of time wasted on argument? Spaces seem to be slightly more popular than tabs, so if I were going to do that, I suppose I would mandate indenting with spaces (despite the fact that I personally prefer to use tabs).

Are there any situations where eliminating the possibility of indenting with tabs, would cause a problem?

rwallace
  • 1,208

3 Answers3

16

No. The tab character is an aberration that should never have found its way into ASCII, let alone any modern programming language. It was supposed to move the carriage on a teletype terminal to one of a predefined set of absolute positions, something that has no equivalent in the task of editing source code. Instead, it usually does a halfhearted approximation of that obsolete task, moving to the nearest multiple of n columns, and in a quite unpredictable way unless you have near-autistic attention to detail. I can see no advantage whatsoever to allowing it in source files, particularly since its presence is not discernible to an unsuspecting reader (unless special processing is enabled, like the whitespace-visual-mode of emacs).

Note that this does not rule out the use of the Tab key to do something useful, e.g. indent in a context-sensitive way like the better IDEs do, but that doesn't mean the compiler should have to deal with the Tab character. In my opinion, it can only cause confusion and is of about as much worth for the programmer trying to express something as the BELL character, i.e. none.

Kilian Foth
  • 110,899
4

Yes, to some degree. The holy wars of tabs and spaces is still going on, and if you choose to only allow one of them, you will alienate the opposing group.

My suggestion is, allow both if you don't want to be radical.

Hakan Deryal
  • 1,423
2

Some editors support tabs more easily than spaces, e.g., zero-feature plain-text editors which have no expand-tabs-to-spaces functionality. Mandating spaces makes it more inconvenient for people using such editors.

Some editors support indenting with spaces, but have only a global configuration for it rather than a per-file configuration. If the user prefers indenting with tabs, he may find it inconvenient to reconfigure his editor just to use your language. Perhaps more likely is an editor which supports per-file configuration of indentation mode, but uses a global configuration for the default mode when creating a new file: again, if the default isn't spaces then it's inconvenient.

Some programmers prefer indenting with tabs (you've said that you do, for example). They may find it irritating for the language to mandate the use of spaces.

Of course there are no technical problems with mandating the use of spaces. Everyone has a space key, and most programmers use editors capable of indenting with spaces without the user having to tap out <SPACE><SPACE><SPACE><SPACE> each time. However, irritation should not be underestimated as an influence on people's choices.