r/ProgrammerHumor • • Aug 11 '19

Meme Lamo

Post image
78.0k Upvotes

799 comments sorted by

View all comments

Show parent comments

98

u/[deleted] Aug 11 '19

Alternatively, int to String. The best way to do this is n+"", amirite?

161

u/ThomasTheHighEngine Aug 11 '19

Just use str().

Python gang rise up

141

u/Sckaledoom Aug 11 '19

Just don’t even have strings natively

C/C++ gang rise up

62

u/ConfuzedAndDazed Aug 11 '19

Just don’t use types

JavaScript gang for the win

90

u/DarkwingDuckHunt Aug 11 '19

What's in the box?

Javascript: fuuuuuuuuuuuuuuuuuuuuck i dunno, you wanna guess?

C/C++: It's an address to a house somewhere in Morgansville, give me a few milliseconds to go there

Java/C#: It's a head

SQL: It's your wife's head, and she's pregnant with 1 child.

57

u/logan_houston Aug 11 '19

Python: Idk but I can shake it around and try to figure out

10

u/WITHYOURASSHOLE Aug 11 '19

Shake first, ask forgiveness for breaking it later

2

u/nomnomnom92 Aug 12 '19

Python: i don't care, let's do some shit.

2

u/BrightCash Aug 11 '19

What do you mean, types? There's only one type of list.

→ More replies (4)

1

u/jack-of-the-woods Aug 11 '19

Used this literally 10 minutes ago before getting tired of this library so now I’m on reddit

1

u/Dysp-_- Aug 11 '19

Ruby: 5.to_s

No parenthesis hell

1

u/[deleted] Aug 11 '19

str() and int() have saved my ass so many times

1

u/Xaayer Aug 12 '19

Laughs in Perl

33

u/[deleted] Aug 11 '19

double binary not(~) in js will convert any type to int in js. eg ~~'5.4' becomes 5

40

u/ninj1nx Aug 11 '19

Wat

2

u/_Lady_Deadpool_ Aug 11 '19

I mean you can just use ''+myInt or myInt.toString()

Or in ts `$(myInt)`

→ More replies (1)

6

u/LetterBoxSnatch Aug 11 '19

For those wondering why: the general convention in js is that it will do its best to convert the type to make an operation legal, rather than fail. In order to perform the bitwise operation, js tried toInt32(String), and then performs the operation on the result. The same operation is then applied again to reverse the first.

This is a similar situation to doing: 5 + '' to convert a number to a string, or '5' - 0 to convert a string to a number. “plus string” can only mean string concatenation, so the first value is made into a string of possible. “minus 0” can only be a number operation, so the first value is converted to a number if possible

→ More replies (6)

7

u/ColombianoD Aug 11 '19

fun fact: at least in Java using the shorthand string notation is objectively better than the long hand notation.

String x = "Hello, World!";
vs.
String x = new String("Hello, World!");

in the former case the JVM checks the heap to see if the same string was already created, and if so, points to that object (because Strings are immutable). In the latter case it always creates a new String object.

1

u/MEME-LLC Aug 11 '19

I prefer ""+n