rwaldron / idiomatic.js

Principles of Writing Consistent, Idiomatic JavaScript
Other
24.83k stars 3.48k forks source link

Should the "switch" example have a space before the first paren? #134

Open leoj3n opened 10 years ago

leoj3n commented 10 years ago

https://github.com/rwaldron/idiomatic.js#misc

Should it be written switch ( instead of the current switch(?

jamsyoung commented 10 years ago

Yes, switch is not a function so it should have a space before the (. I am not a fan of inner-space, so I would write it as:

switch (foo) {

For those that do use inner-space:

switch ( foo ) {
sopta commented 10 years ago

I don't think that inner-space give more readability in the switch statement.

jcblw commented 10 years ago

This is in-line with the way that functions are declared

var foo = function( bar ) {
}

switch( bar ) {
}

the style in which the switch is declared seems accurate to me.

jamsyoung commented 10 years ago

switch is not a function, it is a statement, so it should have the space before the paren to make this clear. Also, practically every example I could find, outside of this instance, shows the space in front of the paren.