views:

51

answers:

3

Imagine a function that deletes a cookie and returns its value.

What would you call it if you have to use a single verb?

I called it clear but I'm not very fond of the name.

+4  A: 

It sounds similar to Pop, except Pop typically acts on the last element in a collection. Perhaps Extract could be a suitable name?

Fredrik Mörk
Ouch. There goes my convention that List.Delete removes an item from the list and frees it, while List.Extract removes the item from the list and returns it, but certainly does not free it. Having an extract that deletes something, feels very disconcerting. I'd simply call the method Delete or DeleteCookie. The fact that the cookie is deleted seems far more important than that the method also happens to return the last value...
Marjan Venema
+2  A: 

I'd do something like this:

public String GetAndDeleteCookie(String cookieName); // C#
function getAndDeleteCookie(cookieName); // JavaScript
get_and_delete_cookie(cookieName); // php (forget exact syntax)
Nate Bross
+2  A: 

In the Ruby doc for hsh.delete(key), their doc is:

"Deletes and returns a key-value pair from hsh whose key is equal to key. If the key is not found, returns the default value."

So deleteCookie would probably be acceptable, the key is to just document the behavior properly.

dcp