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,198
  • 11
  • 19
  • 2
    Before another holy war: http://programmers.stackexchange.com/questions/57/tabs-versus-spaceswhat-is-the-proper-indentation-character-for-everything-in-e – Hakan Deryal Apr 16 '12 at 17:12
  • Also, in a perfect world, it should be [elastic tabstops](http://nickgravgaard.com/elastictabstops/) – Hakan Deryal Apr 16 '12 at 17:17
  • Note that, unlike that other question, I'm not asking which of tabs and spaces is better. (As I said, I happen to prefer tabs.) I'm asking a different question: would it cause a problem if a language were to _mandate_ spaces? – rwallace Apr 16 '12 at 17:21
  • 1
    Yeah I figured that out, just wanted to point it out to remind people not to turn this one into another tab-space holy war. – Hakan Deryal Apr 16 '12 at 17:22
  • You could be a real stinker and detect whether the first indentation uses spaces or tabs and then require that throughout the remainder of the file. – Blrfl Apr 16 '12 at 17:47
  • @Blrfl, that's the fallback liberal option. I'm definitely not going to allow both to be used in the same file. – rwallace Apr 16 '12 at 17:55
  • 2
    Don't agree with you assertion "Spaces seem to be slightly more popular". Your hypothesis is based entirely on anecdotal evidence. [See](http://programmers.stackexchange.com/questions/57/tabs-versus-spaceswhat-is-the-proper-indentation-character-for-everything-in-e) seems to be 158/109 in favor of tabs (even this is probably biased in some way). I have no problem with eliminating one or the other I am in the third group (but biggest) (I don't care which you use just be consistent so I can set my editor up appropriately). – Martin York Apr 16 '12 at 18:09
  • Note: This is not the first time context (indent) sensitive languages have sprung up as an idea. They failed previously I expect it to fail again as we have forgotten the lessons learned (ie nobody did the research to find out why it was a bad idea last time). [OCCAM](http://en.wikipedia.org/wiki/Occam_%28programming_language%29) springs to mind. – Martin York Apr 16 '12 at 18:13
  • Tabs are very important: a [whole language](http://en.wikipedia.org/wiki/Whitespace_%28programming_language%29) has been built around them :) :) :) – Sergey Kalinichenko Apr 16 '12 at 18:22
  • 1
    @LokiAstari, Python? Haskell? Both are alive and kicking. – Hakan Deryal Apr 16 '12 at 19:04
  • @HakanDeryal: Haskell has been around for a while, though I was not aware it was context (indent) sensitive. Python is the new language on the block attempting this old technique. Has it learned anything from the past?? – Martin York Apr 16 '12 at 20:01
  • 1
    @LokiAstari, erm, Python is a new language? You might want to check it's [history](http://en.wikipedia.org/wiki/History_of_Python). It's 30 years old. – Hakan Deryal Apr 16 '12 at 20:43
  • @HakanDeryal: Ops. :-) New to my notice then. ;-) Question still stands though. Has it learned from the mistakes of it forbears. – Martin York Apr 17 '12 at 00:09

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
  • 107,706
  • 45
  • 295
  • 310
  • 3
    I up-voted this answer; then following Hakan's link in the comment and realized I had up-voted the Tab answer made by Fishtoaster. – Codism Apr 16 '12 at 17:22
  • "I can see no advantage whatsoever to allowing it in source files" Some people absolutely hating 4 space indentation and some people that are barely able to read anything other than 2 space indentation isn't an advantage? – remmy Oct 29 '13 at 21:14
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,403
  • 10
  • 13
  • Yeah. What got me thinking along these lines was, I had been going to allow optional braces and semicolons, then I read http://christianheilmann.com/2012/04/16/of-parser-fetishists-and-semi-colons/ and realized maybe I better hadn't, and then it occurred to me maybe the same reasoning might apply to tabs versus spaces. In other words, maybe I should want to be radical. – rwallace Apr 16 '12 at 17:47
  • Being radical has it's consequences, and the limits of how much radical you should be is up to you, ofcourse. There are lots of people out there hates Python because of the indentation rule. And lots of people love it, just because of the same reason. But it's widely used anyway. – Hakan Deryal Apr 16 '12 at 17:56
  • I don't think it really matters that much. In the end, if your language proves to be useful than the others in some areas, to the magnitude that will get developers interested in it, it will be used. I use spaces, and if I want to use a language that only uses tabs, I will just change my IDE settings to use tabs, and be happy with it. – Hakan Deryal Apr 16 '12 at 17:57
  • Probably the right idea. Consider tabs and spaces equivalent, but issue a warning if you find both in the same source file. – kevin cline Apr 16 '12 at 18:59
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.

John Bartholomew
  • 1,620
  • 12
  • 12