What’s in the name?

Contributed by Khurshidali Shaikh on 25 Mar 2009

This may be true when naming humans and many other things but when developing software names used inside the code are very important. While developing software, what names you give to entities (classes, methods, variables, files, etc) inside your code have a big impact on how easy it is to deal with the program during development and later during maintenance, by yourself and other team members.

We mostly use a person’s name to associate a label to a face.  A person’s name may have a meaning but it does not tell anything about the person. As opposed to this, names used inside software program are expected to be meaningful and serve as an indicator of what the entities represent or are expected to do.

Looking at some one else’s code, or even looking at one’s own code after a long time, is a pain. In addition to that if the proper names are not used it becomes irritating and difficult to work with.

Names used in a program should almost always fall into 2 categories

  1. Noun: These are used to represent some concept that is modeled in the system.
    e.g Customer, Order, Bank Account, etc
  2. Verb: These are used generally to name functions, methods, procedures, actions.
    e.g register(), calculateTotal(), copy(), delete()

    There are some exceptions like Collection.size(), StringUtils.defaultString(), etc but its still better to stick to the convention of using verbs to describe methods, functions, procedures.

Names should be explanatory but at the same time overly long names should be avoided
e.g. registerUserSendMailAndSubscribeToNewsletter()

Correct names should be used from the start and not left as a TODO exercise.  Correcting names in a program later on is a difficult task as there may be dependencies  involved and this also needs further testing to be done. Also once a software is running fine no one is interested in doing this unless its a paid effort or is mandated by someone.

Last but not least, names must not have spelling mistakes.

So next time you are coding think before naming anything and not use the first name that comes to your mind.

Visit us at Neevtech.com to know more about our offerings.

Tags: , , ,

facebook comments:

Leave a Comment