risorse | nomi di funzione

The Poetry of Function Naming

Alcune considerazioni sulla scelta dei nomi delle funzioni di un indiscusso esperto del settore:

The goal is to take the concept and functionality of a function, and capture the essence of it in one, or two, or perhaps three, words (like Riffle, or DeleteCases, or FixedPointList) – chosen so that when someone sees those words, they immediately get the right idea about the function.
The reason you can't find a good name is because you don't really understand with complete and ultimate clarity what the function does. And sometimes that's because the function really isn't designed quite right. There's something muddled about it, that has to be unmuddled before you'll ever be able to find a good name.
In ordinary human languages, new words typically develop by some form of natural selection. [...] But for a computer language the pattern is necessarily different. For once a function name – that corresponds to a “word” in the language – has been introduced, it must immediately be a full, permanent, element of the language.
Function names are in a sense ultimate points of human-machine communication. They're the places where all that internal computational activity has to be connected with something that humans can understand.
[...] one of the responsibilities of function naming is that it is the names of functions that to a large extent directly determine how people will think about a function. If they are led in a particular direction by the name, that will be the direction in which they will go in using the function.
A sophisticated function should have a sophisticated name (like DynamicModule or EventHandler). A straightforward, common, function should have a simple name (like Length or Total). A function that does a clear but unusual thing should have an unexpected name (like Thread or Through).
When one finds a good name for a function, one of the things that happens is that when people hear the name, they can successfully “unpack” it into a one-sentence description of what the function must do – often in effect just by using the name of the function as the main part of a sentence.

Riferimenti

Wolfram, S. "The Poetry of Function Naming". Stephen Wolfram Blog. <http://blog.stephenwolfram.com/2010/10/the-poetry-of-function-naming/>. Visitato il 29 Novembre 2012.

Pagina modificata il 29/11/2012