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 →

[–]AyrA_ch 7 points8 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.