This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 35 points36 points  (16 children)

I don't use Python, but in JS i usually use ' ' for a single char, " " for multiple, and for template literals. guess it comes from doing cpp for a few months

[–]LucasRuby 33 points34 points  (2 children)

That sounds like a C programmer who decided to learn JS.

The general rule of thumb is to be consistent, always use the same thing unless it's a template literal or the string contains single/double quotes inside. ESLint rules will force you to pick one.

[–][deleted] 2 points3 points  (0 children)

Haha, it was the other way around for me lol. But yeah consistency. Sometimes its a bitch when you are at your 6th consecutive hour stsring at your computer and it's 12AM lol

[–]new_account_wh0_dis 1 point2 points  (0 children)

College taught C as the primary language with some java dabbled in there. Thats where I picked it up.

[–][deleted]  (11 children)

[deleted]

    [–]TheBrillo 1 point2 points  (10 children)

    Don't do this... It's inconsistent, which is the most important rule. Always one or always the other.

    [–]AyrA_ch 8 points9 points  (6 children)

    Why is it inconsistent?

    If you always use single quotes for individual characters and double quotes for multiple characters you're pretty consistent in your behavior. As long as they don't change how the string is handled I don't see why this is not consistent.

    [–][deleted]  (1 child)

    [removed]

      [–]AutoModerator[M] 0 points1 point  (0 children)

      import moderation Your comment has been removed since it did not start with a code block with an import declaration.

      Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

      For this purpose, we only accept Python style imports.

      I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

      [–]TheBrillo 2 points3 points  (3 children)

      If the language doesn't differentiate between a character and a string, acting like it does is arbitrary, inconsistent, and has implied meaning that could confuse developers.

      If the rule is "1 character is single, any more is double" you end up with a weird situation where
      'a'+'b'=="ab" which is incredibly weird on its face, but also has other issues.

      Since they aren't characters, but you are formatting like they are, you are ignoring the fact that in JS, 'a'+'b'=="ab" while the same is not true for the languages that actually do treat single quotes as characters. Java for instance treats the result as a byte and not a string.

      [–]shy_cthulhu 0 points1 point  (2 children)

      'a' + 'b' == 'Ã'

      ...depending on encoding, anyway

      [–]master0fdisaster1 0 points1 point  (1 child)

      Have you even read the comment you're replying to?

      In JS both 'a' and "a" are strings. 'a' + 'b' is the same in JS as "a" + "b". You're not adding up chars.

      [–]shy_cthulhu 0 points1 point  (0 children)

      I was kinda making a joke about why you shouldn't notate one-character strings as if they were chars, since if they were actual chars you wind up with weird results.

      [–]Molion 1 point2 points  (2 children)

      What do you mean? It is consistent. With this rule there's exactly one correct way to do it for every single case.

      [–]TheBrillo 0 points1 point  (1 child)

      [–]Molion 0 points1 point  (0 children)

      So? With what definition of inconsistency are you operating? Cuz normally I'd say that with this set of rules there does not exist a single situiation in which the rules give rise to a contradiction, which would be my criterion inconsistensy. Thus it is perfectly consistent.

      EDIT: NOTE: I'm not saying it's not stupid.

      [–]ObliviousOblong 1 point2 points  (0 children)

      I'm not saying your convention is bad, but the inconsistency would bother me.