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!"

21 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 Jeremi · · Score: 2, Insightful
    I must have missed the part of the discussion where tabs/spacing became intimately interwoven into human culture and society.


    They became interwoven into the computer-programming subset of society back in the 60's and 70's, if not earlier.


    But even beside that, a lot of things are set semi-arbitrarily in the tech world. So why not the length of a tab?


    Because the proposal isn't to define a new standard, it's to re-define a very well-entrenched (if crappy) existing standard. All 60 million people who are already happily accustomed to doing things the old way will simply ignore the new "standard", and a standard which nobody uses is worthless.

    --


    I don't care if it's 90,000 hectares. That lake was not my doing.
  4. 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.
  5. Re:From Wiki by Kesch · · Score: 2, Insightful

    :s/Vi/Emacs/g

    --
    If this signature is witty enough, maybe somebody will like me.
  6. It's not a comment about Microsoft. by Ayanami+Rei · · Score: 2, Insightful

    So, uh. What the fuck does VS have to do with anything?
    I've never used it so I can't comment. So it has variable-width fonts and logical indenting and spacing? Good for them.
    If it appears in anything _besides_ Visual Studio I'll be a happy camper.

    --
    THIS THING CAN TURN ON A DIME, MACROSSZERO STYLE ALSO FUCK BETA, ~NYORON
  7. Re:A standard tab length would be easier by GroeFaZ · · Score: 2, Insightful

    How can you tell whether nobody will use a new standard if it is significantly better than the old one? If you admit the old standard is crappy, why not even try for the better? Considering how tabs tend to break across platforms or even across applications, it already seems like everyone is doing what he wants anyway. Doing or not doing things because "that's the way it used to be and we don't want change because change is hard" just doesn't make sense, especially considering the fact that we're talking about computers. That's not exactly a field whose methods are carved into proverbial stone like, I don't know, metal smithing, pottery, or something ancient like that.

    --
    The grass is always greener on the other side of the light cone.
  8. Re:A standard tab length would be easier by doshell · · Score: 2, Insightful
    La lingvo oficiala da tero estas Esperanton, tial fiku vin!

    Mi pensas, cxu "fikugxi" ne estas pli tawga vorto? :P

    Saluton, karaj esperantistoj!
    --
    Score: i, Imaginary
  9. Source code is not a table by Anonymous Coward · · Score: 1, Insightful

    Tab is short for Tabulate - make into a table. Source code is not a table.

    If you want to represent data in a tabular form then use tab stops and the tab character to separate the data items such that when it is displayed the data items form columns.

    Source code for most languages is not like that. It happens to be convenient to use the 'tab' key as if it were an 'indent' key and space can be saved on disk by representing a number of spaces by a single character, but the 'tabbies' are confused.

    It happens that _some_ languages are 'tabular'. Assemblers, for the most part, are best represented in columnar form. Perhaps the tabbies are locked into the 1960s when programs were written on 'card punch forms' and a format card was used to set the tabstops for the punch girls, but the cards had _spaces_ on them as Hollerith intended, the tab key did _NOT_ punch a tab character into the card.

    I do use the tab key as a means of stepping along a number of spaces but the resulting files has exactly the number of space characters that are necessary and no tab characters at all.

    1. Re:Source code is not a table by DrMorris · · Score: 2, Insightful

      I do use the tab key as a means of stepping along a number of spaces but the resulting files has exactly the number of space characters that are necessary and no tab characters at all.

      Yeah. And this is exactly the way it should be today. In mature Emacs modes for example, pressing the TAB key doesn't necessarily mean that you insert an ASCII TAB character, instead it indents to the right place. Modern editors should take the burden of 'manual' indenting from the coder and instead let him focus on the semantics (without introducing a new 'standard').

  10. 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.

  11. 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.

    1. Re:The subject of tabs vs spaces should be clear by Anonymous Coward · · Score: 1, Insightful

      The "standard" you are quoting is relevant to kernel programming in C only. For example:

      The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.

      Okay, one level of indentation for a class' members. One level of indentation for a member function. That leaves one level of indentation for loops, conditionals etc. Are you really saying that nested ifs mean your program is screwed? That it's impossible to have a sanely-designed loop that has an if statement in?

  12. 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.

  13. Re:A standard tab length would be easier by peterpi · · Score: 2, Insightful
    You might as well try and define what the 'end' key does. Or better still, define what the F7 key does.

    Tab is already standardized. It means either "move onto the next record" in tabular data, or in programming languages "indent". If you have a preference for how much like code to be indented, then you get to set your editor in accordance. Indenting code with tabs is far more considerate than indenting with spaces. Indenting with tabs says "Indent a little. I trust you to set your editor accordingly". Indenting with 4 strikes of the space bar says "In my opinion, four spaces, not two, nor eight, nor six, is the only way to indent. If you want to read my code you shall accept my rules".

  14. 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
  15. Re:A standard tab length would be easier by linvir · · Score: 2, Insightful

    I'm sure a lot of things seem so simple when you're so ignorant of the actual issue.

    Why does the PEAR coding standard insist on space-only indentation?
    Using spaces and avoiding tabs is the only way to ensure that a piece of code is rendered consistently in all editors and viewers. Many editors render tabs as 4 spaces, and a lot of editors, terminal programs and utilities render tabs as 8 spaces.
  16. Re:From Wiki by Ed+Avis · · Score: 2, Insightful

    Nope, afraid not. vi is a modern-day abomination. Ed is the standard text editor.

    --
    -- Ed Avis ed@membled.com
  17. Re:A standard tab length would be easier by brianmf · · Score: 2, Insightful
    Using spaces and avoiding tabs is the only way to ensure that a piece of code is rendered consistently in all editors and viewers. Many editors render tabs as 4 spaces, and a lot of editors, terminal programs and utilities render tabs as 8 spaces.


    Wait. Doesn't this miss the entire purpose of tabs?

    I like to see my code indented by the equivalent of two spaces. The other coders in my team like to see their code indented by the equivalent of four spaces. Do we engage in massive edit wars in cvs? Do we regulate a specific number of spaces so that some portion of the team is unhappy? No. I setup my editor to display tabs as the equivalent of two spaces, and the others setup theirs to look like 4 spaces. Everybody is happy.

    Regulating a specific number of spaces is sub-optimal. It totally removes a coders flexibility to see the code how they prefer.
  18. 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 {

    ;)

  19. Re:A standard tab length would be easier by Breakfast+Pants · · Score: 2, Insightful

    Ughhh. If it were so simple everyone could just pipe everything through GNU indent and get everything in the format they want. It isn't so simple.

    --

    --

    WHO ATE MY BREAKFAST PANTS?