[haiku-development] Re: Haiku Coding Guidelines Issues

On 9/4/07, Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx> wrote:
> > The * for pointers is always located by the variable or method name,
> > right? There are examples of this, but it isn't spelled out
> > explicitly. For example:
> >
> > class Example {
> >     public:
> >         Example();
> >         ~Example();
> >
> >         const char *Name();
> >
> >     private:
> >         BString *fName;
> > }
>
> Actually as OpenBeOS started that was more or less the convention, but
> since the '*' or '&' belong to the type some people (at least Axel and me)
> consequently sticking it to the type nowadays. According to his sample file
> Michael feels the same, but still has a space between type and '*'.

I'm no Be/Haiku coding standard expert, or even developer, but I still
want to mention the following. There's a reason why it's considered
good practice to write * and & next to the variable rather than the
type. Consider this declaration:

    char* foo, bar;

Intuitively, this should declare two string variables, but the fact is
that this makes foo a string and bar a character. Grouping the * with
the variable name makes it more obvious that it modifies the type of a
single variable only. While this reasoning does not really apply to
method signatures, it's more consistant to use the same convention for
both methods and variables.

Regards,
Truls

Other related posts: