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

Maciej Stachowiak mjs at apple.com
Mon Sep 5 15:17:52 PDT 2016

> On Sep 5, 2016, at 2:35 PM, Ryosuke Niwa <rniwa at webkit.org> wrote:
> On Mon, Sep 5, 2016 at 10:13 AM, Darin Adler <darin at apple.com <mailto: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.
> I agree the verb "take" is not semantically sound here.  How about
> HashMap::receiveReleased / ExceptionOr::receiveReleased?  Or simply
> HashMap::released / ExceptionOr::takeReleased?  Even HashMap::receive
> / ExceptionOr::receiveReturnValue might work better because "receive"
> is more a passive form of accepting the ownership of something.

receive() is still caller-perspective so it doesn't solve the issue with take(). If you wanted a detailed and wordy name, getAndRemove() would be accurate and callee-perspective (though natural for collections but not so much for smart pointers). getAndRelease() would make sense for smart pointers, but not really for collections, since you normally ask collections to remove (or delete or erase), but to release.

release() as shorthand for getAnd{Remove,Release}() seems ok, though it would be local jargon and I'm not sure it would be very readable in the case of a HashMap, to those who are not familiar with it. Without knowing the jargon, it would not be apparent that this line of code does a lookup and removes the item: value = map.release(key)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20160905/aa48060c/attachment.html>

More information about the webkit-dev mailing list