I'm having hard time deciding which name to choose for my method. I think they both are pretty much self-explanatory, but the latter is faster to type, so, my current preference is supportedModes(). What do you think?
A:
I would prefer the more explicit which is getSupportedModes. You don't want other developers to second guess what the method does.
Vadim
2010-01-01 15:36:10
A:
Functions that act on more than just their passed arguments should be named as actions.
Ignacio Vazquez-Abrams
2010-01-01 15:36:33
Not all "functions are actions". Is `sqrt()` an action? Should it be named `CalculateSquareRoot()`? Usually *functions* are not actions, while *methods* usually are.
Martinho Fernandes
2010-01-01 16:01:23
An important distinction. Answer clarified.
Ignacio Vazquez-Abrams
2010-01-01 16:06:36
+3
A:
To me, getSupportedModes
implies simple retrieval, whereas if there is some actual logic involved to work them out, something like determineSupportedModes
or calculateSupportedModes
may be better. The name should describe what the function does. Brevity is not a major consideration with modern IDEs with some form of autocomplete.
Different languages also have their own conventions. For example, a function called calculateSupportedModes
in Java would normally be called CalculateSupportedModes
in C# or VB.
David M
2010-01-01 15:45:29
+1 for the note on autocomplete. Being a lazy typist is no excuse for poor variable/method naming with a modern auto-completing IDE.
Paolo
2010-01-01 16:10:11