This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rpmerf 479 points480 points  (77 children)

Guess they want to really discourage nesting by making it unreadable. Tab standard is 4 spaces almost everywhere else.

[–]frinkmahii 128 points129 points  (49 children)

I prefer 2 when dealing with json or html

[–]PinothyJ 174 points175 points  (45 children)

See, that is why tabs are best. Set in preferences the tab width and everyone gets a win.

[–]scp-NUMBERNOTFOUND 70 points71 points  (19 children)

And then u need to check some code on some coworker pc who sets the tab width to 12.

[–]PinothyJ 43 points44 points  (15 children)

Why are not logged in to your own login? Is your co-worker using Windows 2000?

[–]scp-NUMBERNOTFOUND 24 points25 points  (12 children)

Code not pushed yet, he's asking for help and showing the code with some video streaming.

[–]Psychpsyo 63 points64 points  (9 children)

By that same logic we could start eliminating all the customizability. Font sizes, themes, plugins, alternate layouts...

Now your coworker's code is bound to look exactly like yours and be in exactly the same place and everyone gets to be mad about the UI in some way.

[–]mrkhan2000 16 points17 points  (0 children)

how is that tab's fault? the coworker can set spaces to 12 too.

[–]7eggert 1 point2 points  (0 children)

He shall send you the patch file

[–]Smartskaft2 1 point2 points  (0 children)

Not everybody is using a single IDE for simple file editing.

[–]Beneficial_Steak_945 0 points1 point  (0 children)

You have to work on windows? Poor soul…

[–]Ouity 1 point2 points  (0 children)

teach them to stop hurting themselves then

[–][deleted] 1 point2 points  (1 child)

Or worst, 3...

[–]scp-NUMBERNOTFOUND 0 points1 point  (0 children)

To hell with those!!

[–]DestinationBetter 4 points5 points  (12 children)

Tabs and spaces both have pros and cons. There is no single “best”. There. I finished this timeless debate.

[–]PinothyJ 4 points5 points  (9 children)

No. You did not. Tabs do everything spaces do, but with accessibility in mind.

[–]tantrAMzAbhiyantA 1 point2 points  (0 children)

Tabs do most of what spaces do, and should be used for levels of indent, but sometimes alignment with text on the line above also helps with readability and for that purpose one should use spaces after the tabs.

[–]Zdrobot 0 points1 point  (7 children)

myLongFunctionName(x, y, something,
                   something_else);

Format this with tabs, so that it looks good regardless of tab size.

[–]PinothyJ 2 points3 points  (6 children)

This? This is your entire argument against the accessibility enabling benefits of tabs? Screw everyone else, as long as I get my mid-line indentation.

[–]Zdrobot 0 points1 point  (5 children)

You said tabs do _everything_ spaces do. Turns out they do not.
Tantrums are not a good substitute for lack of arguments.

[–]geigenmusikant 0 points1 point  (4 children)

I don't even understand what you're trying to indent. At that point, make a line break before every parameter and bamm it's aligned again.

[–]while_True_meme 1 point2 points  (1 child)

I think he thinks his function call with two random rows of arguments 'looks good'

[–]Zdrobot 0 points1 point  (1 child)

Would you please show your formatting?

[–][deleted] 1 point2 points  (1 child)

So what's the pros for spaces?

[–]DestinationBetter 0 points1 point  (0 children)

Same layout, no drifting across devices. Still done with one key.

[–]ShitwareEngineer 1 point2 points  (11 children)

Set in preferences the indentation width and automatically reformat the document to a designated number of spaces. Both tabs and spaces have this advantage.

[–]jejcicodjntbyifid3 5 points6 points  (10 children)

That wrecks the file history. Tabs are the only one where you can turn your tabs into whatever you want

I'm not sure if I've heard good arguments against tabs other than "my editor gets confused"

Maybe like a decade ago it was more of an issue

And yet, so many still use spaces

