Classify your magic numbers in the database
I often see how developers do the same mistake over and over again.
This time it’s concerned with using the magic numbers in the database.
Often you get a request to realize something like:
“If a given piece of data is in positive status 1 or 101 then do this or that” or “Export all data which is in the positive status 1 or 101″
Usually what I see as being done then is:
Now think about what happens when the client calls you in 3 months from now asking to add another positive status?
Probably you will need to *hard code* it’s positive status in half a dozen places and then even forget about a couple of them… argh… awful.
What can be done?
Well, you can introduce your own level of abstraction - or better said - classify your statuses to avoid maintenance nightmare.
![statuses3[5]](http://vladan.strigo.net/wp-content/postfiles/2007/11/statuses35.jpg)
Now you can create your “Positive response” status classification in the Status Classifications table, and connect it to the current and future statuses pretty easily through the third table StatusClassificationStatuses.
Also, then you can do a better and cleaner query with something like:
![]()
This way your code doesn’t depend on the clients direct changes but on your abstraction - which in my book is a lot better.
As you can see this is a very simple and effective way to get yourself out of some bugs and issues in your applications.
Cheers!

Leave a Reply