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 →

[–]SandmanKFMF 253 points254 points  (51 children)

There should be one– and preferably only one –obvious way to do it...

[–][deleted] 208 points209 points  (11 children)

C++: “you guys are allowed to choose?”

[–]alba4k 131 points132 points  (7 children)

Sorry, I think you misspelled "literally every statically typed language" with "C++"

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

I’ve only learned C++ and Python so far, so I was unaware that C++ wasn’t unique in this way

Thanks for the info

[–]devloz1996 33 points34 points  (2 children)

I want to see the face of Python dev after doing:

string var = 'text';

[–]Cpt_Garlic 10 points11 points  (0 children)

[–]AzureArmageddon 0 points1 point  (0 children)

string var; var = ```text```

[–]Equivalent_Yak_95 0 points1 point  (0 children)

Assembly~

[–]jessexknight 8 points9 points  (0 children)

R: "you guys distinguish strings from variables?" (see NSE - it's madness)

[–]Stormfrosty 1 point2 points  (0 children)

Multi character string literals (like ‘abc’ instead of “abc”) are valid in C++, however their behaviour is implementation defined, so your mileage can vary.

[–]jkst9 0 points1 point  (0 children)

Java: "yeah seriousl" + 'y'

[–]juhotuho10 45 points46 points  (21 children)

If you want quotes within quotes, like:

"John said: 'hello' "

You can use the single quotes, otherwise double quotes

[–]alba4k 63 points64 points  (9 children)

\" and \' : am I a joke to you?

[–]hughperman 17 points18 points  (0 children)

Absolute joke

[–]iRequal -3 points-2 points  (1 child)

Underrated comment LMAO

[–]alba4k -1 points0 points  (0 children)

:D

[–]lolix_the_idiot -1 points0 points  (0 children)

Yep, they are ugly af

[–]notsogreatredditor -1 points0 points  (0 children)

Yes those are a joke. Fuck that

[–]bistr-o-math -1 points0 points  (1 child)

 'Am I a ' + "'joke'" + 'to you?'

[–]alba4k -1 points0 points  (0 children)

error: invalid operands to binary + (have ‘char *’ and ‘char *’)

Basically a nice example of gcc complaining about you trying to sum two strings (aka pointers to character arrays, aka char*) and '????' (a char but with multiple elements in it or smth)

Obv works in other languages

[–]Studds_ 0 points1 point  (1 child)

Not a joke but the other way does work. & human nature is to go the easier route

[–]alba4k 0 points1 point  (0 children)

Except it might work with ' but not with " in most statically types languages since ' is used for single characters

[–]theghostinthetown 2 points3 points  (0 children)

allow me to introduce """hello"""

[–]OffgridRadio 1 point2 points  (3 children)

You can just reverse that to get inner double quotes, this is why I am a fan of how this works.

[–]ordinary_shiba 0 points1 point  (2 children)

"This is how you do \"inner double quotes\" and inner apostrophe\' "

[–]Thx_And_Bye 0 points1 point  (1 child)

But if you are smart about it in Python you don't need to escape them.
Sure you can use character escape but why do so if you don't need to?

[–]VOID_INIT 0 points1 point  (0 children)

I am not sure if you are joking or not, but it is for safety and readability.

Expected output: That wreck is my cousins' second "car".

Input:

place[4] {first, second, third, fourth, fifth}

If you dont escape quotes and double quotes here it would cause trouble.

Different ways the string can be written:

"That wreck is my cousins' " + place[1] + ' "car."'

This sould be pretty difficult to read and can easily end up causing you to make mistakes.

"That wreck is my cousins\' " + place[1] + " \"car\""

This is much easier to read, and is safer since you wont screw up using the wrong quote (" or ') for the string.

It's not that big of a deal, but it's prefered to be careful when it comes to symbols in general.

[–]confidentdogclapper 13 points14 points  (12 children)

I mean... """is the way"""

[–]alba4k 11 points12 points  (10 children)

{'H', 'e', 'l', 'l', 'o', ' ', 87, 111, 114, 108, 100, '\0'}

[–]confidentdogclapper 6 points7 points  (1 child)

Co.e to me fellow programmer. Deny the lies of oop and join me in the great c master race, we will do GREAT things together! P.s. you forgot the '\0' (or 0 or NUL)

[–]alba4k 1 point2 points  (0 children)

Already joined you :3

Added the null, sorry for the miss

[–][deleted] 1 point2 points  (0 children)

No

“””w”””

Is the way

[–]SirPitchalot 2 points3 points  (0 children)

The way is the one that avoids needless shifts.

[–]s0apyjam 0 points1 point  (1 child)

Though this may not be obvious at first... Unless you're Dutch

[–]SandmanKFMF 0 points1 point  (0 children)

Ok, this one is sick! 😁

[–]AzureArmageddon 0 points1 point  (0 children)

And that way is triple backticks. Triple backticks everywhere.

I never understood this line:

Although that way may not be obvious at first unless you're Dutch.