Smart Pointers

A place to discuss everything about the Orxonox framework.

Moderator: PPS-Leaders

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Smart Pointers

Post by 1337 » Mon Jul 13, 2009 2:44 pm

Yes, the mysterious topic finally made it to the forum! So many rumors...

I mainly want to open this discussion here to decide about the naming conventions. The rest is so "on-the-fly" that the one implementing it has to find the right ways.

Now, what do you suggest? I haven't exactly worked with smart pointers a lot and therefore I'm not familiar with any naming conventions. A smart pointed object type could be called for instance SOrxonoxClass. But that doesn't fit very well for classes beginning with an S ^^
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: Smart Pointers

Post by x3n » Mon Jul 13, 2009 4:14 pm

Hm, good question. Another idea would be to use the prefix "c" for all classes (cSpaceShip) and then use the original name for the smart pointer. But I think we have to implement it first and then see where and how the smart pointers are used. Only then we'll see what naming convention is the least confusing I think.
Fabian 'x3n' Landau, Orxonox developer

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Re: Smart Pointers

Post by beni » Mon Jul 13, 2009 5:35 pm

Do we really need another class for each existing class? should work with templates, right?
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: Smart Pointers

Post by x3n » Tue Jul 14, 2009 12:13 am

Yeah, but there's often a short and simple typedef to the (long) template name
Fabian 'x3n' Landau, Orxonox developer

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: Smart Pointers

Post by 1337 » Tue Jul 14, 2009 6:54 am

The complete expression would be boost::shared_ptr<Scene>, which adds quite a lot of code. So by typedefing every class in the Prereqs file we can achieve code that is much better readable.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Re: Smart Pointers

Post by beni » Tue Jul 14, 2009 12:41 pm

of course that makes sense. I don't know that much about various approaches to solve that problem, so I didn't know that this'll be clear and we're really only talk about names here. Great I figured that out now :).

Why use c? Don't see the point in that...

I checked out the Internet and found following examples:
  • OrxonoxClassType
  • ptrOrxonoxClass
  • spOrxonoxClass
  • OrxonoxClassPtr
  • OrxonoxClass_p
I like the three in the middle.
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: Smart Pointers

Post by 1337 » Tue Jul 14, 2009 1:13 pm

I think it would be wise to let the reader know that it is a pointer. I suppose we'll be using shared_ptr and weak_ptr from boost (as suggested in this ticket).
And I agreed that we don't yet really know how often the weak_ptr has be used, so no name for that yet. But shared_ptr sure will be. And my favourite is OrxnoxClassPtr.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
greenman
Baron Vladimir Harkonnen
Posts: 360
Joined: Wed Oct 03, 2007 2:53 pm
Contact:

Re: Smart Pointers

Post by greenman » Wed Jul 15, 2009 8:08 am

i too like OrxonoxClassPtr.
but if we also have to use weak ptrs then maybe ptrOrxonoxClass (shared) and wptrOrxonoxClass (weak) would be a better choice ?
There are only 10 types of people in the world: Those who understand binary, and those who don't.

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Re: Smart Pointers

Post by beni » Wed Jul 15, 2009 4:47 pm

and what about OrxonoxClassWPtr? or is this not as readable? hmm, maybe not :(. Or maybe OrxonoxClassPtrW or something similar...

It's all a matter of what you prefer and what is easier to read. In the end we use the smart pointers to lessen the errors we could make (among other reasons of course). That's why we should increase the error probability to use unreadable or easy to misread-able names.
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: Smart Pointers

Post by 1337 » Wed Jul 15, 2009 4:52 pm

I suppose the weak pointer will have little, but very important, use.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Re: Smart Pointers

Post by beni » Wed Jul 15, 2009 5:04 pm

So we shouldn't change out preferred OrxonoxClassPtr just because of that.

I suggest OrxonoxClassPtrW for clear and consistent naming.
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: Smart Pointers

Post by 1337 » Wed Jul 15, 2009 5:08 pm

If you want consistency:
OrxonoxClassSPtr (shared_ptr)
OrxonoxClassWPtr (weak_ptr)

but I think omitting the 'S' is perfectly ok.

So, enough of this discussion, we can wrap it up later one when the naming comes up. But I'm always happy to let people discuss naming matters.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: Smart Pointers

Post by x3n » Wed Jul 15, 2009 7:25 pm

Personally I wouldn't mind if we just use a template name, but with a typedef for the smart pointer classes (no boost:: and maybe shorter). Because it's somehow a mistery if you have to append "Ptr" to get the right type.

And whatever option we chose, I really insist to make the difference between shared and weak pointers obvious (and yes, this means more than just an additional "W").

Don't understand this as a proposal, just to show in which direction this post aims:
Ptr<OrxonoxClass>
WeakPtr<OrxonoxClass>
Fabian 'x3n' Landau, Orxonox developer

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: Smart Pointers

Post by 1337 » Wed Jul 15, 2009 7:35 pm

I actually quite agree. Frankly I thought you'd be the one to make it less obvious :P, herefore please apologise my prejudice.
Now, the long versions really are too much to write, but a Ptr<> is just 5 letters more and I'm perfectly happy with it because (as you've pointed out) people will notice that's a template and might even ask why (and maybe figure out what a smart pointer really is;)).
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Re: Smart Pointers

Post by beni » Wed Jul 15, 2009 8:36 pm

You guys are right. Naming it with just an additional "Ptr" increases confusion as it looks exactly like a class name. Writing those <> is a pain in the ass, but at the end of the day it is maybe the clearest proposal.
"I'm Commander Shepard and this is my favorite forum on the internet."

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests