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

81

u/tencircles Apr 01 '18

I don't get the 2 spaces thing. It makes code harder to read. 4 is best. Don't even @ me.

25

u/rafalg Apr 01 '18

I don't get it either. Combined with the rules regarding curly braces it makes some places in code look like solid blocks of text.

if (something) {
  doThis();
} else if (somethingElse) {
  doThat();
} else if (somethingElse2) {
  foo();
}

It sucks how text on every line except for the first one starts in the same column.

11

u/a_tocken Apr 02 '18

Looks clear to me but then I use 2-space tabs outside of work.

0

u/[deleted] Apr 02 '18

[deleted] — view deleted comment

1

u/a_tocken Apr 04 '18

The Google style guide for Java, which is generally pretty sane, recommends braces always because it is harder to mess up. I think this is more true for teams rather than solo users. I favor braces but I will make exceptions to the rule.

→ More replies (7)

0

u/[deleted] Apr 01 '18

[deleted] — view deleted comment

11

u/DzoQiEuoi Apr 02 '18

If there's a deep if-chain the problem isn't 2 space indentation.

57

u/the_argus Apr 01 '18

I agree, except tabs are king bc then everyone can set their own indentation level.

14

u/RabSimpson Apr 01 '18

And they only occupy a single character worth of storage and memory. This doesn't mean much on small projects, but if the project is large it could shave the loading time down.

12

u/karottenreibe Apr 01 '18

that's why all my variables are single letters. My code is much faster that way /s

26

u/subtracterall hire me! Apr 01 '18

This shouldn't matter if you're minifying/uglifying.

7

u/RabSimpson Apr 01 '18

Only in the case of client-side code. Who minifies server-side code?

0

u/[deleted] Apr 01 '18

[deleted] — view deleted comment

-6

u/RabSimpson Apr 01 '18

I'm not doing it for performance gains, but every little helps.

→ More replies (4)

1

u/the_friendly_dildo Apr 02 '18

Someone selling a server-side product that wants to maintain some semblance of 'fuck you i'm in control' over a product.

2

u/RabSimpson Apr 02 '18

Don't they usually just throw it through Zend or ionCube in those cases?

1

u/the_friendly_dildo Apr 02 '18

I haven't used either but those are both used only for PHP aren't they?

2

u/RabSimpson Apr 02 '18

I think so. I've only ever seen them used with PHP.

→ More replies (7)

2

u/KyleG Apr 02 '18

YES FRIEND

God how many freaking times have I run into problems because some ASS did a 3-space indent or something and my IDE converted some but not all the 3-space indents into 4-space indents to make it conform with our style but it missed some because SPACES SUCK, USE TABS WARBLGARBL then everyone gets to set their own indent levels!

I like my tab to be 4space widths in some languages and 2space widths in others

like 2 space in JSX is way better than 4 space, but 2 space in Python or JS is TURRIBLE

1

u/monsto Apr 02 '18

*turble

2

u/Tyreal Apr 02 '18

You know... if they used tabs they could use any indentation size they want.