Important Note : program readability is most important after working software.
Guidelines in using variables :
Guidelines in using variables :
- Declare and define variable close to the where it is being used for the first time
- Use const wherever possible
- Keep variable scope as short as possible
- Try not to use global variables
- Use variable for one purpose only
- Avoid variable with hidden messages
Guidelines in naming variables :
- Code is read far more times than it is written. Favor read-time convenience over write-time convenience
- You should not give variable name like how you name your dog
- Goodness/ Badness are determined by variable`s name
- A good variable should be readable ,memorable and appreciate
- Avoid the variables names like temp, x, y (who knows what does that mean ??)
- Try to give names to problem domain
- Come up with a standard naming conventions in cases like revenveTotal, totalRevenve.. etc.
- For naming looping indexes, Try to come up with a more descriptive names than I, j, and k
- Come with a better name than just using flag for naming status variables
- Give temporary variables more descriptive names
- Do not use negative variable names like “NotFound”, Use positive names like “Found”
- Avoid misspelled word in variable name like cnt(count) ,msg(Message)
- Do not differentiate variable names solely by capitalization
No comments:
Post a Comment