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

Maciej Stachowiak mjs at apple.com
Mon Sep 5 15:11:58 PDT 2016


> 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?

In the context of a container, take() sort of makes sense by parallel to get(). Though get() could be interpreted as either what the caller is doing or what the callee is doing.

In other words, you could say that in the code below, function something gets an item from the collection. In that sense, take() is a parallel construct. Of course, you could instead say that function something asks collection to get an item. That's what makes take() not make sense. But I am not sure release() makes sense either way, for a collection. It conveys letting go of the item but doesn't seem to convey fetching in the sake way get() or take() do. I don't think move() would be right in this context either.

function something(Collection& collection, Key& key)
{
	doSomething(collection.get(key))
}


Given that explanation, I think a possible direction is to rename the smart pointer release() operation to take(). Many of our smart pointers already have a get(). And the idea of taking the underlying value from a smart pointer kind of makes sense, even though it is caller-perspective.

Regards,
Maciej


More information about the webkit-dev mailing list