resource / Front-End-Standards

Front-end development standards for Resource.
MIT License
23 stars 1 forks source link

Single quote vs. double quote #26

Closed JBRector closed 10 years ago

JBRector commented 11 years ago

I think single quotes make more sense for strings. There will be occasions where you will need to use a double quote in the string itself.

html = '<h1 class="heading">This is a "heading"</h1>'

I know you can escape them, but that would add superfluous code IMO. This way seems more simple.

nicetransition commented 11 years ago

I escaping makes sense, complex dom structures should be a template not a variable string. A complex structure is the only time it makes sense.

nicetransition commented 11 years ago

Your example also makes me think that we don't outline special characters in strings. @LukeAskew, your thoughts? This comes a lot stuff like trademarks, quotes, ampersand, etc

LukeAskew commented 11 years ago

I initially had single quotes, but we chose double quotes because it is more consistent with other languages.

@JBRector your example shows double quotes when defining an html element attribute. Are there any other cases for double quotes in a string?

I ask because, typically, we are trying to move away from mixing html and js (or at least html inside .js files).

nicetransition commented 11 years ago
"we are trying to move away from mixing html and js (or at least html inside .js files)."

completely agree!

If dom structures are needed, you can easily write them in JS which makes it easy to read too

JBRector commented 11 years ago

OK, fair enough. I don't really think there is another reason I can offer other than it's my personal preference.

LukeAskew commented 10 years ago

I'd like to revisit this issue.

I'm finding that single quotes is becoming more standard in JavaScript. I'm finding myself switching to single quotes often if I want to contribute to projects, specifically node.js projects as single quotes is the recommended standard.

Looking back, our initial reasoning that "double quotes is more standard" may be a little thin.

Many popular JS app frameworks also mix html strings in JS code, so single quotes are preferred for consistency sake.

Here are some interesting discussions about single vs. double:

mrbinky3000 commented 10 years ago

Just keep in mind that JSON requires double quotes. That being said, I typically only use single quotes myself. Faster to type :-)

On Thu, Mar 27, 2014 at 9:14 AM, Matthew Toledo matthew.toledo@gmail.comwrote:

Just keep in mind that JSON requires double quotes. That being said, I only use double quotes when I'm putting HTML in a string, or when I need to output a control character.

Single quotes for HTML because valid HTML requires attributes be encased in double quotes and I don't want to clutter stuff with escape slashes.

On Wed, Mar 26, 2014 at 10:29 AM, Luke Askew notifications@github.comwrote:

I'd like to revisit this issue.

I'm finding that single quotes is becoming more standard in JavaScript. I'm finding myself switching to single quotes often if I want to contribute to projects, specifically node.js projects as single quotes is the recommended standard http://nodeguide.com/style.html#quotes.

Looking back, our initial reasoning that "double quotes is more standard" may be a little thin.

Many popular JS app frameworks also mix html strings in JS code, so single quotes are preferred for consistency sake.

Here are some interesting discussions about single vs. double:

Reply to this email directly or view it on GitHubhttps://github.com/resource/Front-End-Standards/issues/26#issuecomment-38689766 .

tobius commented 10 years ago

I have always supported single quotes and will continue to do so (note: you can type it faster).

On Mar 27, 2014, at 9:35 AM, Matthew Toledo notifications@github.com wrote:

Ooops. Type-o in last email. Ignore it all... Take 2:

Just keep in mind that JSON requires double quotes. That being said, I typically only use single quotes myself. Faster to type :-)

On Thu, Mar 27, 2014 at 9:14 AM, Matthew Toledo matthew.toledo@gmail.comwrote:

Just keep in mind that JSON requires double quotes. That being said, I only use double quotes when I'm putting HTML in a string, or when I need to output a control character.

Single quotes for HTML because valid HTML requires attributes be encased in double quotes and I don't want to clutter stuff with escape slashes.

On Wed, Mar 26, 2014 at 10:29 AM, Luke Askew notifications@github.comwrote:

I'd like to revisit this issue.

I'm finding that single quotes is becoming more standard in JavaScript. I'm finding myself switching to single quotes often if I want to contribute to projects, specifically node.js projects as single quotes is the recommended standard http://nodeguide.com/style.html#quotes.

Looking back, our initial reasoning that "double quotes is more standard" may be a little thin.

Many popular JS app frameworks also mix html strings in JS code, so single quotes are preferred for consistency sake.

Here are some interesting discussions about single vs. double:

- airbnb/javascript#110https://github.com/airbnb/javascript/issues/110

http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=Strings#Strings

Reply to this email directly or view it on GitHubhttps://github.com/resource/Front-End-Standards/issues/26#issuecomment-38689766 .

— Reply to this email directly or view it on GitHub.