Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Name a few please. I can only think of garbled alignment when reading a diff of a file which used tabs to indent. And that is not really speaking for tabs.


Well, the most basic one is that if I prefer that my code blocks indent on 4 visual "spaces", but you prefer that it does on 2, there's no way of representing that with spaces. Tab means, 1 indentation level. How you choose to display that is then a matter of personal preference. So you can have your cake and eat it too.

Then if I or someone else needs to de-ident a line you remove 1 char. Plus, if your IDE&mode is worth its salt, hitting tab on an already indented line doesn't do anything, and because it has a simple meaning, hitting tab on a non indented line simply indents it.

Of course, if people mix tabs and spaces without understanding them it will be garbled. Or if people just want the cake for themselves, greedy spacers!


That does not work in practice. Consider

    void foo() {
        connect(this, action,
                that, callback);
    }
If the "that, callback);" line was indented with tabs, then any other tab length would make it go at any random place. Thus if you just use tabs your code is only readable with the tab length used for writing it. So instead you can introduce spaces for alignment ; now that you have spaces needed for alignment, why not just use spaces for everything instead of two characters ??


So that anyone viewing the code can choose the indentation width according to their own preference? It really can't be that hard to grasp...

It can still be argued that it's not worth the trouble, especially with the poor tooling available, but what I can't really understand is how supposedly smart people turn off their inner logic when it comes to such a simple concept.


> So that anyone viewing the code can choose the indentation width according to their own preference? It really can't be that hard to grasp...

but viewing that code with anything other than the tab length it was written for breaks it !

here are some screenshots:

- I wrote the code with ts=4 and it looks as it must look: https://imgur.com/Bgr6Pvl

- if your editor is configured for two spaces tabs ? broken ! https://imgur.com/oxj2If7

- if your editor is configured for eight spaces tabs ? broken ! https://imgur.com/puCqdL8


Why are you writing this to me? You already commented on (another) comment of mine which explained what is meant by indentation with tabs and alignment with spaces.

A function call has an indentation level (depending on where it resides in the code); if for whatever reason you split the call on multiple lines, all the lines should have an equal amount of leading tabs to signal that level of indentation – different arguments in a function call do not have different indentation levels. If you choose to align the contents on the lines, for example to the opening parenthesis, you do so by using spaces.

In your own words, this is "all those shenanigans" but you can't possibly try to convince me it is that hard to understand or would not work. Of course it does.


> Why are you writing this to me?

I just reply to the comment text

> what is meant by indentation with tabs and alignment with spaces.

but I said at the beginning that this was not good:

> So instead you can introduce spaces for alignment ; now that you have spaces needed for alignment, why not just use spaces for everything instead of two characters ??

In my experience, allowing both tabs and spaces just leads to that kind of mess, consistently: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-... and for zero good reason as alignment is a semantic thing, and tools cannot understand the semantics of your code (at a human level, not a "pl semantic" level)


Feels like the vi vs emacs fight. For some people, it seems easy to only see their side and consider the others "smart but dumb" or similar. The reality is probably somewhere else. Tastes differ, and just because someone is not sharing your view on things doesnt necessarily mean they are doing something wrong.


eMSF says "what I can't really understand is how supposedly smart people turn off their inner logic when it comes to such a simple concept."

It's part of our human nature, which sometimes gets out of control. Imagine the following as a programming languages discussion rather than a religious one, and ending (rather abruptly) instead with "Spaces vs Tabs":

https://www.theguardian.com/stage/2005/sep/29/comedy.religio...

That's us!


As a tabs user I generally prefer this for multiline function calls, using a tab for alignment. I only use spaces for alignment for whitespace that isn't at the start of a line.

    void foo() {
        connect(
            this, action
            that, callback
        );
    }
I answer your question with another: If your editor is configured to create four spaces when you press the TAB button, why not insert a TAB instead? :-)


> If your editor is configured to create four spaces when you press the TAB button, why not insert a TAB instead? :-)

But I never press the tab button. It just aligns correctly when I press enter depending on the context. I however really want my code to not break whatever the editor anyone is using, and that means using spaces.


If it's not using my preference for the size of a tab then it's broken.


Well, this would be something that the IDE/mode you're using reflects. The indentation isn't "fixed", if you're inside a block it will be something, if it has an open parens, then it might indent on the open parens, or two spaces after the parent line declaration start?

