« prev   random   next »

4
0

Tabs vs Spaces

By Patrick follow Patrick   2019 Mar 21, 8:36pm 799 views   8 comments   watch   nsfw   quote   share    


When typing code, no one should ever use tabs. Every tab character is an error and should be counted as such. The use of any tabs should block the acceptance of the code.

Tabs are individually hard to see and annoying, like a mosquito in one's bedroom at night. Collectively, they are a disaster for humanity on the scale of malaria.

One character should look like one character, and never like a variable number of characters depending on who might be viewing it. Code cannot get better aligned than a perfect grid, as it is with spaces. With tabs, the perfect grid is destroyed, so that one line cannot reliably refer to the previous line with a carat ^, or line up trailing comments with the comments on the previous line.

With spaces, all members of a team see the exact same thing, which is important for communicating code intent and parallel statements via formatting.

Everyone wants his beautiful work to appear right for everyone else, but tabs make the work inconsistent and ugly.

The argument that we can all have different indentation levels only by using tabs is false. Those who want different tab sizes can autoconvert leading spaces to tabs with their editor, and convert back to spaces when committing code. Everyone can have what he wants if everyone uses pure spaces as the definitive indentation format. Not so with tabs, because with tabs, it is inevitably necessary to mix in spaces at times, resulting in confusion. Tabs jumble things up when people use different tabstops. And if a team all uses the same tabstop, then why not just use spaces?

One might try to argue the reverse, that tabs should be the standard and people who want spaces should autoconvert leading tabs to spaces, but that does not work for the simple reason that information is lost when spaces get converted to tabs. Things can be perfectly lined up with spaces. But if starting from tabs and converting to spaces, there is no inherent way to know exactly how far one should space to retain alignment because tabs lack that information.

Tabs are ambiguous. Or think of it in terms of information: four spaces, being four characters, contain more information than one tab does. The tab says "move over some unknown distance". The spaces says "move over exactly this specific distance". The cost of storing that information is trivial these days, and the value of the information is significant.

Imagine replacing the Cartesian coordinate system with a system where increasing a value on the x axis is always subject to uncertainty. You would never be able to graph anything correctly.

Spaces mean happiness for everyone. Tabs mean unnecessary complexity and sadness.

Tabs were meant for making tables, not for indentation. That's why they are called tabs.
Tabs failed both at making tables and at indentation.

With spaces, what one sees is what one gets. Tabs are invisible to the naked eye, so one cannot know where things are just by looking. The code might be a mix of tabs, spaces, tabs...

With spaces, life is simple. In vim, when displaying the cursor position on a line with "set ruler", one gets two numbers with tabs. WTF? Oh, it's characters and columns! Why? Why bother to add the ambiguity and complexity?

Spaces are not optional. All written works in the last few thousand years have used spaces. Code will have spaces for sure. Tabs are optional, a harmful extra complication.

It’s impossible to get spaces wrong. There is no "spacestop". There is only the annoying and inconsistent "tabstop", which no one needs to use if no one uses tabs.

Every IDE/editor supports replacing tab presses with a number of spaces. There is no speed to be gained in using tabs.

When one copies and pastes code with spaces, it always works perfectly.
When one copies and pastes code with tabs, it may get fucked up in various ways, such as seeing tabs come out as ^I.

Python is indentation based, and Guido recommends spaces. Python users know about indentation, because the language depends on it.

Book and magazine publishers can't deal with tabs in source-code listings to be printed. They demand conversion to spaces. And they are right to make that demand.

The right answer for misguided people with tab fetishes is to convert spaces to tabs when reading, and tabs to spaces when writing.

Would babies really die if we just said 4 spaces, everywhere, always, no choice - and moved on?
1   just_adhom_preaching   ignore (4)   2019 Mar 21, 10:00pm     ↓ dislike (0)   quote   flag      

Just map your tab key to the number spaces you want.
2   just_adhom_preaching   ignore (4)   2019 Mar 21, 10:02pm     ↓ dislike (0)   quote   flag      

You still have to use tabs in Makefile though.
3   Tenpoundbass   ignore (14)   2019 Mar 22, 7:04am     ↓ dislike (0)   quote   flag      

I never knew it was an issue.
Paste it in NotePad++ and view all special characters, then find and replace the tabs.
After that you are free to use the formatter plugin.
4   Patrick   ignore (1)   2019 Mar 22, 8:58am     ↓ dislike (0)   quote   flag      

just_dregalicious says
Just map your tab key to the number spaces you want.


Yes, that's all there is to it.

Pity about makefiles. Someone should really fix that.
5   FortWayneIndiana   ignore (4)   2019 Mar 22, 9:04am     ↓ dislike (0)   quote   flag      

I suggest a political compromise. Tabs half the time, spaces other half.
6   Blue   ignore (0)   2019 Mar 22, 9:05am     ↓ dislike (0)   quote   flag      

Tab character is evil, going forward it should be removed or replaced from the key board.
7   Tenpoundbass   ignore (14)   2019 Mar 22, 9:49am     ↓ dislike (0)   quote   flag      

Even if you never use the Tab ASCII character, the tab key still has use for moving focus to the next form element.
8   Patrick   ignore (1)   2019 Mar 22, 2:53pm     ↓ dislike (0)   quote   flag      

Blue says
Tab character is evil, going forward it should be removed or replaced from the key board.


Tenpoundbass says
Even if you never use the Tab ASCII character, the tab key still has use for moving focus to the next form element.


The tab character is pure evil, but the ability to move from field to field in a browser, or to switch apps (alt-tab) are useful.

Maybe the solution is for editors to refuse to accept the tab character.

And while we're at it, caps lock should always be disabled. I literally used to pop it off of the keyboard on my own computers because if you hit it in vim in command mode, suddenly your navigation goes insane and it takes a minute to figure out why.

about   best comments   contact   one year ago   suggestions