开发者

Data files when using intepreted languages

Say I have some data which I want severa开发者_Python百科l 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