I know what you mean because some modes (ie. in emacs, but I guess every other editor as well) sometimes will not be indenting how I think is correct, but this is not a problem with the "concept". I'm sure if we can cram artificial intelligence to give you the full word you're typing we ought to be able to make indentation by tabs work correctly across editors/machines/modes/plugins - and each "plugin" for whatever language can have its own idea of what is the right way (that would still be customisable - at least that's how it works with emacs). It's also a problem that only needs to be solved once per editor and then can be reutilised by whatever plugins using their own definition of what is the visual size of the tab and how it behaves on other semantic blocks of the language in use.

I've moved to use formatters in languages that have a strict one so to not worry about this, I can even understand saying that just using spaces solves it, as it's the same everywhere - but essentially it mixes things - one is a question of visual representation that should be represented by a unit that a user can define (tab), the other is significant whitespace.

In your example, with whitespaces, it's basically arbitrary - here it's 12spaces, next function where you multiline the arguments, it's `connect_more_14_chars(` so it will be 26 whitespace chars...


> one is a question of visual representation that should be represented by a unit that a user can define (tab),

where does this assumption come from ?

> In your example, with whitespaces, it's basically arbitrary - here it's 12spaces, next function where you multiline the arguments, it's `connect_more_14_chars(` so it will be 26 whitespace chars...

in practice it'll just be one key press as tools do the alignment. why would the number of whitespace chars matter at all ? what matters is that things are aligned.


> where does this assumption come from ?

From the fact that with exception of languages with significant whitespace/tab it's a matter of visual representation:

  void foo() {
          connect(this, action,
            that, callback);
  }
Perhaps I would prefer that my editor in this language, did this formatting. It doesn't change the meaning of the program.

> in practice it'll just be one key press as tools do the alignment. why would the number of whitespace chars matter at all ? what matters is that things are aligned.

This would be the same with tabs. But we go back to the same presentational aspect. If you prefer that it indents on the open parenthesis, and I that it indents on parent line start + 2 "visual" spaces we can't make an editor that covers both our preferences. With tabs, at least theoretically, we can, since the tab has no other meaning than an "indentation level" (which then translates into whatever it means "whitespace wise" for a given situation).


It's really not hard to understand...

The second and third lines have a single tab to do a lexical indent. Then the third line uses spaces to align the "that" with "this".

Not that I see any reason to format code this way; IME it makes code much less predictable when reading and thus more cognitive load to read and understand.


    void foo() {
        connect(this, action,
            that, callback);
    }
problem solved.


This is a good example of a pointless alignment footguns tabs prevented.

Why do you want to recalculate the number of spaces before 'that' based on any change to the length of the function name 'connect', and why do you realize you don't want to when it comes to aligning connect with 'foo' to be consistent with this styling instead of indenting priority?

Much easier to hit tab twice on the 3rd line because that is the correct nesting depth and not try to adapt lines based on insignificant aspects of previous lines and not make someone refactoring try to hop around any more than necessary.

Edit-typos


> Why do you want to recalculate the number of spaces before 'that' based on any change to the length of the function name 'connect'

from experience ? connect is a Qt function that dates back to 1995, it's been here for the last 30 years, it'll be there when I retire. Optimizing my experience for "what if connect was renamed" is a big YAGNI.

> , and why do you realize you don't want to when it comes to aligning connect with 'foo' to be consistent with this styling instead of indenting priority?

I don't understand what you mean there, what would "aligning connect with foo" mean ?


> from experience ?

Then that's a bad example since this alignment with preceding line style commits you irregardless of your history with any function.

> I don't understand what you mean there, what would "aligning connect with foo" mean ?

If you are aligning with lines above you and your coworkers have so many options:

    void foo(..
         connect(..

    int foo(..
        connect(..

    int foo(..) {
                 connect(
If you are nesting with fixed indents, then everything is fairly well defined and simple changes to one line don't cause significant reflow.


So I don't agree with GP poster that there's no reason to use spaces for indentation, but Rome recently switched to using tabs for accessibility reasons:

https://github.com/rome/tools/issues/425

(Especially look at the Reddit thread linked from that issue: https://www.reddit.com/r/javascript/comments/c8drjo/nobody_t... )

(The problem is that people with visual impairment disabilities benefit a lot from being able to customize tab widths.)


> garbled alignment when reading a diff of a file which used tabs to indent

I have never experienced this. Tabs are of consistent length, so how can the indentation be garbled?


Tabs are not of consistent length. A tab does not insert X spaces worth of whitespace. A tab moves the cursor to the next tab-stop.

There can still be alignment issues if different people choose different tab-stop intervals.


That's why tabs are used for indentation and not alignment. From col 0 on tabs are consistent.


The only case I can think of is when the patch has lines above or below indented with spaces and a modified line with tabs. It looks OK in an editor, but the extra +/-/space from the diff doesn't move the tabbed code, which still is indented to the tab-stop boundary (the tab "absorbs" the diff marker). The space-indented lines are moved 1 to the right by the diff marker, but the code on the tab line now looks to be 1 character too far to the left in the diff.

The problem is not the tabs, instead it stems from trying to mix lines indented with tabs and lines indented with spaces.


- semantic coherency: use only one character to signify an indentation level - user preference of UI representation of code: decide for yourself how far a tab indents a codeblock. - less reformatting necessary during refactoring and rewriting - separation of keyboard keys for different functionality

Just the first few that come to mind.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: