2

My team is working on an android app. A co-worker and I have different ideas on how to load constant data.

To clarify, the data we are going to use

  • are 100 × (n × 〈integer-integer pair〉) where 10 < n < 20; not so many,
  • are rarely going to be edited in the future,
  • are supposed to be literally constant unless any single value is wrong,
  • are that the end users never need a direct acceess/modification to.

She suggested we put them in an XML, load & parse it during runtime in the name of "maintenance".

The data is actually light so XML parsing is not a big deal. However, doing unnecessary runtime tasks only to not mess up the code doesn't make sense to me. I'd rather write a simple program to read the raw data and spit out code to paste in.

input:

0   253
1   5150
2   6666
1   8126
3   11949
…

output:

arrays.add(new Pair(0, 253));
arrays.add(new Pair(1, 5150));
arrays.add(new Pair(2, 6666));
arrays.add(new Pair(1, 8126));
arrays.add(new Pair(3, 11949));
…

She is more experienced than me by a decade so I might be ignorant.

Can her approach ever be a good practice even though the data is not accessible from the user?

  • is your loading time critical? is the application directly linked to the numbers i.e. does the numbers change with a new version of the application and does the application need to keep backwards compatibility with the numbers? it has merit not having to change the code whenever such static numbers are modified. – Anders May 22 '15 at 5:10
  • @CyberSpock Nope, loading time doesn't really matter and the numbers aren't supposed to change except when the values are just wrong. So you have a point; no edit to the code. – Attacktive May 22 '15 at 5:19
2

doing unnecessary runtime tasks only to not mess up the code doesn't make sense to me

Actually, messing up the code just because to avoid some runtime tasks for which the running time does not matter does make much less sense to me. Your priorities should be

  1. make it right
  2. make it clean
  3. make it fast enough

exactly in that order. See also: Is premature optimization really the root of all evil?

  • To be honest, I haven't thought anyone would disagree. Now I think I'll need to experience more. =D Thank you for sharing your opinion. – Attacktive May 22 '15 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.