Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Why do people hate tab indents?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Why do people hate tab indents?
Chris Katko
Member #1,881
January 2002
avatar

I've seen two distributions now that have marked a commit as "replaced all tabs with spaces."

That sounds incredibly stupid on face value. Why are people doing this?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Johan Halmén
Member #1,550
September 2001

I guess this has been discussed earlier. But I guess there's no standard that says that tabs have to look like anything. They could always mean 4 spaces. Or 5 spaces. Or something else, like to indenting to right after the first space on the previous line.

If you want to copy and paste code into a document that you are writing with Word (or something similar), you don't want the tabs there. Instead you want spaces. Unless you take care of how the tab marks are placed in your text. I'd just paste the code into my text and set the font to some monospace font, hoping that the original coder took care of the indenting using spaces.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

AMCerasoli
Member #11,955
May 2010
avatar

I always use tabs :-/. All editors that I have used to program stuff have the option to define a tab; 3, 4 spaces, etc.

Matthew Leverton
Supreme Loser
January 1999
avatar

I think because a lot of careless, stupid people write code these days. Mixing spaces and tabs is of course evil. And at least if people use spaces, they can easily tell themselves when they've done that.

I prefer tabs because it lets people control the indentation themselves. If you use tabs for indentation and spaces for all other whitespace, there is never any alignment problems.

Talk about copy and paste is nonsense. One tab copied is one tab pasted. :P

StevenVI
Member #562
July 2000
avatar

From my experience, it's been solely an arbitrary choice. However, having everyone on the same project or in the same organization writing code in the same style is important. That way anyone can pick up a source file and it will already be in the format that they are accustomed to reading.

At the two places I've worked over the past 5 years, the rule has been to use four spaces to indent things.

__________________________________________________
Skoobalon Software
[ Lander! v2.5 ] [ Zonic the Hog v1.1 ] [ Raid 2 v1.0 ]

Chris Katko
Member #1,881
January 2002
avatar

I prefer tabs because it lets people control the indentation themselves. If you use tabs for indentation and spaces for all other whitespace, there is never any alignment problems.

I know. Spaces denote whitespace, tabs denote indention! Why is this so hard for people to grasp? And every good editor in the world has adjustable indention depth.

It's like, let's get rid of semicolons because not everyone knows how to use them.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

raynebc
Member #11,908
May 2010

I've always used tabs and always will. Having to deal with spaces is just obnoxious.

kazzmir
Member #1,786
December 2001
avatar

There is only one true amount of indentation, which is 4 spaces. Tabs are a power that are not needed. Since a tab = 4 spaces and its evil to mix tabs and spaces you might as well just use spaces everywhere.

I realize a lot of beginner programmers use a default tab indentation of 8, as I was one of those people too, but I quickly learned the proper way. Its also annoying that the default interpretation of a tab in bash is 8, but its changeable with the 'tabs' program.

torhu
Member #2,727
September 2002
avatar

Yeah, the default size of a tab being 8 spaces is actually one of the advantages of using spaces. Like when viewing diffs in a terminal, which is very handy to be able to do for small and simple diffs when you can do it without them getting messed up. For larger diffs, I prefer to use an editor that color codes diffs. But the "default" tab size really is 8, while the most common tab size for coding probably is 4. Of course, you can only view diffs in a terminal without going insane if you stick with a default line maximum width of 79 or less. Linux Mint (13, don't know about later versions) makes this even more interesting by setting the default terminal width to 78 characters :-/

Mark Oates
Member #1,146
March 2001
avatar

I switched to tabs a long time ago and haven't looked back. Far superior in all the ways that those of us here think are obvious.

Hmm... looking now, it looks like my tabs are set to 4 spaces. :)

StevenVI said:

At the two places I've worked over the past 5 years, the rule has been to use four spaces to indent things.

