Slashdot Mirror


Elastic Tabstops — An End to Tabs vs. Spaces?

An anonymous reader writes "Along with Vi versus Emacs, the tabs versus spaces argument must rank as one of the classic holy wars among coders. Here's an attempt to solve it by making tabstops expand or shrink to fit their contents. The concept's pretty cool to use, so be sure to have a play with the demo!"

8 of 263 comments (clear)

  1. Re:A standard tab length would be easier by Jeremi · · Score: 4, Insightful
    I think this is the wrong kind of solution to the problem. A standard would be easier. Just have someone say "Tabs are now officially SOME_NUMBER spaces long, so fuck you."


    You might as well tell the world "Earth's official language is now officially Esperanto, so fuck you". The effect would be about the same.

    --


    I don't care if it's 90,000 hectares. That lake was not my doing.
  2. whether or not this solves the problem by yagu · · Score: 3, Insightful

    Whether or not this solves the problem (I don't think it does), I get real nervous when source code starts being perceived as a document that lends itself to proportional fonts. Maybe I haven't been in the latest and greatest IDEs lately and am missing something here, but source code seems to scream for canonical form, and proportional font is not that.

    I think vim has a reasonable approach (do the research: shiftwidth, tabstops, softtabstop, etc.), I assume there are other approaches in emacs.

    Start talking about proportional font source code documents, and now everyone's going to want to have styles, and all the confusing garbage that is word processing. As difficult as source code and programming is, it doesn't need to be more nuanced in word processing.

  3. Re:A standard tab length would be easier by Daniel_Staal · · Score: 5, Insightful

    Actually, it is attempts to do that which have created the current confusion. Some were obviously too long, some obviously too short, and the end result is tabs which aren't useful.

    I actually like this idea, because it actually you from using this seemingly-simple but in actuality horribly complicated idea that tab = x*space. Instead they have an actually simple idea: Each tab is a seperate column of text. Line up items in the same column with each other. (Of course, how simple this is in practice is yet to be deterimined, but it seems simpler to me.)

    This idea is actually about seperateing sementic and content info. Programmers use tabs (those who do) to convey sementic info. If we can make the program understand that, then we can offer more flexiblity to the user on how to present the information.

    --
    'Sensible' is a curse word.
  4. Re:A standard tab length would be easier by peterpi · · Score: 4, Insightful
    I can't understand why people still find this a problem. It's so simple. Tabs indent, spaces line up. In other words

    • space means "move to the right by exactly one character width"
    • tab means "I want to indent, move across a bit". "A bit", and "across" mean whatever you like. It could be right8 chars, right 4 chars, left 2 chars, down 947565 chars, whatever you like. That's the beauty of it; everybody gets to view it in their favourite format.


    It's so simple, it's quite embarassing for the whole of the computer-literate society that people still get their kickers in a twist about it.

    Anybody who tries to lay down the law by saying that a tab must be 4, 8 or 2 characters' width has missed the point of the tab key completely.

    As for your wish, I'm willing to bet money that either vim or emacs will do it for you.

  5. The subject of tabs vs spaces should be clear by frn123 · · Score: 4, Insightful

    The subject of tabs vs spaces should be clear enough to everyone.

    Let me quote the relevant standard:

    Linux kernel coding style
    [cut]
    First off, I'd suggest printing out a copy of the GNU coding standards,
    and NOT read it. Burn them, it's a great symbolic gesture.
    [cut]
                      Chapter 1: Indentation

    Tabs are 8 characters, and thus indentations are also 8 characters.
    There are heretic movements that try to make indentations 4 (or even 2!)
    characters deep, and that is akin to trying to define the value of PI to
    be 3.

    Rationale: The whole idea behind indentation is to clearly define where
    a block of control starts and ends. Especially when you've been looking
    at your screen for 20 straight hours, you'll find it a lot easier to see
    how the indentation works if you have large indentations.

    Now, some people will claim that having 8-character indentations makes
    the code move too far to the right, and makes it hard to read on a
    80-character terminal screen. The answer to that is that if you need
    more than 3 levels of indentation, you're screwed anyway, and should fix
    your program.

    In short, 8-char indents make things easier to read, and have the added
    benefit of warning you when you're nesting your functions too deep.
    Heed that warning.

    [cut]
    But even if you fail in getting emacs to do sane formatting, not
    everything is lost: use "indent".

    Now, again, GNU indent has the same brain dead settings that GNU emacs
    has, which is why you need to give it a few command line options.
    However, that's not too bad, because even the makers of GNU indent
    recognize the authority of K&R (the GNU people aren't evil, they are
    just severely misguided in this matter), so you just give indent the
    options "-kr -i8" (stands for "K&R, 8 character indents").

    "indent" has a lot of options, and especially when it comes to comment
    re-formatting you may want to take a look at the manual page. But
    remember: "indent" is not a fix for bad programming.

    Linus Torvalds.

  6. Re:A standard tab length would be easier by peterpi · · Score: 3, Insightful

    I vote for TAB = however many spaces you want it to be. If you meant "move to the right by the width of four characters", press the space bar four times.

  7. Consistency is better than religion by morrison · · Score: 4, Insightful

    For several large projects I work with where there are lots of developers, consistency of the source code is considerably more important than any particular developer's opinion on what the correct behavior of tabs and spaces are. These are projects where it is pretty much expected that there are or will at least eventually be developers that use both vi and emacs with zealotry as well a myriad of IDE environments. For at least vi and emacs, all source files utilize a local variables block that is understood by both editors in order to encourage a project-defined convention with consistent indentation:

    /*
    * Local Variables:
    * mode: C
    * tab-width: 8
    * c-basic-offset: 4
    * indent-tabs-mode: t
    * End:
    * ex: shiftwidth=4 tabstop=8
    */

    With that comment block at the very end of all source files (whether they be C, C++, Tcl, Perl, Sh, SGML, etc), we do quite well in maintaining order and minimizing the indentation dispute. For the IDE environments, it at least gives them clear documentation on how to configure their IDE indentation preferences to match in every file. Maintaining a tabwidth/tabstop of 8 ensures consistent source display in most environments, including text printing and console display, leaving projects to simply define what offset/shiftwidth level they want for indentation. It can similarly still be tweaked for the projects that seem to insist on no tabs or want to match some IDE default religion.

    --
    Cheers!
    Sean
  8. Re:A standard tab length would be easier by peterpi · · Score: 5, Insightful
    And they make the fundamental misunderstanding in the very first sentence! Why is consistency desireable? Why should my text editor render code consistently with yours? We could be using a different font in a differerent point size at a different resolution. Is that important too? I have white text on a black background on one machine, black on white white for the other. If you specifically need some lines of text to be lined up with each other (consistency within the confines of the document), use space. If you just need it to be shunted over to express intent, use tab. That way we can both set tab to look exactly how we want it to.

    eg: (---> means 'tab', '.' means 'space')


    void foo ()
    {
    --->if (something)
    --->{
    --->--->/* I like to format my comments so that
    --->--->.* the stars make a vertical line,
    --->--->.* but I don't care how much you like to
    --->--->.* indent */
    --->--->bool something = SomeLongFunction() &&
    --->--->.................Another()
    --->}
    }


    This code satisfies everybody with a good text editor. If you like 8 spaces, set your editor so. If I like 2, 7 or 3.14 I can set mine. Pressing space n times annoys everybody who likes 2n, n/2 or any other number of spaces.

    That way they can get on with arguing over important issues like the placement of {

    ;)