[webkit-dev] Terminology for giving up ownership: take, release, move
fpizlo at apple.com
Mon Sep 5 10:23:35 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?
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?
> — Darin
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
More information about the webkit-dev