Skip to content

Conversation

@LB--
Copy link
Member

@LB-- LB-- commented Apr 21, 2013

Make sure to view it on GitHub and not via the diff viewer to get the formatting:
https://github.com/LB--/ChessPlusPlus/tree/adjust-styleguide/src#readme

A lot more needs to be added, but I can't think of it all. Can everyone think of more ambiguous cases that need to be clarified?

@Thumperrr
Copy link
Member

I dislike where the const keyword is put, but other than that I agree with the styleguide.

const char *something;

makes more intuitive sense to me. But I can get around that if everyone else agrees to have it like

char const*something;

@LB--
Copy link
Member Author

LB-- commented Apr 22, 2013

I will definitely go both ways on that - the reason I originally put it after is because of the actual definition of 'const' and how it is used in other cases.

const type * * const * * identifier;

Which * is const? It might appear that the third * is const due to how const is first used, but it's actually the second *.

If everyone prefers putting const before the type, then of course I will accept that instead.

@Thumperrr
Copy link
Member

I'll have to read up on the definition of const then, because that made absolutely no sense to me, lol.

@LB--
Copy link
Member Author

LB-- commented Apr 22, 2013

http://stackoverflow.com/questions/5503352/const-before-or-const-after
http://stackoverflow.com/questions/5248571/is-there-const-in-c
It just seems inconsistent to place it before in some cases and after in others. The order doesn't actually matter until you involve *, at which point things would get confusing.

const int *const p; //inconsistent: sometimes left, sometimes right
int const *const p; //consistent: always left

I would also say that perhaps it shouldn't snuggle to the right to make it more clear what it is affecting. EDIT: And, of course, I somehow manage to misspell change.

@Thumperrr
Copy link
Member

Oh I see.

int const*obj; //pointer to const obj
const int *obj; //const pointer to non-const obj
---
const int obj;
int const obj; //both same thing

So then wouldn't it depend on what you're trying to do with the bit of code where you placed const?

EDIT: but in the case of non-pointer objects, I have nothing against having const to the right of the type.
EDIT2: Just read your recent change to the style-guide. I can agree to it now after reading more about const. I also like the const not snuggling next to the identifier.

@LB--
Copy link
Member Author

LB-- commented Apr 22, 2013

int const*obj; //pointer to const obj
const int *obj; //const pointer to non-const obj

Both are a non-const pointer to a const integer.

const T *       //non-const pointer to const T
      T *const  //const pointer to non-const T
      T const * //non-const pointer to const T

As you can see it is inconsistent which side of the token const appears on with the first two examples, whereas with the second and third is is clear that const affects what is on its left.

I also like the const not snuggling next to the identifier.

I assume you mean * and &, const can't snuggle next to an identifier because then it would be part of the identifier ;)

@LB--
Copy link
Member Author

LB-- commented Apr 22, 2013

Quite a lot of post editing going on, let's both take a moment to reread the whole discussion >_<

@Thumperrr
Copy link
Member

You're right. That makes sense to me.

And yeah that's what I meant, lol. So we're good here, now.

Thumperrr pushed a commit that referenced this pull request Apr 22, 2013
Add specifics to styleguide
@Thumperrr Thumperrr merged commit 8179ca2 into cpluspluscom:master Apr 22, 2013
@LB-- LB-- deleted the adjust-styleguide branch April 22, 2013 22:59
@ghost ghost assigned Thumperrr May 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants