Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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.
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?
Every good solution is obvious once you've found it.
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.
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...?
Top three reasons why my OS project died:
Too much overtime at work
Got married
My brain got stuck in an infinite loop while trying to design the memory manager
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.