News for hackers. Stuff that matters.
Re:CryEngine out on GitHub by shmerl on Tuesday May 24, 2016 @12:52PM (#11763161)
Yeah, this sort of declaration[1] (inherited from C) is horrendous and prone to nasty errors.

Consder this:

    char* p1, p2;
You could erroneously think that char* is a type, and p1 and p2 are variables of that type. That's not correct however, since p1 is indeed char*, but p2 is char. Such declarations therefore should be strongly avoided for clarity.

[1]: https://github.com/CRYTEK-CRYENGINE/CRYENGINE/blob/release/C...

Re:CryEngine out on GitHub by zanny on Tuesday May 24, 2016 @04:10PM (#11765086)
I always think it is inappropriate to type declare like char* p1 in the first place. Yes, you want to be saying "I'm declaring an 8 bit integer pointer" but since in reality the pointer declaration is bound to the name in C, you should do it everywhere.

So I always do char \p1. Yes, for a non-C programmer its not as intuitive, but C isn't intuitive a lot of the time (cough, char p1[] what?). But you avoid making these mistakes altogether.

Note in function declarations I use char, because you cannot do statement expansion with a comma there, and because in headers the variable name is optional anyway.

Re:CryEngine out on GitHub by shmerl on Tuesday May 24, 2016 @04:16PM (#11765124)
You mean

    char *p;
?

I prefer to use char* p; as well as std::string& s; and etc. rather than attaching the type syntax to the name, since in essence that's part of the type. But yes, it's a mess that this inherited C logic doesn't treat it that way clearly. To avoid such mistakes, it's better not to use comma declarations altogether, you can perfectly avoid them.

It's a good feeling when working with new languages like Rust which avoid such mess.

Re:CryEngine out on GitHub by zanny on Tuesday May 24, 2016 @04:36PM (#11765248)
Yes, the banes of markdown reap their ugly head again.

The point is, though, that while in a developers mental model you attach ref or ptr to the type, the language itself does not, and writing it out like it does can easily drive newer developers who do not understand the nuance to make hard to recognize mistakes as a result of it.