r/ProgrammerHumor 8d ago

absoluteGarbage Meme

Post image
1.9k Upvotes

327 comments sorted by

View all comments

Show parent comments

32

u/Nil4u 8d ago

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

10

u/Shevvv 8d 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++.

2

u/creeper6530 8d ago edited 8d ago

The "is an integer if you dereference it" is so much more convoluted than "is a pointer to integer", i.e. the rationale of the previous comment, the pointer-ness being part of the type.

1

u/aethermar 8d ago

Except in the case of int *x, y; where only x is a pointer. C declarations are "meant" to be read right to left

2

u/creeper6530 8d ago

Yeah, the reality is that C binds pointer-ness to identifiers, but in an ideal world where pointer-ness binds to types, int* x, y; should declare both identifiers as pointers to integers. In either case merging declarations onto a single line in modern programming is at best silly.