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.