by DocTomoe · 5y ago · 0 comments
There are good reasons for using tabs. I am still to find a good reason for using spaces.
If tabs-as-whitespace trouble you, editors since the 1990s have allowed you to choose/configure other representations of tabs.
They do matter for humans though. The reason we write code and structure it the way we do is for human convenience. One of those conveniences is thinking of the layout of code as a visual help to scan and read it. As such I am very much organizing my code like a graphic designer would organize information.
Edit: Indentations do matter in some languages and used to signify information. But not in a lot of them. The point still stands that most of the time we are using them for visual purposes not information to the compiler/interpreter.
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!
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 ??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.
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? :-)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...
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.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
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.)
I have never experienced this. Tabs are of consistent length, so how can the indentation be garbled?
There can still be alignment issues if different people choose different tab-stop intervals.
The problem is not the tabs, instead it stems from trying to mix lines indented with tabs and lines indented with spaces.
Just the first few that come to mind.
Space bar is our chisel, to craft beautiful codes and reassure our mammal brain that being in the zone make us closest to god