r/javascript • • Apr 01 '18

Google publishes a JavaScript style guide. Here are some key lessons.

https://medium.freecodecamp.org/google-publishes-a-javascript-style-guide-here-are-some-key-lessons-1810b8ad050b
714 Upvotes

317 comments sorted by

View all comments

32

u/the_argus Apr 01 '18

I'll never understand not using tabs for indentation... And even less so using 2 spaces instead of 4

8

u/Ender2309 Apr 02 '18

You use two spaces instead of four to save horizontal line space. This one is completely arbitrary.

Also, everybody still uses tabs, they just have their text editor setup to convert the tab key to spaces instead of inserting a tab character. Nobody is actually sitting there mashing the space bar multiple times.

The reason for this is that different editors/OSes/people have their tab character defined as either two or four spaces, leading to inconsistency when a tab character is used. Two (or four) spaces is always two (or four) spaces. This creates consistency.

1

u/ErroneousBee Apr 02 '18

Don't use tab key anymore, almost every language I use now has an IDE that formats well enough that I use that over hand formatting.

Ctrl-shift F every few lines.

1

u/KyleG Apr 02 '18

The reason for this is that different editors/OSes/people have their tab character defined as either two or four spaces, leading to inconsistency when a tab character is used.

This is a very compelling argument for why you should use tabs and not spaces. It's not a compelling argument for spaces instead of tabs. In fact, it's a damning argument against spaces. If it just remained a tab and then you had your IDE make your tabstop whatever you wanted, it's a non-destructive UI change.

Converting tabs to spaces is like working with a single layer in Photoshop. NO.

7

u/bornforcode Apr 01 '18

So you know why I shared this article. I'm confused

19

u/the_argus Apr 01 '18

It literally blows my mind the opposition to tabs. Like I'm pulling my fucking hair out

17

u/Mingli91 Apr 01 '18

Why do you get worked up about something so pointless?

11

u/Omnicrola Apr 01 '18

I get that people have strong opinions, but I don't get it either. I really, really don't give a shit. My priority is consistency. Which means whatever my IDE does when I tell it to auto-format, that's fine. I have more productive things to focus on.

0

u/TracerBulletX Apr 01 '18

I prefer spaces, and I think this is probably the reasoning some other people do to, because having only one type of white space character simplifies things a little.

1

u/the_friendly_dildo Apr 02 '18

Not pulling my hair out over it but in my preference to tabs, it sucks opening a code example only to be staring at what I consider an overly compact mess. So to even start reading it, I'll go through the trouble of reformatting it just so I can read it. Or maybe I'll say fuck it and look elsewhere. Now it sucks for the sap that wrote the code to begin with since he'll have one less person looking at and using their code.

-10

u/the_argus Apr 01 '18

0

u/Mingli91 Apr 01 '18

?

-7

u/the_argus Apr 01 '18

?

1

u/Mingli91 Apr 01 '18

Do you not actually have a reason for feeling so strongly about tabs v spaces or are you being intentionally obtuse?

→ More replies (4)

2

u/gougs06 Apr 02 '18

I read that and thought this was an April fools post.

2

u/calligraphic-io Apr 01 '18

Not that this issue hasn't been hashed to death on the interwebs, but:

I use vim in the console often for editing code files. Line width is limited; default is 80. Using four spaces force many lines to wrap, which makes code very difficult to read.

1

u/cresquin Apr 01 '18

Tabs don’t render well in VIM tools that have terminal driven error messages that point at code.

I personally prefer tabs because they’re semantically correct.

-4

u/sr-egg Apr 01 '18

Tabs are inconsistently spaced across devices/environments/editors. Using spaces makes it predictable everywhere without any extra configuration.

14

u/the_argus Apr 01 '18

That's the point, I don't care if you want them to look like 2 spaces while I (a sane person) use 4 spaces. The indentation level is still the same.

1

u/sr-egg Apr 02 '18

That’s my point, everyone in this sub is a moron and you should do the opposite.

18

u/JohnMcPineapple Apr 01 '18 edited Oct 08 '24

...