5 ms·
Except YAML is straight-up wrong at times, unless you know all the edge cases. I just learned unquoted NO is coerced to False. A classic case of leaky abstracti
by kortex 6y ago
Except YAML is straight-up wrong at times, unless you know all the edge cases. I just learned unquoted NO is coerced to False. A classic case of leaky abstraction/"bad magic".
Unless you have actual type annotations/tags (eg xml, jsonld, graphql), everything IS a string. There's no assumptions otherwise.
- nine_k 6y agoI would hazard to say that any magic is bad in engineering. (Sorry Perl fans!)
- laumars 6y agoThere isn’t really any magic in Perl, just lots of unfamiliar lexicon if you come from more traditional programming languages. Perls problem is it’s history is rooted in command line usage so there’s a tonne of inherited reserved single character variable names and such like that are optimised for keystrokes rather than readability. However you can certainly write Perl programs that don’t follow those older conventions and look more like a modern language.
- bmn__ 6y ago> There isn’t really any magic in Perl http://p3rl.org/guts#Magic-Variables http://p3rl.org/guts#Magic-Variables perl -MDevel::Peek=Dump -mTie::Scalar -e' //g; Dump $_; tie $c => "Tie::StdScalar"; Dump $c; Dump \%ENV ' 2>&1 | grep MAGIC
- jlokier 6y agoThat kind of magic in Perl has a different kind of meaning than "magic number/bool/string parsing" in YAML. Perl tied-variable magic just means there are (effectively) getter and setter properties attached to the variable. "Magic" is just the name that was chosen in the implementation, and it stuck. It's used to implement variables with special, automatic meanings, like $$ for "current pid" and $! for "last error". It's also used to implement variables with user-defined behaviours on access, which is quite handy for a lot of abstractions. A lot of modern languages support both of these things, because they are useful, but it's not called magic in those languages, it's called something like "watchers", "proxies", "getters and setters" or "hooks". No, the criticism of YAML-style "magic" is that it leads to entirely surprising behaviour from innocuous input. Perl magic is not that kind. If you're using a special variable, you already know why.
- laumars 6y agoThat’s just playing around with the same reserved variables I spoke of before and there is nothing magical about them aside their silly name. In fact the opposite is true, they’re actually predictable and well documented. They just happen to have terse names as a throwback to command line usage (eg you wouldn’t call $1 a magic variable in Bash because it happens to work the same as ARGV[1]). In fact in Perl, you can opt for longer, readable, lexicon over the terse single character variables; and that’s literally how modern Perl should be written. Whereas the problems described with YAML is where it can automatically alter your data based on what the parser “thinks” the data should represent. Which is generally what people mean when they talk about “magic” in IT: systems that don’t honour your input and instead automatically convert it into something else. Perl doesn’t do this even in spite of it looking like executable line noise to many.
- forgotmypw17 6y agotechnology without magic? nonsense
- kchr 6y agoInsert Arthur C. Clarke quote here.
- atoav 6y agoI think "magic" is often just abstraction. And while abstraction is certainly necessary to speed up work and declutter the brains of the end users, too much abstraction takes control away and bad abstraction takes the wrong decisions in your name. If you take a look at how string handling works in most programming languages there is a lot of "magic" going on there. Which isn't a bad thing necessarily, because most programmers don't want to deal with the intricates of strings unless they really have to. The key is that this magic doesn't get in your way and doesn't do too magical things nobody ever asked of it.
- anderskaseorg 6y agoYAML 1.2 removed most of the nonsense booleans and only recognizes true | True | TRUE | false | False | FALSE. https://yaml.org/spec/1.2/spec.html#id2805071 https://yaml.org/spec/1.2/spec.html#id2805071 Of course, even though YAML 1.2 is a decade old, there are still many parsers that accept YAML 1.1.
- kortex 6y agoHuh, I had no idea, thanks for the heads up!
- hannibalhorn 6y agoThat seems like a pretty sensible approach - eliminates the "Norway problem" altogether. I'd guess you have to use the "%YAML 1.2" directive in all documents in order to get it though...
- anderskaseorg 6y agoYou don’t need this directive to get YAML 1.2 parsers to parse your document as YAML 1.2; that’s the default. You only need it to instruct YAML 1.1 parsers to raise a warning (and I guess for parsers of future version of YAML to fall back to 1.2 behavior, if that ever happens). https://yaml.org/spec/1.2/spec.html#id2781553 https://yaml.org/spec/1.2/spec.html#id2781553 https://yaml.org/spec/1.1/#id895631 https://yaml.org/spec/1.1/#id895631
- tybit 6y agoThat was the GPs point, YAML contains a lot of insanity, but let’s not throw out what it got right along with everything it got wrong.
- dragonwriter 6y ago> Unless you have actual type annotations/tags (eg xml, jsonld, graphql), YAML has actual type annotations (tags).
- kortex 6y agoWait, really? scrambles to check woah... I've never seen typed yaml, this is wild. negative: !!int -12 zero: !!int 0 positive: !!int 34 Can't say I love the notation, but indeed that is type annotations. I guess neither "yaml type hints" nor "yaml type annotations" are the right query. Had to search explicitly for "yaml tags".
- wowwow 6y agoTypes are !!screaming at reader. Don't want to start blameshitting, but is yaml supposed to be a simple human-readable format?
- kchr 6y agoIt is screaming with double negations!
- PaulDavisThe1st 6y agoIt's not screaming without double negations!!
- Varriount 6y agoThe neat thing is that you can use tags to represent custom data structures or functions. For example, AWS Cloudformation uses YAML tags as a shorthand for template functions [0]. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-base64.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGui...
- kanox 6y agoDepending on the parser you can also use them to call arbitrary code. This used to be the default behavior of `pyyaml.load`.