[Development] Setters: Clarifying the ownership

Thiago Macieira thiago.macieira at intel.com
Fri Jan 19 19:32:49 CET 2018


On Friday, 19 January 2018 09:26:10 PST Edward Welbourne wrote:
> Jaroslaw Kobus (19 January 2018 17:09)
> 
> > "give" may be confused with "get", which is usually an accessor. I may
> > also think "Am I giving (to QCoreApplication)" or "The
> > QCoreApplication is giving (me)". Maybe it is just a matter of the
> > other verb? Absorb, hand over, hand on, suck in, swallow...
> 
> However, we have plenty of take functions, where the caller takes
> ownership from the object on which the method is called; so it makes
> sense that a give function would be the caller giving ownership to the
> object on wich the method is called.
> 
> Thus we'd keep child.setParent(newParent), since the child doesn't take
> ownership of the parent; but QMainWindow's setCentralWidget() would
> become giveCentralWidget(), matching its takeCentralWidget().  This
> would save the search for its doc, to find that it does indeed take
> ownership.
> 
> The signature is, in any case, always sufficient to make clear that a
> give()r isn't a get()ter.

Let's stop the discussion about method *naming* right here. We're not going to 
change hundreds of getters and setters now or even in Qt 6.

Let's instead find a solution that either uses macros or uses simple binary-
compatible pointer wrappers like GST.

And be careful with template functions. Changing from T to Something<T> may 
change what gets deduced.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center






More information about the Development mailing list