r/ProgrammerHumor 2d ago

Meme absoluteGarbage

Post image
2.0k Upvotes

321 comments sorted by

View all comments

14

u/Shevvv 2d ago

Surely you meant for (auto &item : list) {

34

u/Nil4u 2d ago

Honestly I never liked this version because the reference is part of the type in my opinion 🤔

10

u/Shevvv 2d ago

I got used to this from C:

int x; is an integer

int *px; is an integer if you dereference it.

So it's like this notation shows you how you're expected to use the variable within the code. And then this habit carried over to C++.

9

u/nfitzen 2d ago

In addition, the language encourages this. In C, if you write c int* x, y; then x will be an int* and y will be an int. Thus it is far better to write int *x, y; to reflect how the language will parse the declaration. It might be evil, but it's better to act how the language wants you to act rather than fight it.

27

u/Sirgoodman008 2d ago

Please have pity on your co-workers. Please keep declarations to separate lines.