Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Reading URLyBird data file

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

Until now when I am opening the data file of the URLyBird I was reading everything (every byte) from the data file and initializing my configuration with it. Example:

Reading the record length, reading the names of the headers etc etc.

What I want to ask is:

Is it ok to switch to an approach where I assume that the values given in the desciprion for URLyBird are correct ?

So for example that the HotelName fields is always 64 ? And that the length of the headerfield "name" is always 4 and it is found at the first position a.s.o. ?

Would it be ok to desclare final statics with these values ?


daniel
 
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel,


Currently I am doing the same, but I also have the same concern.

I think at the end, from the Object Oriented Design point of view you would want to make the Room and Data class as loosely coupled as possible, so you can make the Room
class reusable if at a later day, you have to switch your Data class implementation from a Data File (where you are forced to deal and manipulate all the Schema details)
to a RDBMS (MySQL, Oracle, etc.).

In the Andrew Monkhouse book, in the DVD class the equivalent of the Hotel Room in URLyBird, all the fields length are declared as static final constants, even though
in the Denny's DVD example from the book you don't have to deal reading a Schema.

I think the catch in URLyBird is that the data file format has to be preserved because it is also used by a legacy application to generate reports.

I think it is OK to have all the static final constants declared, as long as you justify it in your choices.txt.


HTH,



Carlos.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel and Carlos,

I read my database schema dynamically, so didn't use constants to declare field length etc. The only static I declared was the expected value of the magic cookie. My good buddy Roberto Perillo declared the necessary information in static final constants. We both justified in choices.txt and passed. So no need to worry, it is certainly a valid approach.

Kind regards,
Roel

 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I myself...

Roel De Nijs wrote:My good buddy Roberto Perillo declared the necessary information in static final constants.



Oh, there you go!
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also put mine in static file constants. I documented my decision and reasoning in my choices.txt and also validated the file header against my constants as the data class starts up.

Not sure if this is necessary, but figured it was important that if my program assumes a certain data structure and the data structure describes itself, its a good idea to compare them.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cory Max wrote:the data structure describes itself, its a good idea to compare them.

If you read data structure to compare values, why not just read it dynamically and make your program more solid, because able to handle changes in data structure without any code modification (like a column getting bigger) and your Data class can also be used to handle a file with customers (having complete other data structure)?

Kind regards,
Roel
 
Cory Max
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My only problem with doing that is the boolean flag for deleted. If the file describes itself as having more bytes describing that boolean value, how do I convert it to a boolean?

For now it is easy because I just use the

 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Cory!

Please take a look here. I think it might be helpful!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic