News for hackers. Stuff that matters.
Re:Airbnb JavaScript Style Guide by YorkianTones on Friday July 03, 2015 @01:39AM (#9823716)
If you use contractions like don\'t inside of a string then you need to escape the apostrophe if you\'re using single quotes, which is annoying and can make the string a bit harder for humans to parse. I like the aesthetics of double-quotes better too, though that\'s not a compelling reason.
Re:Airbnb JavaScript Style Guide by vog on Friday July 03, 2015 @02:57AM (#9823963)
For such cases I find the Python style most appropriate. It says that you use some consistent default (e.g. always single quote), but for all a strings that require escaping, you should use the delimiter with the least (preferably no) escaping.

Note that this is easier in Python than JavaScript because Python provides more string delimiters:

    'He said hello.'

    'He said "hello".'

    "Don't say hello.'

    '''Don't say "hello".'''

    r'Some regex\sstuff'
Re:Airbnb JavaScript Style Guide by icebraining on Friday July 03, 2015 @06:11AM (#9824601)
The only problem is that sometimes it leads to bugs when people mix different delimiters - like in your third example :)
Re:Airbnb JavaScript Style Guide by jaredmcateer on Friday July 03, 2015 @09:21AM (#9825401)
Note that as of ES6 there is the template string literals using backticks so it looks like JS is at parity with your example.

    'He said hello.'
    'He said "hello".'
    "Don't say hello."
    `Don't say "Hello".`
    /some regex\sstuff/
Mainstream support just isn't there yet.
Re:Airbnb JavaScript Style Guide by elros on Friday July 03, 2015 @02:31AM (#9823877)
Well, one simple typographical way to solve this is not to use a quotation character (') when what is meant is an apostrophe character (’).
Re:Airbnb JavaScript Style Guide by recmo on Friday July 03, 2015 @07:08AM (#9824766)
"Don’t say “Hello”"

Proper typography solves all.

My toy programming language uses “ and ” for string literals. It counts nesting, so you can write “Don’t say “Hello””. There is no escaping. In fact, you can quote any piece of code by simply enclosing it in “ and ”. Code is commented out by turning it into an unused string literal.

Re:Airbnb JavaScript Style Guide by vog on Friday July 03, 2015 @02:51AM (#9823942)
Ouch, I'd be afraid that this may become the source of subtle bugs.
Re:Airbnb JavaScript Style Guide by JimmyM on Friday July 03, 2015 @03:08AM (#9823994)
I thought that (') was the apostrophe character, although it doesn't look like one. (Source: http://www.cl.cam.ac.uk/~mgk25/ucs/apostrophe.html) The same source agrees with you elsewhere though, making my distinction pedantic. (http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html)

I can't personally imagine this solution would be any less confusing, given that the new preferred apostrophe character according to this source is specifically a right single quote character.

Re:Airbnb JavaScript Style Guide by marcoms on Friday July 03, 2015 @06:02AM (#9824582)
You could use ` backticks instead and use both " and ' in strings without worry
Re:Airbnb JavaScript Style Guide by Bahamut on Friday July 03, 2015 @02:19AM (#9823842)
You can use template strings in ES6 and avoid that whole problem.