faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 6 people (100%) answered Yes
Recently 4 of 4 people (100%) answered Yes

Entry

I've heard the term "magic numbers", what does it mean?

Jun 20th, 2000 07:12
unknown unknown, Brian Matthews, Jason K. Monroe


Question continued:

Is it when a number is used instead of a name?  For example, magic 
numbers are when you use

rs.open sql, conn, 2, 3

Instead of using

rs.open sql, conn, adOpenDynamic , adLockOptimistic

Am I understanding this correctly?

Answer:

Yes, you are exactly right..  Magic numbers got the name due to the fact
that you can put a number as a param to a piece of code and no one will
really know what they mean.  It always helps to be as descriptive as
possible..

Even when I write server components, I will take parameterized inputs to 
my functions and routines and wrap them around an Enum to make it easier 
not only for myself to utilize the functions (6 months to a year down 
the road) but for other people to know what they mean as well..

It's all a readability/maintainability issue.  It's a heck of a lot 
easier to know that adOpenDynamic means that you are going to open up a 
recordset in dynamic mode.. then to say "2"



© 1999-2004 Synop Pty Ltd