There is a useful pattern to follow when naming functions:
namespace? + high context (HC) + low context? (LC) + action (A)
Take a look at how this pattern may be applied in the table below.
Name | Namespace | High context (HC) | Low context (LC) | Action (A) |
---|---|---|---|---|
userGet |
User |
Get |
||
userMessagesGet |
User |
Messages |
Get |
|
clickOutsideHandle |
Click |
Outside |
Handle |
|
shouldMessageShown |
should |
Message |
Shown |
Note: The order of context affects the meaning of a variable. For example,
shouldUpdateComponent
means you are about to update a component, whileshouldComponentUpdate
tells you that component will update on itself, and you are but controlling when it should be updated. In other words, high context emphasizes the meaning of a variable.
When you write code in IDE, you have an "code intelligency" or autosuggestion. If you type action first "get", you'll see all function in project that has "get" action, and you need to type High context and Low context to reduce amount of methods. But if you first type High context you can see all functions that can operate with that context and with lowest contexts, then you can narrow the search typing the Low context name, and now you see all functions you can do with that context and nothing more.