[openbeos] Re: Pointer or reference?

  • From: Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sun, 28 Mar 2004 19:55:33 +0200

On 2004-03-28 at 18:38:01 [+0200], Axel Dörfler wrote:
> Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx> wrote:
> > In the BeOS API references are used rather sparingly in wide parts
> > (basically only for copy constructors and comparison/assignment
> > operators).
> > Exceptions are the media kit and the net kit, both feeling a bit un-
> > Be-ish
> > anyway, IMHO.
> > 
> > So, I would say, for public APIs (or those that may become public in
> > the
> > future), references should be avoided.
> 
> Well, is there any reason that we copy that? When the media and network
> kit already use them, maybe we should propagate its use for the future
> a bit more?

Personally, I like references and use them in my code. But that code is not 
a public API and changing a reference to a pointer, when I see the need, 
doesn't hurt me.

In the older kits Be used pointers consistently. One might wonder, for 
instance, why a BNode is constructed using a const BEntry*, especially 
because one mostly constructs the entry on the stack. While that might be a 
bit annoying sometimes, it is, well, consistent. There is not a single 
BEntry in the Be API that is passed per reference (let alone copy 
constructor and operators). Since for functions where the parameter is 
optional, a pointer has to be used anyway, you'll end up with a mixture, 
even if you try to consequently use references. So, you'll need to convert 
between references and pointers and probably blur the checking policy for 
NULL pointers.

To cut it short, I'm sceptical.

CU, Ingo

Other related posts: