Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S-How to deal with some magic number?

 
Chih-Wei Lee
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How you guys deal with some magic number, like the index of data field?
For example, on UI portion, you have to know the index of owner field is 5
so you can set a customer ID when someone book a contractor, like
data[5] = "BS123456";

Do you hard code the index "5" or how you handle this?

Thanks
 
John Mattman
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How you guys deal with some magic number, like the index of data field?
For example, on UI portion, you have to know the index of owner field is 5
so you can set a customer ID when someone book a contractor, like
data[5] = "BS123456";



Hello Chih,

I am doing B&s version 2.3.3. As per the instructions in my assignment, the data type for customer id is 8 digit number. Does you assignment say it as an alphanumeric?.

In my assignment I have hard coded the magic value as static constant.
I am only using it for validating my database.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Chih-Wei Lee;

In my opinion and project, hard code these index instead of getting it dynamically.

Regards.
Mohamed Darim.
 
Chih-Wei Lee
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response.
John, you are right. the customer id is 8 digit number.
I didn't notice this, sorry.
 
Rico ZHANG
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I got a similar question.
Just want to know can I set the other header information as final static variables(coz tat will be much easier), or I should load it from the db file every time I need them.

i.e, the length of every field in a record,
the offSet of the Record 0..

things like this.

Thanks...
 
Chih-Wei Lee
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read header information from db file every time when I run a server or run the local mode application.
In my opinion, since I need to read data from db file every time, it would be easier that I also read head and schema information. At least, I don't have to hard code the beginng position of data section in db file.
But I hard code the magic cookie because I need it to check if the loaded db file has valid format so that my program is able to process it.

Lee
 
Rico ZHANG
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lee,

Tat really helps.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic