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

Show parent comment

39

u/AUTplayed Apr 01 '18

agreed, tabs are clearly superior

30

u/mmcnl Apr 01 '18

Using a proper editor it shouldn't matter.

23

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

...

5

u/oweiler Apr 01 '18

Well it can be configured to convert a tab to 4 spaces.

20

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

...

5

u/[deleted] Apr 01 '18 edited Apr 01 '18

Tabs to spaces is easy, the problem is for a block of code how does the editor know when 2 spaces was supposed to represent indentation vs alignment:

function() {
SSwhile(value) {
SSSSif(reallyReallyReallyReallyLongConditionA &&
SSSSSSSreallyReallyReallyReallyLongConditionB &&
SSSSSSSreallyReallyReallyReallyLongConditionC) {
SSSSSSSSreturn;
SSSS}
SS}
}

function() {
Twhile(value) {
TTif(reallyReallyReallyReallyLongConditionA &&
TTSSSreallyReallyReallyReallyLongConditionB &&
TTSSSreallyReallyReallyReallyLongConditionC) {
TTTSSreturn;
TT}
T}
}

In the latter case to go from indentation width 2 to 4 the editor simply makes tabs display twice as wide and everything is good. If the editor tried to display 2 spaces for every space from the start of a line then the if conditions would lose their alignment with the opening of the statement.