- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
throw new WTFException("frist")
Admin
Eh?
YAML is perfectly cromulent. One could argue that XML, SGML, JSON and so on are equally cromulent. I have my preferences, and I don't like verbosity and start-end tags and so on, but I can work with all of them, given a decent parsing apparatus.
I'm assuming that Remy has been bitten by a lousy project that happened to use YAML as a transfer/storage protocol, because otherwise I can't see why the WTF here is YAML.
Admin
Yet... I like this code and especially the style of the programmer responsible... I may self-reflect and do some soul-searching tonight (whilst sleeping). Most likely, I'll still like this WTF afterwards.
Admin
YAML is sometimes nice to use, but then once you start to stumble onto bizarre things like the Norway problem, it makes you want to give up software engineering and go back to making furniture.
Admin
the true WTF is that this code if (! $message) { $message = "WTF!?"; } else { $message = "WTF!? " . $message; } can be rewritten as this:
$message = $message ?? ''; $message = "WTF!? " . $message;
Admin
The great secret about YAML is that it accepts loose JSON as well. So you can nearly completely ignore all the indentation rules and spell out your data structure as JSON, with comments and no need to quote most of your object keys!
Admin
TRWTF is this code is how to determine when a trailing space is needed for readability....
Admin
If I had a dollar for every hour of my life that had been stolen trying to figure out bizzare and obscure edge cases in YAML documents that were causing failures I'd have enough money to convince everyone to use a decent data format.
Admin
I love this line:
if ($contents === false)
He didn't check for true and FILE_NOT_FOUND, and that's TRWTF.
Admin
Nah, that's not PHP'ish enough.
$messages = ['WTF!?'];
if ($message !== null) $messages[] = $message;
parent::__construct(implode(' ', $messages), $code);
Admin
If I hear "YAML Be There" one more time, YAML burn the building down.
Admin
If you're looking to be concise, just...
$message = 'WTF?!' . ($message ?? '');
Admin
We've run into the Norway Problem with a vendor. It can vary based on the version of YAML in use (and what parser/validator people are using). See https://stackoverflow.com/questions/53648244/specifying-the-string-value-yes-in-a-yaml-property
Admin
YAML is really, really bad.
I can't count the times that errors caused crazy effects in Kubes for Docker containers, simply because something was parsed as a value but was intended as a string or simply because indenting was wrong, messing up the whole file.
And for all defending "indent as data" as a feature:
The reason why most modern, professional formats scope their data or code explicitly is simply because it was one of the most common errors. Scope tags are there to separate visual document design from data, because scope is the context in which the data is hosted, and therefore data itself. If you remove tags for scoping (begin end tags, terminator tags, etc.), you remove the only weak error checking available to a parser and for humans as well to find the actual mismatch but cross referencing the document with it's indenting.
So yeah, all formats that use visual layout as data are way more error prone and harder to maintain than formats separating data from design. Which makes YAML one of the worst out there.
Admin
Cries in Python
Source code is ultimately also a data format. I wonder how well Python projects do with git merges...
It sounds nice at first, but in most cases I'd prefer C style brace syntax and a code formatter over making the programmer into a code formatter. Indentation for the benefit of the programmer, explicit grouping, even if redundant with indentation, for expressing the actual structure TO the formatter.
Brace syntax is especially nice, because it is more consistent for tooling than having to tell a tool which keywords start a block and which end it (compared to e.g. bash or Fortran).
Addendum 2022-05-05 10:25: In Emacs Lisp I love how uniform the syntax is. Sadly, the use of parentheses for EVERYTHING can make it hard to see, if you're looking at an assignment or a condition :/
Admin
Mostly OK. You usually either aren't changing the structure of the program very much in the first place, or the change you're doing is obvious (even if it isn't to git).
Admin
YAML is to JSON what Python is to PHP. YAML / Python: Indent one thing wrong and it can all blow up in your face. (Never mind getting into tabs vs spaces.) JSON / PHP: Beginners can do some truly horrible things with them and give them a bad name. (And they really DGAF about tabs or spaces outside quotes.)