Live data from Hacker News

Tabs or spaces – Parsing a 1B files among 14 programming languages

medium.com

11–20 of 124 posts

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#11
post #8

I've never really understood why you would use several characters (=spaces) for something that is semantically one indent. Can someone enlighten me? What are the advantages of spaces over tabs?

def doSomething( parameter1 , parameter2 , parameter3 ): pass How would you make all the punctuation line up using tabs?

Rather (assuming you’re dealing with Python),

    def do_something(parameter_1,
                     parameter_2,
                     parameter_3):
        pass

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#12
After 20+ years of listening to the tabs-vs-spaces debate and considering all the legitimate points that both sides have, many have made the following observation and it's what resonates with me the most:

In an ideal perfect world, _all_ of programmers and _all_ text editor tools would use tabs specifically for indentation and spaces specifically for alignment. But, we don't live in that perfectly coordinated world so spaces maintains the most fidelity -- at the expense of programmers not being able to instantly customize the indentation from widths of 2,4,6,8.

Therefore, the slight edge goes to spaces even though I find tabs extremely attractive. (That conclusion is in the context of a team of multiple programmers, using multiple languages, multiple text editors. If you're solo and can maintain "tabs discipline", that's a different scenario.)

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#14
post #8

I've never really understood why you would use several characters (=spaces) for something that is semantically one indent. Can someone enlighten me? What are the advantages of spaces over tabs?

def doSomething( parameter1 , parameter2 , parameter3 ): pass How would you make all the punctuation line up using tabs?

    def do_something(
        param1, param2,
        param3, param4
    ):
        ...
It's not that hard. Alignment is generally harmful - it's a maintenance burden which adds whitespace noise on diffs, which means more noise in code reviews. Not to mention how atrociously ugly it is when long variables/method names lead to 5+ lines with 60+ characters of indent for a single variable name per line.

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#15
post #7

Earlier quoted context omitted.

People always talk about consistent display of spaces whereas tabs might be shown as 4 spaces or even 8. Of course that means you can usually customize how tabs are rendered unless you code in Notepad or something crazy.

Lots of people need to access files on a server via Emacs or Vim. Having to deal with tabs there can be very frustrating.

On vim (I am sure as hell you can do this on Emacs) you can always define your tabs to be spaces and you can specify exactly how much. So this is really not a big problem.

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#16

I've never really understood why you would use several characters (=spaces) for something that is semantically one indent. Can someone enlighten me? What are the advantages of spaces over tabs?

Not all editors are smart about tabs and spaces, and when the two start to mix things get really funky if everyone doesn't have the same "1 tab = x spaces" value set on their editor.

For example:

      function_call(really_really_really_really_really_argument1,
                    really_really_really_really_really_argument2)
Say that this is supposed to be at one indent level. The beginning of both of those lines should contain only one tab, and the spacing that positions the second argument from the indent should be only spaces:

  function_call(really_really_really_really_really_argument1,
  SSSSSSSSSSSSSSreally_really_really_really_really_argument2)
If the text looked like above (each 'S' is a space), then one's editor could easily change whether or not a was displayed as 8 spaces or as 4 spaces, and the display wouldn't be affected. Many editors, however, consider all spacing at the start of the line to be indentation. If you were using one of those editors with tabs set to (e.g.) 4 spaces, the code might look something like this:

  function_call(really_really_really_really_really_argument1,
  SSreally_really_really_really_really_argument2)
Now the code only looks the way it was meant to look if you have you = X spaces value set to 4. If you set it to something else, the code looks like a mess.

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#17
post #12

After 20+ years of listening to the tabs-vs-spaces debate and considering all the legitimate points that both sides have, many have made the following observation and it's what resonates with me the most: In an ideal perfect world, _all_ of programmers and _all_ text editor tools would use tabs specifically for indentation and spaces specifically for alignment. But, we don't live in that perfectly coordinated world s…

My other personal feeling is that it's easy to auto-check we aren't using tabs (just search for tabs, and reject if any are found).

Depending on how you choose to format, it can be arbitrarily hard to check tabs are being used correctly.

For example, many people want to do some space indenting, such as:

    void my_function(int arg1, int arg2,
                     int arg3)
    {
It's (I believe) impossible for a language-agnostic tool to know this is "correctly tabbed", but (for example)

    void my_function(int arg1, int arg2,
                     int arg3)
        {
Is not.

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#18
post #12

After 20+ years of listening to the tabs-vs-spaces debate and considering all the legitimate points that both sides have, many have made the following observation and it's what resonates with me the most: In an ideal perfect world, _all_ of programmers and _all_ text editor tools would use tabs specifically for indentation and spaces specifically for alignment. But, we don't live in that perfectly coordinated world s…

Unless you're using golang,in which case gofmt will correct you. Hence the overwhelming consensus of the go row for tabs.

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#19
post #8

Earlier quoted context omitted.

def doSomething( parameter1 , parameter2 , parameter3 ): pass How would you make all the punctuation line up using tabs?

def do_something( param1, param2, param3, param4 ): ... It's not that hard. Alignment is generally harmful - it's a maintenance burden which adds whitespace noise on diffs, which means more noise in code reviews. Not to mention how atrociously ugly it is when long variables/method names lead to 5+ lines with 60+ characters of indent for a single variable name per line.

Most diff programs have an "ignore whitespace" option. "whitespace noise on diffs" is pretty much a solved problem. You can even add '?w=1' to a Github URL to turn on the feature.

Re: Tabs or spaces – Parsing a 1B files among 14 programming languages

#20

Some IDEs will convert tabs to spaces when saving and the other way around when editing, so, while your approach is interesting, not really a proof of a majority choice. Also my beef is specially with people who don't use tabs in files like fstab, like beasts.

I'd bet most of the code ever written gets styled however the IDE du jour decides to by default.

If some IDEs decided to switch to tab indent by default, people would suddenly love tabs.

Post reply on HN