Ask HN: When data is code, what is the meaning of a config script?
I'm writing a game engine in a combination of C++ and the dynamic language Io. (http://iolanguage.com/) Some of the operational code of the engine will be written in Io scripts, while all of the configuration settings will be in Io scripts. (No need to invent a special text file format when Io's terse syntax makes it just as easy to specify settings data directly as Io code.)
It seems strangely arbitrary to make a distinction between the Io scripts that describe operational components of the engine, and the scripts that describe lists of settings. After all, they are both in the same, Turing-complete language. When I am writing my configuration settings, should I just pretend the language has less features than it does, restricting my Io code in the configuration scripts to just setting name-value pairs?
On the other hand you could go completely the opposite way and hardcode all the values in the scripts that comprise operational code. While this sounds like a recipe for a mess, it would satisfy our minimum goal for scripting the game engine, which is that we want to be able to change settings without recompiling the C++ code. It would certainly be simpler by some measure. Although you might be editing a settings value while it is surrounded by other very important code!
We don't have to go to either extreme, but when the data itself is also represented in code, there's no longer any imposed limits on the difference between configuration files and code files. Where would you place the distinction?
3 comments
[ 4.1 ms ] story [ 17.7 ms ] threadAny code, e.g. startup scripts should be ideally in a separate file. In the *NIX tradition these are usually of the form .foorc where 'foo' is the name of the app, and the '.' hides the file from normal directory listings. Ideally, it would be nice to pre-parse such startup code and only execute if it is syntactically correct.
So what's the difference between a config file and code? Config files aren't compiled (so no need to rebuild when you change them) and they are intended to be modified by the user, while other code isn't.