News for hackers. Stuff that matters.
Re:Developers who use spaces make more money than those who ... by jinglebells on Thursday June 15, 2017 @10:41AM (#14560811)
> Finally, when another developer looks at the code, their IDE will render the tabs as whatever its set up for, 2 spaces, 4 spaces, etc. In other words, it adds flexibility.

This is exactly why I use tabs and the reason which appears to never get cited in the holy wars.

People who use spaces want to line up their '=' signs, that's fine, but I don't believe it's my position to enforce the amount of whitespace another developer has to use in their editor. It's an accessibility thing, they might have their font size really large because of eyesight problems in which case 8 spaces is going to make reading the code a lot harder.

The fact that Python's rule used to be 8 spaces, then got changed to 4 thereby invalidating old code really showed me how shortsighted it is to use a set number of spaces in a whitespace sensitive language.

Re:Developers who use spaces make more money than those who ... by tom_mellior on Thursday June 15, 2017 @11:31AM (#14561322)
> This is exactly why I use tabs and the reason which appears to never get cited in the holy wars.

I see this cited every time. Unfortunately, it's bogus in practice. Consider:

    print('some long thing',
          further, arguments)
If this is an indented block, you'd have to indent the second line to the correct depth with tabs, then add exactly six spaces for alignment. You have to mix spaces and tabs, which is never good news. Additionally, if you try to actually type in the six spaces, editors might take, say, four of them and group them into a tab. (I have vague memories from a long time ago of Emacs doing this. I might be wrong.)

If you get this wrong in program parts that are by definition invisible, it might look good for you and look really bad for others (i.e., the opposite of the stated goal). In code I see mixing spaces and tabs, the latter tends to be the case.

Re:Developers who use spaces make more money than those who ... by news_to_me on Thursday June 15, 2017 @12:21PM (#14561796)
I'm pretty sure there's a circle of hell specifically for those who mix spaces and tabs.

That being said, this problem and problems like it can be solved simply by not aligning things visually:

    print(
        'some long thing',
        further,
        arguments
    )
Strictly adhering to indentation and never alignment can make the code a bit less readable, but conforming to a canonical indentation like this also makes it easier to reindent, move code around, etc.

I think that's what the argument really comes down to – alignment flexibility vs display flexibility. It's interesting to see which people generally prefer.

Re:Developers who use spaces make more money than those who ... by tom_mellior on Thursday June 15, 2017 @12:46PM (#14562031)
> can make the code a bit less readable

Yes, and I'd say that that's a big problem. I'm not a religious opponent of tabs, but making code less readable just so you can keep using them wouldn't fly if I were Malevolent Whitespace Dictator For Life.

Re:Developers who use spaces make more money than those who ... by striking on Thursday June 15, 2017 @02:21PM (#14562968)
IMO, that reads just as well. Each object is still indented, it's close enough.
Re:Developers who use spaces make more money than those who ... by pera on Thursday June 15, 2017 @01:26PM (#14562406)
> I'm pretty sure there's a circle of hell specifically for those who mix spaces and tabs.

Could you please clarify why do you consider "tabs for indentation, spaces for alignment" such a bad practice? I have never read any argument against it.

Alignment itself can be done automatically by any editor that supports smart tabs.

Re:Developers who use spaces make more money than those who ... by lloeki on Thursday June 15, 2017 @05:38PM (#14564605)
Simple: it's hell to automate.

My process is as follows:

    - tabs allow for custom settings
    - tabs need spaces to allow for alignment, because previous
    - automatically deciding what constitutes alignment vs
      indent is a non-trivial problem, highly dependent on the
      language†
    - using spaces throughout is worse theoretically because
      it flattens the theoretical problem but solves impedance
      mismatch
    - therefore I use spaces and am all the merrier in every practical
      use case
    - except for languages who make dash 3 easy (such as Go thanks
      to gofmt)
    - except for projects I have no say in, where I respect the will
      of the maintainers, because conventions among well-behaved
      people matter more than my highly individual opinion. 
† to which the usual answer is "but your editor sucks with lang X", well too bad, I'd rather have pragmatic editor portability than have perfect language parsing in every editor being a pipe dream I hinge upon.
Re:Developers who use spaces make more money than those who ... by Stratoscope on Thursday June 15, 2017 @03:23PM (#14563573)
It's not that "tabs for indentation, spaces for alignment" is a bad practice, it's that alignment itself is a bad practice. It doesn't help readability, it directly causes overly long lines of code (which pushes people to try to use narrow indentation to compensate), it's something you have to fiddle with every time you refactor a name, and it gives you spurious changes in your VCS diffs. (Yes, you can set any diff program to ignore whitespace changes, but I want to know when whitespace has changed.)
Re:Developers who use spaces make more money than those who ... by pseudalopex on Thursday June 15, 2017 @12:09PM (#14561670)
Yes, Emacs used to group spaces into tabs. I think most editors these days do the right thing.

This problem goes away if you indent parameters instead of aligning them:

    print(
        'some long thing',
        further, arguments)
In this case it takes an extra line, but it's often shorter.[1]

[1] https://github.com/pennersr/django-allauth/blob/a44134688f5b...

Re:Developers who use spaces make more money than those who ... by sqeaky on Thursday June 15, 2017 @12:50PM (#14562070)
Gross, You purt 3 parameters are on two lines. Either indent none of them and keep it on one line or indent all of them. What are you doing, trying to hide "arguments"?
Re:Developers who use spaces make more money than those who ... by pseudalopex on Wednesday June 21, 2017 @01:42AM (#14600978)
That's how the original example was formatted. I'm illustrating one small change.
Re:Developers who use spaces make more money than those who ... by u801e on Thursday June 15, 2017 @03:40PM (#14563714)
> I see this cited every time. Unfortunately, it's bogus in practice. Consider: > > print('some long thing', > further, arguments) > > If this is an indented block, you'd have to indent the second line to the correct depth with tabs, then add exactly six spaces for alignment. You have to mix spaces and tabs, which is never good news.

One way to avoid this would be use a hanging indent. For example:

    print(
        'some long thing', further,
        arguments)
That would work well with either tabs or spaces.
Re:Developers who use spaces make more money than those who ... by Sammi on Thursday June 15, 2017 @03:53PM (#14563832)
This is the right way to do it always, because it is the consistent way. You'll always be indenting the same way everywhere if you do it like this.
Re:Developers who use spaces make more money than those who ... by mikejmoffitt on Thursday June 15, 2017 @03:11PM (#14563474)
This is an example of where it's absolutely okay to mix tabs and spaces. If it's Python, that's not going to work, but depending on one's preferences and opinions that can be seen as a defect of the language, not the formatting. In C, C++, Java, Javascript, and nearly every other language, this is a great practice.
Re:Developers who use spaces make more money than those who ... by tom_mellior on Thursday June 15, 2017 @03:40PM (#14563721)
I agree in theory. Having seen terrible mixes of tabs and spaces, I don't agree in practice.

I've worked with several projects that painfully switched from tabs to spaces because tabs didn't work for them in practice, in a setting where several people work on one thing. I haven't seen projects go the other way. (Yes, automated formatting would solve part of thise.)

Re:Developers who use spaces make more money than those who ... by gcb0 on Thursday June 15, 2017 @12:03PM (#14561608)
you're going to be downvoted by the thou shalt not mix tabs and spaces crowd that fails to understand the reason of what they preach. sigh.

also the fly by night devs who still don't see tabs on their text editors... I mean, ide.

Re:Developers who use spaces make more money than those who ... by hibbelig on Thursday June 15, 2017 @04:06PM (#14563925)
I feel it's a matter of style. I've resisted a long time, but then I've come to appreciate:

    some_function_name('some long thing',
        further, arguments)
Assuming a tab width of four, there is no problem with starting the second line with a tab. And the whole thing can be indented by tabs, as well (in which case the first line has N tabs and the second line has N+1 tabs).

The longer the function name, the better the advantage of indenting like this.

Re:Developers who use spaces make more money than those who ... by sicariusnoctis on Thursday June 15, 2017 @04:12PM (#14563962)
Spaces are only beneficial if you use styles with alignment. I dislike them: they sometimes look pretty, but they waste a ton of space on the left and don't work well in all situations.
Re:Developers who use spaces make more money than those who ... by z3t4 on Thursday June 15, 2017 @02:47PM (#14563225)
I wonder how much time have been wasted trying to make margins and columns look good with a proportional (non-monospace) font ...
Re:Developers who use spaces make more money than those who ... by Stratoscope on Thursday June 15, 2017 @03:09PM (#14563460)
Almost certainly none at all. Those of us who use proportional fonts simply don't try to do column alignment, because it would be a fool's errand.

In most situations, I consider column alignment to be detrimental to code maintainability. I actually stopped using it long before I switched to a proportional font.

When I later got curious about trying different fonts, I discovered to my surprise that the code looked just the same in a proportional font as it did in a monospaced font.

Regarding margins, if you mean indentation, that works the same in a proportional or monospaced font. The only thing that doesn't work well is the popular two-space indents. That ends up with very little visible indentation in a proportional font.

But to my eyes, two spaces isn't enough in a monospaced font either. It's just not enough spacing for me to see the code structure clearly. Four-space indents solve this problem; tabs solve it even better. When you use tabs, you don't have to argue about how many spaces to use.

I think these are related. Why do people want to use two-space indents? I believe it is often because their lines of code are getting too long. Why are the lines getting too long? Often that is because of the use of column alignment, especially with function arguments and the like.

If you stop using column alignment, your lines will naturally be shorter, and there is less reason to try to save horizontal space with narrow indents.

Re:Developers who use spaces make more money than those who ... by pyre on Thursday June 15, 2017 @11:24AM (#14561248)
> The fact that Python's rule used to be 8 spaces, then got changed to 4 thereby invalidating old code really showed me how shortsighted it is to use a set number of spaces in a whitespace sensitive language.

Not sure what you're talking about here. In Python, as long as the indentation is consistent you could (e.g.) use 2-space indentation to make a code block. It's considered bad practice, and most linters will complain about it since 4-space indentation is the "golden rule."

If you're talking about the Python interpreter's interpretation of the tab character in indentation, that's different[1]. In any case, old code that has 8-space indentation using spaces rather than tabs is still good. The only issue would be old code that mixed tabs and spaces for indentation, which might not match up anymore to make correct code blocks. But, in general, it's just a bad idea to mix tabs and spaces for indentation.

[1] To the uninitiated, the Python interpreter treats a tab as X number of spaces when parsing the source code. This means that technically you could mix a block's indentation between tabs and a corresponding number of spaces. For example, if X = 4, then this code block would work:

  def function():
  <tab>something()
      something_else()
Re:Developers who use spaces make more money than those who ... by waqf on Thursday June 15, 2017 @03:46PM (#14563775)
The right solution here would be to treat a tab as exactly pi spaces. This, while not forbidding the use of tabs, would guarantee that any inconsistent mixture of tabs and spaces would be considered misaligned.
Re:Developers who use spaces make more money than those who ... by tom_mellior on Friday June 16, 2017 @03:58AM (#14567329)
> exactly pi spaces

That's an irrational choice.

Re:Developers who use spaces make more money than those who ... by sicariusnoctis on Thursday June 15, 2017 @04:15PM (#14563980)
I think pi*pi is even better. Twice the pi!
Re:Developers who use spaces make more money than those who ... by _yosefk on Thursday June 15, 2017 @04:17PM (#14564004)
"I don't believe it's my position to enforce the amount of whitespace another developer has to use in their editor."

I suspect this might not be my most popular comment, but I honestly think that this is why tab users might actually make less than space users on average. On average, it's more productive to enforce things than leave everything configurable, thus different everywhere, thus harder to make sense of and debug. I knew brilliant people who don't want to "enforce" and decide and dim people who happily enforced and decided and it's always amazing how badly the former do career-wise relatively to their talent and effort, and how well the latter do relatively to theirs.

(Of course there might be another explanation for the data and I don't claim that my just so story is in any way scientific; though I think it should pass as a scientific theory in the social sciences.)

Re:Developers who use spaces make more money than those who ... by ccalf on Thursday June 15, 2017 @06:00PM (#14564788)
It's plausible and goes to show why the blog post choosing salary is itself a bad metric to begin with. It has skewed the entire discussion.
Re:Developers who use spaces make more money than those who ... by zephyrfalcon on Thursday June 15, 2017 @12:09PM (#14561669)
"""The fact that Python's rule used to be 8 spaces, then got changed to 4 thereby invalidating old code really showed me how shortsighted it is to use a set number of spaces in a whitespace sensitive language."""

When exactly did it use 8 spaces? I have been using Python since 1996 and I don't recall this 8-spaces thing. Almost all code I've seen uses 4 spaces.

In any case, it doesn't matter because, as another commenter pointed out, as long as your indentation is consistent, your code will work just fine, no matter how many spaces you use for indentation. Even if some code does use 8 spaces, it should work without problems. (Tabs as well, by the way... it's mixing tabs and spaces that is a problem.)

Re:Developers who use spaces make more money than those who ... by Kevguy on Thursday June 15, 2017 @02:48PM (#14563228)
I may be misremembering since it has been a long time since I've used it, but I thought at one point Python treated one tab as equivalent to eight spaces.
Re:Developers who use spaces make more money than those who ... by IanCal on Thursday June 15, 2017 @11:17AM (#14561164)
First, my golden rule is "do whatever the other devs using the repo do" but

> People who use spaces want to line up their '=' signs, that's fine

To me this feels like it's a good use of spaces as well as tabs. Tabs for indentation, to get your nesting right. Spaces to align things. That way setting your tabs to X spaces works just fine and everything remains nicely aligned.

Though I'm not sure how common this is, so I just use spaces.

Re:Developers who use spaces make more money than those who ... by jdmichal on Thursday June 15, 2017 @11:31AM (#14561316)
Get your blasphemous mixing of spaces and tabs out of this holy war!
Re:Developers who use spaces make more money than those who ... by SamBam on Thursday June 15, 2017 @12:14PM (#14561711)
> This is exactly why I use tabs and the reason which appears to never get cited in the holy wars.

It's probably been mentioned 20 times in this thread alone.

Re:Developers who use spaces make more money than those who ... by hollander on Thursday June 15, 2017 @11:16AM (#14561147)
> People who use spaces want to line up their '=' signs

How does that prevent the use of tabs? You can use tabs to indent, and spaces for your = signs.

Re:Developers who use spaces make more money than those who ... by ElijahLynn on Thursday June 15, 2017 @11:25AM (#14561257)
Mixing tabs and spaces is a nightmare, unless it is your personal non-open project. If a project is open or shared with anyone you need a simple rule to follow. There shouldn't be another leaf in the decision tree for when to use tabs or spaces. We have enough decisions to make the way it is.
Re:Developers who use spaces make more money than those who ... by dagenleg on Thursday June 15, 2017 @01:06PM (#14562211)
> Python's rule used to be 8 spaces

Interesting. Unfortunately I cannot find anything on the internet regarding that. Care to share a link proving that?