0

Say I have some data which I want several kinds of. I think the easiest example could be tiles in a game: I would have grass, rock, tree, etc. each with different sets of values.

I would immediately go ahead and make a file and read it in at runtime, so I wouldn't have to recompile it all for a tweak with something like C++. But if I was using Python, or some other intepreted language, would there be much point in having to make the file in a format like:

kind grass
colour 0xdfdfdf
walk true
see true

Rather than:

class grass(tile):
def init(self):
I can't remember how to init. parents
self.colour = 0xdfdfdf

The obvious benefit of the first is lost, when you don't compile.

tshepang
  • 12,111
  • 21
  • 91
  • 136
PrettyPrincessKitty FS
  • 6,117
  • 5
  • 36
  • 51

1 Answers1

1

Several other reasons, not least that a non-coder may change config, let's make them comfortable.

You may have many different config files for different situations. If you use your code-based approach you have true, syntactically more complex, code replicated for each different config instance. I'd claim that multiple copies of code is a bad thing.

Furthermore, config need not come from a file, it might (for example) be in a database - in distributed systems that may be better than a file. Hence separating code and config can give flexibility.

djna
  • 54,992
  • 14
  • 74
  • 117
  • If I changed the requirements slightly-such that the only people editing this would be coder(s), and that it's only going to be done by files, would the time lost by having to complicate the syntax be that much of a loss against the time taken to write a parser and integrate it? – PrettyPrincessKitty FS Nov 30 '10 at 17:27
  • In some langauges, such as Java, reading a properties file is trivially available as a standard capability. So you may well have an off-the-shelf capability already. My appraoch generally is that I tend tonhave such things in my toolkit, so over time the build/integrate cost is quite small. – djna Dec 01 '10 at 17:45