user1028880
user1028880

Reputation:

Why do the most languages employ double quotes not single for String Literals?

Why do the most languages employ double quotes not single for String Literals?

As far as I know, the only language to employ single quotes is JavaScript where this manner works well.

Any historical reason ?

EDIT: Thank you all for various inputs. This really helps me out.

Upvotes: 5

Views: 381

Answers (3)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221262

Not to be too obvious, but standard English punctuation uses double quotes for quoting and single quotes for interior quotes, so it makes sense that programming languages would default to double quotes.

Upvotes: 1

Chtioui Malek
Chtioui Malek

Reputation: 11515

because usually when you type text strings, you need the single quote more than the double quote like:

  • string s1 = "it's a rainy day.."
  • string s2 = "this file can't be opened.."

this way you have less escaping to do, and it's more readable.

also, i like the way JavaScript does this, it accepts both single and double quotes for strings.

Upvotes: 4

elclanrs
elclanrs

Reputation: 94131

In some languages double quotes represent strings, and single quotes represent characters. In other languages double quotes can interpolate variables while single quotes can't. JavaScript is not the only one that allows single quotes for strings, PHP does, and so does Ruby, and many others, but in JavaScript there's no difference at all of using one or the other.

Upvotes: 4

Related Questions