[webkit-dev] Terminology for giving up ownership: take, release, move

Daniel Olegovich Lazarenko danielo at opera.com
Tue Sep 6 01:29:35 PDT 2016


Hello,

For a WebKit observer like me:
* "release" - has a well-known meaning in Mac/Objective-C world. It's
expected to "free" the memory. Same as COM's IUnknown::Release, but
different from auto_ptr::release or unique_ptr::release (which don't free
the memory).
* "move" - has a well-known meaning in C++ 11 world. Different from
"release" above. If I see methods "move" and "release" and they do the
same, I will have to learn and understand that trick.
* "take" - a typical name for collections like a blocking queue, heap and
some others (usually ordered). If it's a collection's method, it's
logically expected to return an item. The key distinction between
fred.takeCandy() and say bowl.takeCandy() is that bowl is passive. We treat
bowl as a passive bag of data, and expect others to take from it. It's
pretty easy to understand and remember, it makes intention more clear than
say "bowl.removeCandy()".
Pure OOP style is always the right way when it comes to readability. A good
example mentioned by Stroustrup once that it should be sqrt(5), not
5.sqrt(). Maybe "bowl.takeCandy" is a good compromise to keep it as a
method (instead of a global "TakeCandyFromBowl(bowl)").

Naming is fun.

--
Daniel
https://twitter.com/battlmonstr

On Mon, Sep 5, 2016 at 9:00 PM, <webkit-dev-request at lists.webkit.org> wrote:

> Send webkit-dev mailing list submissions to
>         webkit-dev at lists.webkit.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://lists.webkit.org/mailman/listinfo/webkit-dev
> or, via email, send a message with subject or body 'help' to
>         webkit-dev-request at lists.webkit.org
>
> You can reach the person managing the list at
>         webkit-dev-owner at lists.webkit.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of webkit-dev digest..."
>
>
> Today's Topics:
>
>    1. Terminology for giving up ownership: take, release,       move
>       (Darin Adler)
>    2. Re: Terminology for giving up ownership: take, release, move
>       (Filip Pizlo)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 05 Sep 2016 10:13:28 -0700
> From: Darin Adler <darin at apple.com>
> To: WebKit Development Mailing List <webkit-dev at lists.webkit.org>
> Subject: [webkit-dev] Terminology for giving up ownership: take,
>         release,        move
> Message-ID: <3AD4BD53-7CC2-4F26-8D3D-B3631413B796 at apple.com>
> Content-Type: text/plain; charset=utf-8
>
> Hi folks.
>
> WebKit has some critical functions that involve asking an object to give
> up ownership of something so the caller can take ownership.
>
> In the C++ standard library itself, this is called move, as in std::move.
>
> In WebKit smart pointers, we call this operation release, as in
> RefPtr::releaseNonNull and String::releaseImpl.
>
> In WebKit collections, we call this operation take, as in HashMap::take
> and ExceptionOr::takeReturnValue.
>
> The release vs. take terminology is distracting to my eyes. The verb
> ?take" states what the caller wishes to do, and the verb ?release? states
> what the caller wants the collection or smart pointer to do. My first
> thought was be to rename the take functions to use the word release
> instead, but I fear it might make them harder to understand instead of
> easier and clearly it would make them longer.
>
> Does anyone have other ideas on how to collapse WebKit project terminology
> down so we don?t have three different single words that are used to mean
> almost the same thing?
>
> ? Darin
>
> ------------------------------
>
> Message: 2
> Date: Mon, 05 Sep 2016 10:23:35 -0700
> From: Filip Pizlo <fpizlo at apple.com>
> To: Darin Adler <darin at apple.com>
> Cc: WebKit Development <webkit-dev at lists.webkit.org>
> Subject: Re: [webkit-dev] Terminology for giving up ownership: take,
>         release, move
> Message-ID: <8C068BFC-10D2-4388-919A-761CA9323EAB at apple.com>
> Content-Type: text/plain; charset=utf-8
>
>
> > On Sep 5, 2016, at 10:13 AM, Darin Adler <darin at apple.com> wrote:
> >
> > Hi folks.
> >
> > WebKit has some critical functions that involve asking an object to give
> up ownership of something so the caller can take ownership.
> >
> > In the C++ standard library itself, this is called move, as in std::move.
> >
> > In WebKit smart pointers, we call this operation release, as in
> RefPtr::releaseNonNull and String::releaseImpl.
> >
> > In WebKit collections, we call this operation take, as in HashMap::take
> and ExceptionOr::takeReturnValue.
> >
> > The release vs. take terminology is distracting to my eyes. The verb
> ?take" states what the caller wishes to do, and the verb ?release? states
> what the caller wants the collection or smart pointer to do. My first
> thought was be to rename the take functions to use the word release
> instead, but I fear it might make them harder to understand instead of
> easier and clearly it would make them longer.
> >
> > Does anyone have other ideas on how to collapse WebKit project
> terminology down so we don?t have three different single words that are
> used to mean almost the same thing?
>
> The use of "take" for these methods grinds my gears, for the same reason
> you were distracted: "take" describes the desires of the caller, but that
> doesn't work for me because I read "fred.makeCoffee()" as "makeCoffee()"
> being an imperative verb phrase and "fred" as being the subject that will
> make me the coffee.  So, "HashMap::take" means to me that the HashMap is
> taking something from me, rather than releasing something to me.
>
> I wonder if there is anyone who is surprised more by release than by take,
> and who would find it strange to say ExceptionOr::releaseReturnValue.
>
> I wouldn't want any words other than "release" used for this purpose,
> because I know exactly what to expect "release" to mean, since we use it so
> much already.  I think that would be even worse than sometimes using
> "take", because even though "takeReturnValue" is annoying, I've learned to
> know what it means.
>
> If there isn't anyone who prefers take, maybe we should just rename "take"
> to "release" in these cases?
>
> -Filip
>
>
> >
> > ? Darin
> > _______________________________________________
> > webkit-dev mailing list
> > webkit-dev at lists.webkit.org
> > https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
>
> ------------------------------
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
> End of webkit-dev Digest, Vol 136, Issue 3
> ******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20160906/1164209b/attachment.html>


More information about the webkit-dev mailing list