Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
cafecortado7824340dError: too many characters in a character literal 'Hello World'.
I choose the second option then. -
tosensei8318340d@thebiochemic a clear and simple distinction between strings and characters is, indeed, an important feature of a good language.
and a lack thereof is, indeed, a clear sign of a not-so-good language.
unless the language doesn't have a specific type for single characters, in which case the question is moot. -
Voxera11585340dThe only language where both these exist and where there is a valid reason (at least among the ones I have used) is php.
There one it literally string and the other allows for variable interpolation.
Any other language where they fill the same exact role is just sloppy design.
And in those cases I go with either all “ or which whatever the lint rules dictate so it at least is consistent. -
thebiochemic3019340d@tosensei as i said depends on the language. In some it will straight up not work (like in the C Family with literals vs characters), some languages use either one format or the other for strings, and some use one for string literals vs strings with placeholders etc.
But yeah.. i agree, that if a language doesn't atleast distinguish between chars and string literals is rather badly designed. -
KDSBest775340d@Voxera php, javascript, yaml and most json parser accept both '' and "" as string.
Me a C++, C# Developer "" string, '' char -
cuddlyogre1186339dI like how C# forces double quotes for string and single for chars because there's less subjectivity in the code. But it takes slightly more work to type out a string.
In Ruby and Python you get to choose, unless you're doing string interpolation, which is faster in the moment, but makes things subjective and causes an inconsistent code style. It's even more subjective if you're following Python's style guide where strings that are identifiers are supposed to have single quotes and literals have double quotes.
There are also languages where you can also use backticks or brackets or heredocs or any number of other formats. All being used seemingly at random depending on the mood of the dev. -
jiraTicket2296339dIn langs like C# you don’t mess with the standard.
But I really do think singleQuotes are a joy to work with as they have a dedicated key
However practicality rules
In JS I find that the majority of places we can copyPaste from use DoubleQuotes. This includes JSON. So I still lean towards doubleQuotes
With a linter and autofixing it matters less though -
Voxera11585339d@jiraTicket only on the english keyboard, not on the Swedish since we need to fit 3 more letters so single quote is using alt/altgr as a shift key and then double quote is easier.
And it follows on that both basic and turbo pascal uses double quotes, and remember, the creator of C# also created turbo pascal, AND he is danish, which also has extra chars ;)
I agree that on an english keyboard, single quote is slightly easier but I think the extra clarity is well worth it.
Related Rants
print('Hello World')
OR
print("Hello World")
What type are you?
question
dev