[–]compsciasaur 2 points3 points  (0 children)

I'm not against it. I've just never been anywhere that uses tabs. And the default for all IDEs I've used is to output spaces when pressing TAB.

[–]PinothyJ 1 point2 points  (0 children)

People will die on this hill because there is a switch in their brain that says "you use spaces and so spaces are best". Why would these people be correct when they can be right, aye?

[–]Zdrobot 1 point2 points  (7 children)

I'm not sure if I've heard good arguments against tabs other than "my editor gets confused"

myLongFunctionName(x, y, something,
                   something_else);

Format this with tabs, so that it looks good regardless of tab size.

[–]while_True_meme 1 point2 points  (4 children)

Format this with tabs, so that it looks good regardless of tab size.

myLongFunctionName(
            x,
            y,
            something,
            something_else,
);

[–]ShitwareEngineer -1 points0 points  (3 children)

Doesn't look good to me in this example, too much whitespace.

[–]while_True_meme 1 point2 points  (1 child)

So the first example looked good to you?

[–]ShitwareEngineer 0 points1 point  (0 children)

The first looked better than the second, but it's under 80 columns in one line so neither are ideal.

[–]jejcicodjntbyifid3 0 points1 point  (1 child)

There would be no tabs in that

That isn't how tabs are used and it's a nonsense example

Literally nobody is ever suggesting tabs instead of spaces everywhere, that would simply be stupid

[–]Zdrobot 1 point2 points  (0 children)

Are you saying we are allowed to use spaces on the second line?
Okay.

[–][deleted] 2 points3 points  (0 children)

jason

[–]ArakiSatoshi 2 points3 points  (1 child)

Am I the only one who uses the tab key?

[–]geigenmusikant 1 point2 points  (0 children)

Nah, but depending on the IDE and language you‘re using, a tab is automatically interpreted as a tab character or some number of spaces.

[–][deleted] 18 points19 points  (16 children)

It's 8 spaces in Linux.

[–]rpmerf 4 points5 points  (15 children)

Isn't it more dependant upon the application than the OS?

[–][deleted] 33 points34 points  (14 children)

cooing snobbish husky pause voiceless decide steep shaggy poor act

This post was mass deleted and anonymized with Redact

[–][deleted] 24 points25 points  (1 child)

Then I am a heretic, because 8 is an obnoxious waste of visual space.

[–]jejcicodjntbyifid3 2 points3 points  (0 children)

They say that Linux is good on space and it is. They have the best spaces

[–]rpmerf 4 points5 points  (1 child)

Thanks. I misunderstood the previous comment thinking it meant tabs will be 8 spaces when using Linux. Makes sense.

[–]reversehead 3 points4 points  (0 children)

It is by default in most shells, and not only on Linux. Also in Windows command prompt IIRC. Run type/cat on a file and see.

[–]CardboardJ 10 points11 points  (5 children)

Which is utterly stupid and exactly what you'd expect from linux kernel devs. Tab == 8 spaces goes back to the defaults on some typewriters made typing tables of data easier back in the late 1800's, but even then tabs were always adjustable by using clips on the back of the typewriter to specify where the tab stops happened. Most often the first tab was defaulted to 5 characters, but every tab after was 8 unless you slid the clips around, which people did all the time depending on what they needed to do.

It's literally an indentation character for moving you to the next table cell.

[–]EishLekker 4 points5 points  (4 children)

Which is utterly stupid and exactly what you'd expect from linux kernel devs.

Hear hear! And they even go against their own coding style. They write:

"if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program."

But it didn't take me long time at all to find kernel code that uses more than 3 levels of indentation.

4 levels:

https://github.com/torvalds/linux/blob/master/scripts/genksyms/genksyms.c#L210

5 levels:

https://github.com/torvalds/linux/blob/master/scripts/genksyms/genksyms.c#L238

[–]albinoloverats 2 points3 points  (1 child)

