Posted by : Deepak Vasudevan Friday, September 26, 2008

Magic Numbers in the Code

When you write a code and somewhere down the line, you are using an arithmetic constant like PI, have it defined as some readOnly constant string and use the string instead of hardbinding the number value in the code. There are good advantages of avoiding magic numbers in the code:

  1. Isolating the magic numbers into a single place labeling them with a variable would help in adjusting the precision value later.
  2. The code appears cleaner and neater without beguile numbers spread across the code and confuse a new person maintaining your code.
  3. Troubleshooting problems because of values to these constants is easy.

Popular Post

Blogger templates


Blog Archive


Blog Archive

Powered by Blogger.

- Copyright © Lavanya Deepak -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -