rwaldron / idiomatic.js

Principles of Writing Consistent, Idiomatic JavaScript
Other
24.64k stars 3.46k forks source link

Idiomatic.js differs on many things from what the majority of style guides recommends #117

Closed ottok closed 11 years ago

ottok commented 11 years ago

Please see http://seravo.fi/2013/javascript-the-winning-style

Idiomatic.js should follow what the majority consensus is and e.g.:

rwaldron commented 11 years ago

use ' instead of "

No.

use natural parenthesis (like this) instead of ( this )

No.

not encourage multi-line variable definitions with commas, or at least not forbid doing them with style 1 line = 1 variable

No.

Are you trolling me?

ottok commented 11 years ago

No, I am not trolling. I think you should consider doing things in the way the majority does. It is the best strategy to reach the ultimate goal of getting everybody eventually to write JS that looks the same.

OClement commented 11 years ago

I must say I agree with @Rick on these

Single Quotes requires less keystrokes and looks less busy in the screen when scanning code; it certainly is cleaner. I personally use them all the time; besides, colleagues and myself had a discussion on this last week and decided on using single quotes, for these reasons among others.

About parens, I'm more on the fence here; I always coded (like this), but like the look of ( this ); again I find it much cleaner to read and easier in the eyes. I do try to change my habits and use ( this ) instead

I am not sure I understand the last point (which style you advocate) but I'd say I care less about this aspect; maybe I should read a bit more about this one.

That being said, I think it's important to note that it's not because "a lot" (or even "most") people do certain things way, that it's the right way to do. As developers it is our responsibility to strives and increase our code quality and style, so it gets easier down the road, especially when acing to deal with other poeple's code

rwaldron commented 11 years ago

It is the best strategy to reach the ultimate goal of getting everybody eventually to write JS that looks the same.

That's not this project's or my own goal. You may specify any style guide you want for your project, the point is that everyone should follow the same style guide per project. This happens to be my preferred style guide for my projects.

serbanghita commented 11 years ago

@ottok Your the article specifies that jQuery recommends using multiple line var declarations, but in the source code you can see the contrary: https://github.com/jquery/jquery/blob/master/src/core.js , also the parenthesis are used like this jQuery.ready( true );

The only difference is that jQuery uses double quotes.

ottok commented 11 years ago

Thanks for noticing those, I updated the article to fix these misreferences.