5 ms·
As others have said, Tcl has some unique advantages. My preferred one, which I have not found in other languages (besides LISP, obviously): treat data as code.
by zvr 3y ago
As others have said, Tcl has some unique advantages.
My preferred one, which I have not found in other languages (besides LISP, obviously): treat data as code.
This way your configuration files are Tcl code using some proc's that you have defined, but they can also include arbitrary code. In order to read them, you simply fire up a slave (safe) interpreter and get the results.
If anyone knows how to do this easily in Python, I'm all ears!
- dkfellows 3y agoPython has nothing at all like safe interpreters (I've looked). You just can't prevent things from leaking, it isn't designed for it at all. You can do a half-hearted approach by specifying the globals dictionary to eval(), but you can't really count on safety because the builtins do the leaking and you can't really stop anyone from finding a way to get back to that; the language is just too deeply interlinked for a proper security boundary to be erected anywhere inside it.
- krapp 3y agoI mean, if it's just Python code as config for a Python, couldn't you just write your config in a Python file and include it? Typically the reason for not using a full-blown programming language for config is to avoid Turing creep - the tendency to want to push complexity into config in order to make the application code simple. At some point the config gets to complex it needs its own config. I run into this temptation using Lua a lot. Lua tables are perfect for config, but it would also sometimes be so convenient to just pop on a metatable and turn it into a class, maybe a proper API, when really all I need is a table that defines constants, maybe some conditionals, arrays, a map and that's it.
- zvr 3y agoI like having a config file like: host thatmachine.example.org port 9991 dbhost server.example.org ... which I can definitely parse myself. But it's also valid Tcl, if host/port/dbhost are defined proc's! So this allows people to be able to create config files like: set mydomain example.org host thatmachine.$mydomain dbhost server.$mydomain if {$mydomain == example.org} { port 12345 } else { port 9991 } I don't expect people to create huge programs in their config files, but being able to give them a "full-blown programming language" for free is sometimes desirable.