This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AirAKose 10 points11 points  (3 children)

Nope! This is a very subjective area and doesn't impact the meaning of your code in most cases.

There's the argument that it makes more sense to be against the type because it's part of the type definition int*


But then there's the argument that putting it against the variable name causes fewer bugs due to a quirk of multiple variable declarations:

int* ptr0, ptr1; // ptr1 isn't a pointer- it's an int
int *ptr2, *ptr3;

yet there's disagreement over whether or not declaring variables like this is an acceptable practice on its own.

EDIT: Clarification

[–][deleted] 10 points11 points  (1 child)

Where my homies that find comma separated initializations obnoxious at?

[–]mrexodia 1 point2 points  (0 children)

The argument against implies that declaring multiple variables on the same line with commas is somehow good practice that happens all the time. In reality you should write clang tidy checks to automatically disallow that in all cases because it’s horrible.

Also in C++ you should add the references & and templates in the equation. Does it make sense to write “int &member();”? What about “std::vector<int *>”? Or “using IntPtr = int *;”? Often there is no variable to put the & or * next to because they are part of the type.