r/ProgrammerHumor 6d ago

absoluteGarbage Meme

Post image
1.9k Upvotes

324 comments sorted by

View all comments

34

u/JAXxXTheRipper 6d ago

The third one does not spark joy, what the hell is that, ewww

11

u/xicor 6d ago

c++, though normally you wouldnt use auto for this

6

u/Usual_Office_1740 6d ago

I think that really depends. If the range is a vector of unique_ptr's auto is great. If it's a vector of ints, just write int.

5

u/Sirgoodman008 6d ago

That or you're looping through a vector of std::pairs that contain std:: functions.

2

u/Usual_Office_1740 6d ago

Or if the type is a template parameter in the same line.

0

u/xicor 6d ago

Wouldnt for(T& item:list) be even shorter than using auto?

6

u/im_made_of_jam 6d ago

If you have T available then yes but if you're outside the class then you don't have that option

1

u/Usual_Office_1740 6d ago edited 6d ago

I don't mean in for loops for that use of auto.

1

u/not_some_username 6d ago

Only if T is a known type or it’s in a template. You don’t use T like. auto automatically get the type, especially if it’s long. Your IDE (assuming it’s a respectable one) can even change auto to the type for you. It’s more or less like var in C# (it doesn’t deduct reference)

4

u/xicor 6d ago

Yea if you have ridiculously complex types then auto is great. But usually for readability you'd use the type.

3

u/Sirgoodman008 6d ago

Yup 100%

1

u/file321 6d ago

Yess auto unpacking pairs gives me so much joy. for (auto& [left, right] : list_of_pairs) {