java - Hardcoding values vs. reading from file -


this general question efficiency of hardcoding data - i'm writing program in java chemical analysis, , need use isotopic abundances of different elements. way have set right values (which never need modified) stored final fields in class, i.e.

static final double c12abundance = .989; static final double c12mass = 12; 

a lot of similar programs store type of data in xml file, read values there, this:

<compounds> <elements>     <element symbol='c' mono_isotopic_mass ='12.00000000000' abundance='.989'/> 

is there reason (performance, memory, etc) read way? seems easier leave field.

hard coding way faster in terms of performance , memory allocation.

the thing gain reading file code re-usability (running program different parameters without need recompile it).

note reading file has following steps:

  1. declare variable use storing value.
  2. create input (stream) object
  3. initialize path
  4. open file fs
  5. find correct line read from
  6. read value
  7. store in variable above
  8. close input (stream)

that's pretty big overhead instead of having pre-compiled final variable value


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -