[Kde-pim] KCalCore Ptr typedefs and constness

Bertjan Broeksema broeksema at kde.org
Sat Aug 21 21:06:03 BST 2010


Hi David, pimsters,

David Jarvie wrote:
 
> I think that many of the method signatures in kcalcore are misleading
> because they use for example 'const Event::Ptr&' which gives the initial
> impression of being equivalent to 'const Event*', but is actually
> equivalent to 'Event* const', i.e. only the pointer is constant, not the
> object pointed to. I think it would be a bit clearer to pass 'const
> Event::ConstPtr&' which *would* be equivalent to 'const Event*'.
 
equivalent to 'const Event * const' even.

David, although I fully aggree with the arguments you bring up, I'm not sure 
that bringing in ConstPtr is the right solution. To make the *full* api 
const correct, you'd end up with numberous of overloads which imo results in 
an api that is hard to read and hairy to use/maintain.

I already said in an internal discussion at KDAB on this topic that we now 
somewhat ended up with an java style API. That is, change something here and 
it will be magically changed at the other side of the universe as well.

I see two possible ways to approach this problem:

1) Pass the *::Ptr objects by value:

e.g. setPerson( Person::Ptr person )

This would give slightly more overhead but probably negligble and makes 
indeed clearer that we're working with pointers here and not with ConstPtr 
or const objects. This would still leave the need of prominent and clear 
documentation about memory management/ownership of the objects passed 
around. But that was not very different in the old situation.

2) Make the API value based.

e.g. setPerson( const Person &person )

This is of course even more clearer than the Ptr/ConstPtr approach. *But* 
this would I think require a considerable amount of work. I.e. changing the 
API and port kdepim (again).

Well, my 2cents.

Cheers,

Bertjan

_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list