[Development] Setters: Clarifying the ownership

Eric Lemanisser eric.lemanissier at gmail.com
Sat Jan 20 09:17:43 CET 2018


Please use an already existing solution to this problem :
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-raw
Errors will be caught by the compiler in case of std::unique_ptr, and by
static analysers (like clang-tidy) for gsl::owner, without run-time cost.
There was already an attempt to use gsl::owner
https://codereview.qt-project.org/#/c/178107/ but it did not go forward,
because of lack of time ?

Le ven. 19 janv. 2018 à 19:33, Thiago Macieira <thiago.macieira at intel.com>
a écrit :

> 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
>
>
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180120/68942d83/attachment.html>


More information about the Development mailing list