As a guy who actually likes C++/STL and sees a lot of value in it, I know already that 99% of this list disagrees with me - AND I've always been a guy who types char* foo without even thinking and prefer it...but...truth be told, I can't with good reason argue against John here and have to agree with him. char *foo is really the "right" way to do it but I suppose it's worth saying/ranting that it's just something you have to live with in C/C++ and arguing/discussing coding styles/standards ultimately becomes a waste of time because in the end you always have to read "the entire statement" and take it in context. When I glance through code and see *foo generally the first thought that goes through my mind is "I'm dereferencing something here" or &foo "I'm taking the address of something here when in reality perhaps I'm just looking at a pointer or reference declaration.
Heck, look at the paragraph I've typed already - a waste of time better spent doing something else? ;) I say, better to spend the time on more important things. But...as a pragmatist as well - I'd say go with the majority simply to save time arguing - and which goes against my preference - and choose char *foo. The same goes for camel case versus underscores in names...would you rather press shift->_ or shift-X (or whatever letter). Takes the same amount of time getting to the shift key, right? I used to be incredibly anal about naming conventions, coding styles, etc, but quickly realized time is wasted on that nonsense and is better used writing meaningful comments (i.e. - documentation)! :) I love reading code that contains a paragraph long comment in which the developer actually tells me what he was thinking at the time, even if I didn't like his coding style. But I digress... And I'm spent... D.J. -----Original Message----- From: John Plevyak [mailto:jplev...@acm.org] Sent: Wednesday, December 09, 2009 9:25 PM To: trafficserver-dev@incubator.apache.org Subject: Re: coding style On 12/9/2009 8:22 PM, Leif Hedstrom wrote: > > I prefer char* too, +1 on that as the standard notation from me, going > forward at least (we can then decide either if we want to "fix" all > existing code, or just fix as we work on it). > > Cheers, > > -- leif Regarding: char *x vs char* x, I am with K&R and GNU in preferring the former for the reason that C types are ... well messy and it is best to remember that :) The problem is that pointers really associate with the thing on the right for the devilish little reason that it makes it possible to differentiate a declaration from a statement and still have the ability to express any type one might want. consider: (int *) x; vs int (*x); then consider the declaration: int (* (* const (c[4]))); vs int **const c[4]; of course we should probably be using typedef, but I am still of the opinion that char* foo deceptively implies that C has a much more sensible type syntax than it does. But then I also think that one should use &anArray[0] when one really means a pointer instead of counting on C's implict array->pointer conversion. In a past life I was a bit of a language lawyer before C++ broke me of that. Now I am just a pragmatist with old habits. john