3 ms·
No semicolons, two space indentation, space after function name, single quotes for strings? There's no way this would fly with a majority of developers.
by distances 11y ago
No semicolons, two space indentation, space after function name, single quotes for strings? There's no way this would fly with a majority of developers.
- jsmith0295 11y agosinglequotes for strings is very much a standard thing in JS. And two space indentation is fairly common as well. The no semicolons and space after function name are really the weird things here.
- sratner 11y agoI thought so too at first, as those were the only things that disagreed with my previous style. However, I've been using "standard" for a bit now, and have to say that both of those decisions have really grown on me in light of ecma2015 features. Space after function name works well with generator functions and yield. Semicolon placement has become somewhat less consistent with the new object literal and class syntax and skipping them everywhere has saved me from constantly trying to remember whether I need one after a particular function or method definition.
- Grue3 11y agoWhy would you prefer single quotes over double quotes? An apostrophe is not just punctuation in English, it is necessary to preserve the meaning of certain words (like "its"/"it's"). So in a way, it can be considered to be another, albeit rare, letter of the alphabet. Now if somebody proposed to delineate strings with the character "x" everyone would agree it's a bad idea. For the same reason, using "'" to delineate strings is also bad, and shouldn't be encouraged.
- robin_reala 11y agoBecause a lot of JS developers have traditionally manipulated strings of HTML, which have standardised on double quotes for attributes. Also, straight quotes as punctuation are ugly; ‘ and ’ look much nicer.
- WorldMaker 11y agoThere's also the subtle laziness that double quotes require an extra keypress (Shift). It's not a great reason to prefer single quotes over double quotes, but it is a useful reason if you are writing a lot of strings. JS has a lot of things that key off strings (because it doesn't have a proper enum type and the Symbol type is too new for a lot of usage yet), so you type a lot of "non-English text" strings, so single quotes make a lot of sense for the majority of uses of strings in JS. English text I typically still "double quote" or `template string quote`.
- tlrobinson 11y agoUntil you mentioned it I was not even conscious of the fact that double quotes required pressing shift, yet I type hundreds of them every day.
- zappo2938 11y agoTwo space indentation is a deal breaker for me.
- jdmichal 11y agoI really really don't understand space indentation over tabs. Every editor known to man allows you to set tabs to display with as many spaces as your heart desires. You like four spaces? Great! You like 2? Not my cup of tea, but OK! You like 8? Weirdo, but whatever! As long as your editor spits out tabs, then we can all live in harmony! EDIT: Looks like I should have joined the fight elsewhere in the comments; please redirect discussion here: https://news.ycombinator.com/item?id=11588783 https://news.ycombinator.com/item?id=11588783