Live data from Hacker News

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

medium.com

51–60 of 124 posts

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

#51
post #2

I hereby declare end of discussion (at least for me), spaces because most other programmers use spaces. Unless you are joining the project that consistently uses tabs, then use tabs. Otherwise spaces.

If greater than 58% of all projects you work on mostly use tabs, then use tabs 91% of the time, in 97% of your projects.

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

#52
post #30
post #25

Earlier quoted context omitted.

Your point is valid, that's why I write function( really_really_really_really_really_long_argument1, really_really_really_really_really_long_argument2, really_really_really_really_really_long_argument3);

Right, not now you're dictating coding style to work around the warts associated with using tabs. If you use spaces there are no such issues because spaces don't change widths between editors.

To be honest, no, because my formatting will not be broken after refactoring changing function name length.

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

#53

Earlier quoted context omitted.

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 t…

Don't align. void my_function( int arg1, int arg2, int arg3, ... ) {

I also much prefer this way of breaking long lines. Aligning parameters always looked ugly to me, specially with long function names.

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

#54
post #36

Earlier quoted context omitted.

1. That's a band-aid. The characters have still been changed - the diff still "exists". 2. Those options are not perfect, they don't always work as expected 3. Those options are not turned on by default (because that would be INSANE) 4. Git's not the only VCS, much as I wish it were 5. Github's not the only Git web UI; that option is not available everywhere. It's not a "solved problem". It's an artificial problem, t…

> It's an artificial problem, that gets solved when you start consistently stripping trailing whitespaces on save and not realigning everything all the time. This is mostly solved via coding standards. If there are no coding standards people will "refactor" the coding style when they touch various pieces of code. If people were following a consistent style, then the alignment wouldn't be changing all of the time. Alt…

    enum {
        NORMAL    = 1
        ABNORMAL  = 2
        IRREGULAR = 3
    }
Now if you're writing like this, what happens when you introduce "EXCEPTIONAL = 4"? You change 3 other unrelated lines. This is something that alignment causes, regardless of "coding standards". Hell, gofmt does that... It looks pretty (to some extent - with long names and lots of members it gets unreadable), but creates so much noise.

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

#55
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?

The longer I've been programming, the more I think that alignment is ideally a presentational feature that a syntax-aware editor should do, not something that should be reflected in the source.

But then tabs vs. spaces isn't an issue.

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

#56
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.

I'm not an Emacs guy but it's trivial to set the tab size on vim. I would be shocked if that were not also the case for emacs.

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

#57
post #23

Now, can we look at the same repositories and look at the number of bugs and correlate it with the use of spaces? But in all seriousness, how often something is used isn't an indication of how good it is. Spaces are like cigarettes. Just don't start.

Yeah, but since in this case it doesn't really matter it's better to just do what most people are doing. There are no serious advantages to either one.

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

#58
post #40

Obligatory clip from Silicon Valley (Season 3): Tabs vs Spaces (Some potential storyline spoilers if you haven't seen Silicon Valley) https://youtu.be/SsoOG6ZeyUI

Wrong link :) https://youtu.be/SsoOG6ZeyUI

Oops, thanks for the correction! Have also updated my original post with the correct link :)

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

#59
post #34

I find it interesting that C++ using the .cc extension has about 7% tabs, whereas C++ using the .cpp extension has about 36% tabs. I wonder what else is different about these two groups.

Probably IDE defaults (i.e. there might be an IDE that defaults to .cpp extension AND tabs).

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

#60
post #48
post #28

Earlier quoted context omitted.

or python, or rust.

Python doesn't care either way as long as indentation is consistent (though there's a common misunderstanding that Python cares). However PEP-8 specifies that code should be indented using 4 spaces and editors should be configured to render tabs as 8 spaces (likely to make mixed tabs & spaces really obvious). But PEP-8 also specifies that code should follow whatever is the coding standard in a given project. IOW, Pyt…

Python treats a tab character as the amount of spaces needed to go into the nearest multiple of 8 column. With py2 ability to mix different indentation as far as it amounts to the same column, you can format your code in pretty interesting ways.
Post reply on HN