Live data from Hacker News

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

medium.com

41–50 of 124 posts

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

#41
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…

Honestly I don't care either way just a long as the file doesn't mix tabs with spaces.

I hate when the code looks perfectly aligned in my editor but is completely messed up in git because git renders tabs a different with.

I personally prefer spaces on my own projects because in the early days a tab used to be fixed at 8 spaces and I though that was a bit too much.

It's adjustable now but I don't think it was then or at least I wasn't aware it was.

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

#42
post #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,…

> Many editors, however, consider all spacing at the start of the line to be indentation.

What? If your editor can't tell the difference between you hitting the tab key versus the spacebar, it's a bug in your editor.

Smart tabs - the idea you're talking about - is well-supported in just about every major editor.

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

#43

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.

I think this definitely applies to xcode, I use tabs everywhere but for xcode it just prints a lot of spaces and I am used to it.

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

#44
post #8

Earlier quoted context omitted.

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

You don't, you use tabs for indentation and spaces for alignment.

Parent, you are the devil incarnate. Grandparent, you have bigger issues to resolve.

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

#45

I would like to know If they are people who have 'switched'(coded with spaces and then use tabs or revers)?

I just recently switched from tabs to spaces. I always used spaces for alignment and tabs for indentation. It was working very well within my company as all my colleagues were using 2sp tabs and I was on 4 space tabs. But now, we've decided to upgrade our codebase and make it PSR compliant (PHP).. which meant switching from tabs to spaces.

To be honest.. it's no biggie after a few weeks you get used to it.

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

#46

I've always used spaces instead of tabs. My rationale: The number of readers of any document will normally be greater than the number of authors. We should give a slight preference for readability and ease of comprehension over writeability, and should certainly not require that our readers adjust their editor settings for each document that they peruse. In addition, it is useful to use vertical alignment to group re…

Hey, a rationale, something I seldom see in those debates :)

I think that if you do want to align, spaces are unavoidable. But I want to reiterate three points against alignment:

- Alignment creates a maintenance burden. It has to be updated whenever you touch unrelated lines, which creates whitespace noise.

- Some types of alignments (specifically, method parameter alignment) create extreme horizontal noise. See for yourself: https://github.com/pennersr/django-allauth/blob/c9b31ddee81d...

That stuff's ridiculous. Styleguides are meant to make the code more readable and maintainable - this is neither. Method calls can be defined just like arrays, where the first argument goes on a newline with a single added indent. No need to align anything.

- Finally, alignment breaks with proportional fonts. This is something someone else brought up on HN in another topic and I think it's a really good point; proportional fonts, like tabs, are an accessibility feature.

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

#47
post #31

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?

With spaces you can position the cursor anywhere you want, with tabs you can not position the cursor in the middle of a tab.

Why would you want to do that? In fact, isn't it much more convenient to be able to jump over one tab with a single keystroke, rather than 2, 4 or 8?

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

#48
post #28
post #18

Earlier quoted context omitted.

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

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, Python is actually far more pragmatic than most people (including most Python programmers) think. It just has a culture that strongly advocates following the rules (i.e. PEP-8 and PEP-20).

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

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

Don't align.

    void my_function(
        int arg1, int arg2, int arg3,
        ...
    ) {
Post reply on HN