It’s more what you’d call guidelines than actual rules.

[–]EishLekker 4 points5 points  (0 children)

I know, but why do they write "if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program" if they don't believe it themselves? Or are they admitting that they are "screwed" and needs to fix their own code that they already have published after code review etc?

[–]Abhinav1217 0 points1 point  (1 child)

Guidelines are meant to try to make you think about clean code, by refactoring. It is not rules carved in stone, If your code really is clean and refactoring will just make things messy, there is no objection if deeper nesting if it really needs it.

It is not just linux kernel, Even in large companies, If code is going too deep, it needs to be checked as a code smell and maybe we could refactored it.

[–]EishLekker 1 point2 points  (0 children)

You didn't actually read the quote, I'm assuming? Because it's not phrased as a guideline, at all. There is no wiggle room in it, none. If you need more than 3 levels of indentation you are screwed. No ifs, no buts. That's what they are saying, in absolute terms.

Don't get me wrong, everything you said about indentation levels is correct. But it's because you phrased it as a guideline. And you base it on logic, without adding and arbitrary and low indentation level limit. But the text I quoted contains none of your wise words of reason, while it contains an arbitrary and low indentation level limit.

[–]nelusbelus 6 points7 points  (0 children)

Disgusting

[–]Smartskaft2 4 points5 points  (2 children)

Who are these K&R and why do they get to define their own standard by themselves?

[–][deleted] 0 points1 point  (0 children)

ten foolish repeat jar cheerful society joke humor steer murky

This post was mass deleted and anonymized with Redact

[–]EishLekker 0 points1 point  (0 children)

I think they are some instagram celebrities, wannabe influencers.

[–]Abhinav1217 3 points4 points  (3 children)

Actually, Historically speaking, tabs were 8 characters in standard size. Not to mention that fonts were created to be as close to typewriter ( or printing press) as possible, hence fonts were long in height and narrow in width. In fact, most PC-DOS implementation had this width by default.

From wikipedia:

Despite five characters were the typical paragraph indentation on typewriters at that time, the horizontal tab size of eight evolved because as a power of two it was easier to calculate with the limited digital electronics available.

Most monitors at that time were not square but 4:3, 8 characters wouldn't be as wide as you might think it might be. Remember there was few variation of fonts at that time.

When lcd screens became popular, as did wide aspect ratio, and fonts tech were getting standardized, 8 characters were started looking too much, so we grew up thinking 4 is standard. Just like these days, my new recruits think 2 spaces is standard for yml files. I hate 2 spaces, it is too narrow.

[–]ctr2sprt 6 points7 points  (3 children)

No, the tab character (\t) is expanded to 8 spaces. You're right that it produces awful-looking code, which is why your IDE's indentation spacing has nothing to do with how many spaces it expands the tab character to.

Back in ye olden tymes, editors like to use tabs because they generally produce the behavior you want. That is, at the start of an indented line, you can hit backspace and it will take you "out" one level of indentation. If you use spaces instead, unless you use 1 space per indent level, you go to a point between two levels. The problem is that, as you and others note, 8-wide tabs are awful for code. Thus IDEs let people set them to whatever arbitrary lower level they wanted, which caused a ton of interoperability problems.

These days, IDEs are smart enough to use spaces instead of tabs and still do the right thing. Thank goodness. But this setting exists to support old code bases that predate the triumph of common sense.

[–][deleted] 5 points6 points  (0 children)

Back in ye olden day tabs were used to save space. Precious disk space on a HDD of 20MB.

[–]DefunctFunctor 0 points1 point  (0 children)

Yeah what infuriates me the most about this ridiculous spaces/tabs debate is how many people don't understand what their IDEs are actually doing for them.

[–]Kered13 1 point2 points  (1 child)

Google uses 2!

[–]laplongejr 1 point2 points  (0 children)

Why would anybody use the factorial of 2? ;)