3
arnavop
347d

print('Hello World')
OR
print("Hello World")

What type are you?

Comments
  • 11
    Error: too many characters in a character literal 'Hello World'.

    I choose the second option then.
  • 1
    “You” is a string
  • 1
    depends on the language
  • 6
    @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.
  • 1
    The 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.
  • 0
    @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.
  • 0
    ``
  • 0
    @Voxera php, javascript, yaml and most json parser accept both '' and "" as string.

    Me a C++, C# Developer "" string, '' char
  • 0
    The type linter/autoformatter for goven language tells me I am.
  • 0
    In Python, f"Hello World" (you never know)
  • 0
    I 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.
  • 0
    In 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
  • 0
    @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.
Add Comment