5 ms·
YAML: Probably not so great after all
- doublepg23 3y agoI think we should use X12, personally.
- triyambakam 3y agoI wrote an not very peformant parser for X12 once, if you mean the medical data format.
- secondcoming 3y agoSignificant whitespace is always a mistake.
- marssaxman 3y agoInconsistent formatting is a worse mistake, because people actually do read whitespace as structure, even when you wish they wouldn't.
- andrei_says_ 3y agoYes, it’s not perfect. Still, totally fine for pretty much everything I’ve needed it for. Maybe I'm just not that ambitious and haven’t hit any of the corner cases pointed out in the article. Have been using it as a html forms definition language for 7 years - with great success. So, yes, maybe not so great, but also not too bad.
- funcDropShadow 3y ago> Still, totally fine for pretty much everything I’ve needed it for. Try writing non-trivial multi-line bash snippets for Gitlab CI in yaml. These change your opinion very fast.
- andrei_says_ 3y ago1. “ writing non-trivial multi-line bash snippets for Gitlab CI” sounds intimidating even without the “in yaml” part. I don’t want to do it. 2. “In yaml” could be a fun way to end all kinds of sentences describing challenging tasks ;)
- kunley 3y agoYou don't want do do it, erm, but maybe people need to do it, because, huh, it's not an unreasonable thing to be put in the CI, right?
- andreareina 3y agoI have to look them up every. time. but YAML has a sigil for multi-line strings and lets you choose between strip/preserve newlines/leading whitespace. I still don't like YAML though
- npn 3y agobecause a sane people would delegate the task to a separated script instead.
- vb-8448 3y agoI wrote some non-trivial multi-line bash snippets for Gitlab CI in yaml and didn't find anything annoying. Any example that gave you problem?
- bagasme 3y agoAfter I digged into related articles on the link, it seems like the holy grail to the config files dilemma is to just hard-code desired settings in the source code. However, it also means that users (especially using binary packages) are stuck with settings from the distro. If you truly needs user-configurable setting, maybe TOML is for you.
- __blockcipher__ 3y ago> it seems like the holy grail to the config files dilemma is to just hard-code desired settings in the source code That is…not remotely the holy grail. You’re really throwing out the baby with the bathwater on that one. User-configurable settings are important for many, many applications. In the narrow case that you’re working on, say, a monorepo for closed-source code that only runs on your own servers, maybe in source code is fine provided there’s no host-level differences that would require a config file. But for any other circumstance…yeah you need some type of configurability.
- amluto 3y agoEven with a single company closed source monorepo, sometimes it’s useful to change settings without a restart and redeploy. And sometimes one runs more than one instance of the same code.
- deepsun 3y agoWhy not both? You can write config-looking Kotlin code so that user won't even realize it's Kotlin. But type-safe and with auto-completion. Something like server { port = 8080 addr = "127.0.0.1" development = true } db { url = $DB_URL user = "app" password = include(".secrets/dbpass.txt") }
- atoav 3y agoI wrote a "common-config" module for an internal python project, that works like this: 1. You hardcode settings in python using a multiline TOML string 2. Users may have multiple configs at the usual config folders 3. The configs override the hardcoded defaults wherever fields are present 4. Configs override each other in order of directories (when we are talking about xdg-directories) and within them in alphabetical order wherever fields are present This allows you to have good defaults, override some fields at will and add something like 99-debug.toml that you can just rename to 99-debug.toml.invalid if you don't need it anymore. The module also provides an install/edit cli and functions for printing the final resulting config and which configs it read on the way to that final config. At some point I have to publish it. If you need anything more than TOML because your use case is so crazy, then consider either writing a domain specific language or use a scripting language like lua, python, js, ...
- c7DJTLrn 3y ago90% of the people using YAML are not using 90% of the features in the spec. Somebody should make a subset of YAML with just the essentials while still remaining compatible. Maybe fix some of the type ambiguity stuff as well.
- NortySpock 3y agoMay I suggest StrictYAML? https://hitchdev.com/strictyaml/ https://hitchdev.com/strictyaml/
- unethical_ban 3y agoWhitespace significance is awful. After some time questioning why I have fallen out of love with python, I realized that is part of the answer.
- pphysch 3y agoThis is more of a tooling problem than a language problem. I haven't thought about Python whitespace in ages (i.e. since I switched to modern code editing tools).
- kleene_op 3y agoThere's a huge difference in desirability for white space significance depending on whether or not it is used for code or data storage. Because the best practice is to decompose your code in functions and classes, space significance isn't so much a problem in Python. YAML on the other hand, is a visually atrocious way to store tree-like/multi-layered data.
- semi 3y agoI somewhat agree in that it does feel like more of a problem in YAML than code, and infinitely more of a problem when doing both (template code generating yaml) But I still don't think there's any desirability for whitespace significance in code. Is there any problem it solves that isn't better solved by having enough structure and standardized tooling for autoformatting like go fmt?
- ajsnigrutin 3y agoYep, whitespace should be used to make things "pretty", and some kind of 'tidy' program should be able to do it automatically. Counting the spaces and/or tabs and/or not even knowing which one it is, really sucks. Some editors help a bit with that, but it still sucks.
- teytra 3y agoTABs should be used for indentation, making it line up pretty. SPace is for separating words. Modern editors (and old ones too) should be able to show what is a TAB, so there is no reason to be confused. The problem is that people think of TABs as a certain number of spaces, as if an indentation must be a certain number of spaces. In Python or Yaml etc, the logical construct is to have "one indentation level" for things like the statemants that belong to an if, or whatever. Requiring people to put in a somewhat randomly chosen number of spaces is just silly. It is "one level", so the logical choise would have been to put in one symbol to designate this fact, then use the settings of the editor to show it as you want (how many "spaces" to move), and this can change depending on personal choice, the monitor you use, etc.
- pragmatick 3y agoOff topic but the weird ligature in "especially" really threw me off. Strange choice.
- deafpolygon 3y agoFor simple, straightforward configs, it's probably better to use TOML. Anything more complicated can be shunted to XML. Just define a spec (schema) for it and you're good to go. Especially if that is going to be used as a data exchange for other applications or uses.
- eviks 3y ago> You’ll need to scroll up, but then you need to keep track of the indentation, which can be pretty hard even with indentation guides, Or you can collapse all the groups in your text editor and usually easily see what level you're at
- luzifer42 3y agoOne big issue is that if a YAML file gets truncated for some reason, parsers generally don't complain.
- baby 3y agoNever thought about that, but indeed there is no termination string. I guess the same is true for python
- quectophoton 3y agoAt this point for my own stuff I just use Lua by default. Just Lua, no stdlib. If I ever want something that is just literals and I'm sure I won't need conditionals or variables or fancy stuff, then I'd probably go for scfg[1]. [1]: https://git.sr.ht/~emersion/scfg https://git.sr.ht/~emersion/scfg
- arp242 3y agoIsn't this just a dupe of this story from yesterday? That's a Lot of YAML - https://news.ycombinator.com/item?id=37687060 https://news.ycombinator.com/item?id=37687060 - Sep 2023 (457 comments)
- koromak 3y agoEveryone hates yaml and I mostly agree. Should we start using something else? At least in the context of CI, I find .INI a little lacking, and TOML has similar gotcha's as yaml. At the very least its single-line restrictions frustrating for readability. That might be as subset of TOML though, not sure. Off the top of my head there's StrictYAML, which likely solves most of the issues, but I'd be interested in a pseudo-language similar to Terraform HCL. It seems config-files-as-scripts are here to stay in the CI world, so why not make config files more scriptable? Then theres dumb yaml calling smart bash or Makefiles, which has some benefits as well. But I don't see people wanting to split smallish configuration over multiple files. Bash scripts are harder to take in at a glance.
- teytra 3y agoI cannot agree to the statement "Everyone hates yaml". If that was true, it wouldn't have been used as much as it is.