this post was submitted on 30 Jun 2024
561 points (98.1% liked)
Programmer Humor
19623 readers
2704 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
What I'd like for a configuration language is a parser that can handle in-place editing while maintaining whitespace, comments, etc. That way, automatic updates don't clobber stuff the user put there, or (alternatively) have sections of
### AUTOMATIC GENERATION DO NOT CHANGE###
.You need a parser that handles changes on its own while maintaining an internal representation. Something like XML DOM (though not necessarily that exact API). There's a handful out there, but they're not widespread, and not on every language.
JSON5
Is a very good idea providing much needed fixes to the JSON spec, but isn't really what I'm getting at. Handling automatic updates in place is a software issue, and could be done on the older spec.
Hmm, maybe I am missing the point. What exactly do you mean by handling automatic updates in place? Like, the program that requires and parses the config file is watching for changes to the config file?
As an example, Klipper (for running 3d printers) can update its configuration file directly when doing certain automatic calibration processes. The z-offset for between a BLtouch bed sensor and the head, for example. If you were to save it, you might end up with something like this:
Thus overriding the value that had been set before, but now you have two entries for the same thing. (IIRC, Klipper does comment out the original value, as well.)
What I'd want is an interface where you can modify in place without these silly save blocks. For example:
Since we're declaratively telling the library what to modify, it can maintain the AST of the original with whitespace and comments. Only the new value changes when it's written out again, with a comment for that specific line.
Binary config formats, like the Windows Registry, almost have to use an interface like this. It's their one advantage over text file configs, but it doesn't have to be. We're just too lazy to bother.
Ahh, then the modification must be done on the AST level not the in-memory representation since anyway you do it, you must retain the original.
Right.