Friday, September 26, 2008

Magic Numbers in the Code

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.

No comments:

[Imported from Blogdrive]Online Virus Scanners

Online Virus Scanners Virus Scanners are no longer difficult to install, tedious to configure. There are easy to use Online Virus Scanne...