This post is also about How We Write Clean Code.
when we write clean code First thing we should consider is putting meaningful names. This is a pretty simple thing, only thing you have to do is just think of some thing nice and matching to what they do (variable, function or classes). If u have watch Smurf its just like that you give names that exactly match with their personality.
There are few things you have to consider when giving names.
- Use intention Revealing Names
when you or some one read you variable name they should get What you was planing to do with it.- Avoid Disinformation
You have to be more careful when you tring to put Small names for variables, it should be more clear to others what you are tring to say. Clearly Do Not use soo much of small names in your codeEg-: If u write a code like this, can you say what is this A is really equal to is it zero or an another variable ???
- Use Pronounceable Names
If you can Read the variable name loud in front of others without sounding like an idiot then there is No Problem. Just put names that you can pronuce Eg -: Do not use something like this 'genymdhms' (generation date, year, month, day, hour, minute and second)- Use Searchable Names
When you write a big codes its not so easy to find variable and constants if you haven't name them properly .Eg -: if you have just put 7 as the working Days of the week instead of putting a constant 'WORKING_DAYS_OF_THE_WEEK' ,when you want to change the working days you have to check all the 7 's in the code. You will be in trouble if the code contain so many 7's :(
- Class Names
Classes and objects should have noun or noun phrase names like Customer, WikiPage,Account, and AddressParser.- Method Names
When you write a method make sure that you use verb or verb phrase like 'deletePage'when you are writing names don't use much cute names that only you can get. may be some people get the what you meant but not all.Cuteness in code often appears in the form of colloquialisms or slang. Eg -: don’t use the name whack() to mean kill().
These are just a few things that you have to worry when putting a name. These are just Simple things that make your code much more readable and clean.
Hope you guys get the idea of how to put a good name :D
Be happy Always friends.
No comments:
Post a Comment