C linked list

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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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?
Every good solution is obvious once you've found it.
m
Member
Member
Posts: 67
Joined: Sat Nov 25, 2006 6:33 am
Location: PRC

Post by m »

You may want to refer to Code Complete (2) for issues about variable names...It fills up a chapter around it. :wink:
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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...
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post 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...?
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post 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. :)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
Seven11
Member
Member
Posts: 25
Joined: Mon Oct 30, 2006 12:48 pm

Post by Seven11 »

Any reasoning behind it? Just curious.
I think it makes the codes way eaiser to read, and the code looks better.
Post Reply