r/ProgrammerHumor • • Aug 11 '19

Meme Lamo

Post image
78.0k Upvotes

799 comments sorted by

View all comments

Show parent comments

263

u/ColombianoD Aug 11 '19

“How to convert string to int”

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

→ More replies (1)
→ More replies (1)
→ More replies (4)
→ More replies (8)

33

u/[deleted] Aug 11 '19

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

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.

→ More replies (3)

21

u/konstantinua00 Aug 11 '19

int stoi(string);

12

u/livershi Aug 11 '19

ew who uses std namespace

12

u/logan_houston Aug 11 '19

I used to use it, I only stopped because everyone bullied me about it. It was actually kinda helpful

15

u/konstantinua00 Aug 11 '19

all those standart-less bullies think that their lack of easy words must be put onto everyone

Everything has its place. Namespaces has their place too.
If you only work on small projects without libs with their own namespaces, you're free to use using to make your life easy

3

u/livershi Aug 11 '19

Oh yeah I was trying to meme haha it's nice in smaller programs especially since you don't run into conflicts and the overhead is really unimportant

14

u/[deleted] Aug 11 '19

static_cast<int> /s

19

u/Mustrum_R Aug 11 '19

Compiler: "Seems fine to me."

Runtime: "Tis gonna be gud."

9

u/[deleted] Aug 11 '19

Big brain time:

Static_cast<auto>

6

u/MEME-LLC Aug 11 '19

Actually i search this a lot since i cant remember the right name when i have to use like 5 languages

5

u/thiago2213 Aug 11 '19

Honestly, I have 9 years of experience and I still Google stuff like that

→ More replies (1)

3

u/Smayteeh Aug 11 '19

Int int = Int.parse(String);

→ More replies (3)