4 ms·
Too bad you're heavily downvoted. Principle "function name is a noun if it returns something, and verb if it doesn't" is super useful - just by looking at its n
by ivanche 6y ago
Too bad you're heavily downvoted. Principle "function name is a noun if it returns something, and verb if it doesn't" is super useful - just by looking at its name you know immediately if it has side-effects. Since I learned it I apply it all the time in programs I write alone, but almost always I see pushback in a team because people are unfortunately used to see `getX`, `fetchY` etc. as method names.
- augustk 6y agoI guess a verb phrase comes up naturally when you are eager to implement a new function and think of all the steps required to calculate the result. However, a noun phrase is a more proper abstraction since the implementation may change to simply return a cached value. (see also the Uniform Access Principle). Anyway, here is my naming strategy: 1. Boolean pure function Use an adjective phrase where the adjective is the last word, for instance UrlValid or DefinitionFound. 2. Non-boolean pure function Use a noun phrase where the noun is the last word, for instance CurrentDefinition or DefinitionUrl. 3. Non-pure "function" Use a verb phrase where the verb is the first word, for instance PrintError or ReadInput.