-
Notifications
You must be signed in to change notification settings - Fork 3
Naming methods
Michael Watts edited this page Aug 11, 2016
·
2 revisions
Ask yourself:
What is this method doing?
The answer dictates what the method should be called. It is completely independent of the programmer, of course.
Choosing your method's verb:
- Performing calculation(s): calculate
- Retrieving data: get or retrieve
- Mutating data: set or change
- Deleting data: delete or remove
- Converting: convert
- Initiating an action: start or initiate
- Stopping an action: stop or cancel
Now, not all methods begin with a verb; but they really don't need to. If you read:
... myString.length();
or
... myArray.size();
you know exactly what is going on - no verb required.