Friday, March 11, 2016

Rename method

When to rename a method or a function?

But before that, do you know what is the difference between a method and a function?

Well a method is a married function :-)

Joking, a method is a function that is associated (for life) with another class,. So a method is a class function.

Back to our refactoring.

We need to rename a function in one of the following cases:

- the previous developer picked a name so bad that nobody understand what it is about. Remember the name should tell us everything we need to know about its purpose

- the purpose of the function changed

- the return type changed. For example if getUser is now returning an Account, of course it needs to be changed to getAccount

- the name is not following the coding standards the team adopted.

Finding a good name is not easy. But working with bad names is a pain, so the effort is paying off.

Read more here How to name your variables and your kids

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.