Re: [guppi-list] Re: foo const & vs. const foo &



On Mon, Jul 19, 1999 at 11:38:40AM +0200, Asger K. Alstrup Nielsen wrote:
>
> <perfectly logical explaination of reasoning omitted>
> 
> So, when you write "const char *", you have to know that the const
> part binds strongest and that this is a pointer to constant chars.
> In other words, you abandon the rule of reading order, and suddenly
> you have to use precedence rules to understand the type.

I agree with your logic, but I think that we are stuck with an
illogical convention now.  Because even if it isn't clean and logical,
we all *do* know that const binds strongest, so it shouldn't be a
problem.  And while your method might be easier on a beginner/novice
C++ programmer, I would assert that it would actually make their life
more difficult, because they are suddenly being confronted with a type
declaration style that is different that what they've seen in
Stroustrup.

> I know Bjarne Stroustrup writes "const string&", but that's not the
> easiest to read, IMO.  However, if you prefer this form, I can switch
> in order to have consistent sources.

Anyone who looks at my code knows I have my own crazy ideas about
notation, indentation, etc., so I feel strange about enforcing coding
standards.  Still, I think that your const-usage is non-standard
enough to be confusing, and maybe we should all try to stick to the
standard form.

Of course, my biggest quirk is that I like to declare things as
  Foo* x;
rather than as
  Foo *x;
or
  Foo * x;

My logic is that the type is "Foo pointer", and * == "pointer" in a
declaration, so that the * should be made part of the type, not part
of the thing being declared.  This is an old habit I have, and it
probably drives lots of people crazy.  However, I think that any
objections to it would have to be purely aesthetic, since I doubt
anyone would be confused as to whether "Foo* x" and "Foo *x" declared
the same variable...

-JT



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]