Page 2 of 2

Posted: Thu Jan 11, 2007 12:27 pm
by Candy
Solar wrote:They are "somewhat" OK for structs, but generally typedefs quickly start obfuscating what type a variable really is.

That can be bad enough if you have a type vector<Value>, which is typedef'ed to TableRow or ObjectList or ItemArray in various contexts, so you have to trace back through various headers to find out what members the type actually has.

It gets positively dreadful when people start typedef'ing pointer types, use standard names for non-standard constructs, or name containers after types they are not (maps that are named vector or vice versa, for example).
HWND, LPCHAR, stuff like that? ;)

I would strongly suggest to typedef all uses of uint*_t or int*_t or any form of int as another name that indicates its use and to not typedef any of the others.

Posted: Fri Jan 12, 2007 2:39 am
by Solar
Candy wrote:I would strongly suggest to typedef all uses of uint*_t or int*_t or any form of int as another name that indicates its use...
Erm... isn't the "indicating its use" the job of the variable name? I mean, I don't typedef size_t to "loopcounter_t" before using it in a for-loop, either?

Posted: Fri Jan 12, 2007 4:38 am
by m
You may want to refer to Code Complete (2) for issues about variable names...It fills up a chapter around it. :wink:

Posted: Fri Jan 12, 2007 5:36 am
by Solar
A book on coding style, on the subject of variable naming, from the company that raped hungarian notation and left it for dead?

I don't think so...

Posted: Fri Jan 12, 2007 10:19 am
by Candy
Solar wrote:
Candy wrote:I would strongly suggest to typedef all uses of uint*_t or int*_t or any form of int as another name that indicates its use...
Erm... isn't the "indicating its use" the job of the variable name? I mean, I don't typedef size_t to "loopcounter_t" before using it in a for-loop, either?
I wasn't exactly hinting at loopcounter_t, but it would prevent you from abusing your loop counter as a pointer type or something similar. I was indicating more something like virt_addr_t and phys_addr_t, which are equal in size but very different in use. The use of such types enforces you to use casts to cast between them which makes bad code look uglier (and therefore less likely for you to type it since it becomes longer and less clear than hacking would've been before). Also, you catch accidental swaps in map() if/when you misorder the arguments.

Posted: Fri Jan 12, 2007 1:14 pm
by Colonel Kernel
Solar wrote:A book on coding style, on the subject of variable naming, from the company that raped hungarian notation and left it for dead?

I don't think so...
No, no, no... Do not confuse Microsoft Press with the rest of Microsoft (or MS Research with the rest of Microsoft for that matter). Steve McConnell, to the best of my knowledge, has never worked for Microsoft and probably never will. He lives in the Seattle area and MS Press was probably the friendliest publisher he could deal with.

Code Complete is an awesome book. It is full of very practical and useful guidelines on how to make code readable and maintainable. I'm not exaggerating when I say it has had a positive influence on my entire career (along with one of McConnell's other books, Rapid Development).

Don't be so quick to jump to conclusions! Didn't you just say in another thread that just because software is commercial doesn't mean it's crap? How is this any different...?

Posted: Fri Jan 12, 2007 2:03 pm
by Candy
Colonel Kernel wrote:Don't be so quick to jump to conclusions! Didn't you just say in another thread that just because software is commercial doesn't mean it's crap? How is this any different...?
I can motivate why software is crap because it's commercial - commerciality promotes mediocrity - if you're good enough you get a higher margin, so you win. It needn't be crap but it has to be good enough for most. Also, stuff that's crap but that looks a lot like the older one is bought automatically. People won't buy Windows Vista since it's better than Linux but since it's the next Windows, so you can run your old windows stuff on it. You still reinstall everything and probably switch all your applications for a new or different version which is pretty different but anyway, it's still windows.

Posted: Fri Jan 12, 2007 2:27 pm
by Colonel Kernel
Candy wrote:I can motivate why software is crap because it's commercial
My intention wasn't to drift off-topic, it was merely to point out Solar's inconsistency. :)

Posted: Sat Jan 13, 2007 5:28 pm
by Seven11
Any reasoning behind it? Just curious.
I think it makes the codes way eaiser to read, and the code looks better.