I think there may be a rule that all workplace jobs require you to do approximately 40-60% of your job incorrectly to appease somebody else. >:(

bamccaig
Member #7,536
July 2006
avatar

The main reason for not using tabs has already been mentioned. The "standard" default interpretation for a tab is 8 spaces. Programming editors allow you to configure that, which is fantastic, but my terminal still presents it as 8 spaces. That and most editors do not show you when you mix tabs and spaces for indentation which can lead to chaos.

I know that it isn't immediately intuitive, but spaces really are better. A decent editor will automatically jump "tab stop" characters over indentation. You won't even realize that you are using spaces if your editor doesn't suck. However, it just makes indentation and alignment so much easier when all of the characters are spaces. I don't have to position my cursor at the beginning of non-whitespace to align things. I can just jump to anywhere in the leading whitespace to do it.

As for people having various preferences, space-based indentation can also be automatically converted reliably and easily without issue. There's no real technical limitation there. Things might get a little bit flaky with multiline strings or heredocs, for example, but as a rule those probably belong in a separate file anyway. For the ones that don't matter enough to move into a separate file you can probably deal with the consequences.

I got turned on to using spaces when I tried Python out. You don't have to use spaces with Python, but it is the defacto standard agreed upon by the community so the tutorials encourage it. I hated Python, but I found that I preferred spaces. If you haven't tried it yet then I suggest you give it a try. Mostly it comes down to using a good editor though. Even Visual Studio can handle space-based indentation, but it's a really crappy editor so you should probably use something better (I personally use VsVim when I use Visual Studio, which at least makes it suck less).

Yes, you are wrong to want to use tabs.

Kris Asick
Member #1,424
July 2001

I choose tabs, some choose spaces, let's be honest here: At least most people use SOMETHING for indenting. Ever go through someone else's code and they didn't indent anything? >:(

--- Kris Asick (Gemini)
--- http://www.pixelships.com

jmasterx
Member #11,410
October 2009

CTRL + Shift + F >:(

Elias
Member #358
May 2000

Only time tabs are ok is if you can be 100% sure nobody else ever has to look at your code (with different tab settings).

--
"Either help out or stop whining" - Evert

Matthew Leverton
Supreme Loser
January 1999
avatar

Elias said:

Only time tabs are ok is if you can be 100% sure nobody else ever has to look at your code (with different tab settings).

???

Chris Katko
Member #1,881
January 2002
avatar

bamccaig said:

That and most editors do not show you when you mix tabs and spaces for indentation which can lead to chaos.

In which case, you have a piece of junk editor. All mine took was a single menu drop down "show whitespace" in KDevelop. Whitespace is whitespace, tabs are small font ">>" embedded into each tab indent. Hell, even Word for Windows 95 supports showing tabs. ::)

Elias said:

Only time tabs are ok is if you can be 100% sure nobody else ever has to look at your code (with different tab settings).

What are you talking about? If they're adjustable by nature, then you can fix the tab view to whatever the other coder was using. And if you're working with plenty of other coders, all it takes is one line of comments "tab width is required to be 4".

If your coders can't be bothered to click a single button typically at the bottom of the screen to adjust the tab width, then you're working with idiots who can't be bothered to adapt to the requirements of the project.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Elias
Member #358
May 2000

If they're adjustable by nature, then you can fix the tab view

As was mentioned, usually the terminal is set to 8-spaces per tab and 78 chars line width, so no.

--
"Either help out or stop whining" - Evert

AMCerasoli
Member #11,955
May 2010
avatar

The terminal? Do you program using the terminal? ???

Elias
Member #358
May 2000

Do you program using the terminal?

Not always, but often I'm just sshed to my dev machine, so yes. And diffs I often inspect in a terminal, and then it's really helpful if no lines are more than 78 chars and if there are no tabs.

--
"Either help out or stop whining" - Evert

AMCerasoli
Member #11,955
May 2010
avatar

Elias... Do you know what appears on Google when I search for "The terminal"?

This:
{"name":"514RQJPS6DL.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/e\/4e1064535b47be15ced2b0fe8d00f019.jpg","w":370,"h":500,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/e\/4e1064535b47be15ced2b0fe8d00f019"}514RQJPS6DL.jpg
And this:
{"name":"DEC_VT100_terminal.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/1\/6197f94c743f9f2fc260857b4ac48d82.jpg","w":2776,"h":2464,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/1\/6197f94c743f9f2fc260857b4ac48d82"}DEC_VT100_terminal.jpg
So, please...

torhu
Member #2,727
September 2002
avatar

I often type hg diff in the terminal. I'm sure people sometimes use grep or other tools on their code.

Chris Katko
Member #1,881
January 2002
avatar

Elias said:

Not always, but often I'm just sshed to my dev machine, so yes. And diffs I often inspect in a terminal, and then it's really helpful if no lines are more than 78 chars and if there are no tabs.

You want us to change our code to be less presentable because you use something modelled to emulate a device created in the 70's?

Also, I use grep all the time with source code and I haven't run into problems yet. And I've been hacking away at the monster called the Dolphin emulator for weeks now.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

bamccaig
Member #7,536
July 2006
avatar

In which case, you have a piece of junk editor. All mine took was a single menu drop down "show whitespace" in KDevelop. Whitespace is whitespace, tabs are small font ">>" embedded into each tab indent. Hell, even Word for Windows 95 supports showing tabs. ::)

Then surely you edit with white-space visible all the time? ??? No, of course you fucking don't because it's harder to read that way. And even if you do to prove me wrong, 99% of people do not and for good reason.

If you don't have visible white-space enabled in your editor then it doesn't do you any good. If you know there are white-space errors then you can either workaround them for fix them (my editor will fix them for me with 7 simple keystrokes).

What are you talking about? If they're adjustable by nature, then you can fix the tab view to whatever the other coder was using.

Unless somebody screwed up aligning something. Even competent coders will regularly make subtle white-space errors, let alone incompetent coders (and those are the majority in the industry).

And if you're working with plenty of other coders, all it takes is one line of comments "tab width is required to be 4".

You have just defeated the only valid argument for using tabs.

If your coders can't be bothered to click a single button typically at the bottom of the screen to adjust the tab width, then you're working with idiots who can't be bothered to adapt to the requirements of the project.

If your editor can't automatically read configuration from the file it's editing then you have a piece of junk editor. 8-) Also, "typically" no there is no tab stop width visible in the UI of most programmer editors. It is typically hidden in an options dialog for GUIs, and for terminal programs probably is controlled by a textual command (it's quite easy to change in Vim, but I'm not going to specially configure my editor every time I open a file; that would be stupid).

The terminal? Do you program using the terminal? ???

About 50% of the time, yes. If I had my way it would be 100% of the time.

You want us to change our code to be less presentable because you use something modelled to emulate a device created in the 70's?

Actually I want you to change your code to be universally presentable.

Modern day virtual terminals and terminal emulators can handle more than 80 characters on supported hardware, but it isn't guaranteed that everybody will have that, and it often requires kernel-level configuration or modules. Not all users have that power, or knowledge, or time. And even when we do, code that is narrow is a lot easier to read than code that is long, even if our environment supports showing the whole line. It's the same way you read a novel. Your eyes don't have to move as far, and you don't have to move your head. It is more efficient.

As for tabs, apparently that is configurable by using the tabs(1) program on supported terminals (and emulators), but (1) that's news to me and (2) probably news to most people and (3) requires modifying your entire environment, where it may be incompatible with other work that you do. It is honestly so much easier to just use spaces. You aren't going to understand until you try it.

See Also

(There are many other threads about this...)

Slartibartfast
Member #8,789
June 2007
avatar

If your coders can't be bothered to click a single button typically at the bottom of the screen to adjust the tab width, then you're working with idiots.

If your coders can't be bothered to adjust their tab settings to the company-wide standard, then you're working with idiots.
If your coders force other coders to repeatedly switch the settings of their editor when they are simply trying to navigate code, then you're working with idiots.

Thomas Fjellstrom
Member #476
June 2000
avatar

I set my indent to three spaces. Suck it internet.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

 1   2 


Go to: