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?

13
  • 2
    Before another holy war: programmers.stackexchange.com/questions/57/… Apr 16, 2012 at 17:12
  • 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. Apr 16, 2012 at 17:22
  • 2
    Don't agree with you assertion "Spaces seem to be slightly more popular". Your hypothesis is based entirely on anecdotal evidence. See 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). Apr 16, 2012 at 18:09
  • 1
    @LokiAstari, Python? Haskell? Both are alive and kicking. Apr 16, 2012 at 19:04
  • 1
    @LokiAstari, erm, Python is a new language? You might want to check it's history. It's 30 years old. Apr 16, 2012 at 20:43

3 Answers 3

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.

4
  • Yeah. What got me thinking along these lines was, I had been going to allow optional braces and semicolons, then I read christianheilmann.com/2012/04/16/… 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, 2012 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. Apr 16, 2012 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. Apr 16, 2012 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. Apr 16, 2012 at 18:59
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.

2
  • 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, 2012 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, 2013 at 21:14
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.