Comment to Better Name
It is very easy to name methods, files, classes or functions, if we don't care about other people, or about future us. This technique help to figure out better name for while we code.
The idea is to first start with a comment in the code. Then translate that comment to name.
From a good comment to a good method name
Lets see an example. We want to create something what produces users and sends the produced users to a queue. We start with comment in the code.
Then we translate this comment to class name, for now.
Then we want to implement a method that will do the work. We write a command what that method is going to do.
Then we translate the comment to a method name.
We always review the name, if it contains any duplications, we remove them. Or sometimes, we need to change the name to make it really understandable.
Good comment, bad name
Here is an example that shows only the first part done well, the comment provides enough information to justify what is going to happen. We have created a very good comment for the method call, Move all the remaining urls in one slot
. But the name of the method does not reflect that good intention.
Here is how the method should be named. The consequence of making the method with proper name, can mean we need to create another method and fix the confusion.
Ideally, we would also rename updateSlotForAllUrls
method. But that might be difficult, because we will need to go through the method code and figure out what the method is really doing.
Last updated
Was this helpful?