this post was submitted on 08 Sep 2024
1236 points (98.3% liked)

Programmer Humor

32580 readers
246 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 179 points 2 months ago (4 children)

Some data formats are easy for humans to read but difficult for computers to efficiently parse. Others, like packed binary data, are dead simple for computers to parse but borderline impossible for a human to read.

XML bucks this trend and bravely proves that data formats do not have to be one or the other by somehow managing to be bad at both.

[–] [email protected] 51 points 2 months ago (1 children)

The thing is, it was never really intended as a storage format for plain data. It's a markup language, so you're supposed to use it for describing complex documents, like it's used in HTML for example. It was just readily available as a library in many programming languages when not much else was, so it got abused for data storage a lot.

[–] [email protected] 7 points 2 months ago

That's why professionals use XML or JSON for this kind of projects and SQL for that kind of projects. And sometimes even both. It simply depends on the kind of problem to solve.

[–] [email protected] 25 points 2 months ago (2 children)

Strong competition from yaml and json on this point however

[–] [email protected] 43 points 2 months ago (3 children)

JSON not supporting comments is a human rights violation

[–] [email protected] 15 points 2 months ago (1 children)

IIRC, the original reason was to avoid people making custom parsing directives using comments. Then people did shit like "foo": "[!-- number=5 --]" instead.

[–] [email protected] 4 points 2 months ago

I've written Go code; they were right to fear.

[–] [email protected] 9 points 2 months ago (1 children)

I wrote a powershell script to parse some json config to drive it's automation. I was delighted to discover the built-in powershell ConvertFrom-Json command accepts json with // comments as .jsonc files. So my config files get to be commented.

I hope the programmer(s) who thought to include that find cash laying in the streets everyday and that they never lose socks in the dryer.

[–] [email protected] 6 points 2 months ago

There is actually an extension to JSON: https://json5.org/

Unfortunately only very few tools support that.

[–] [email protected] 5 points 2 months ago

Wouldn't go that far, but it's an annoyance for sure.

[–] [email protected] 32 points 2 months ago (5 children)

Alright, the YAML spec is a dang mess, that I'll grant you, but it seems pretty easy for my human eyes to read and write. As for JSON -- seriously? That's probably the easiest to parse human-readable structured data format there is!

[–] [email protected] 9 points 2 months ago (2 children)

it is anything but easy to read if your entire file does not fit on a single screen.

[–] [email protected] 6 points 2 months ago* (last edited 2 months ago)

What data format is easy to read if it fills more than the entire screen?

[–] [email protected] 2 points 2 months ago

what kind of config file is short enough to fit on a single screen with line breaks?

[–] [email protected] 8 points 2 months ago (1 children)

My biggest gripe is that human eyes cannot in fact see invisible coding characters such as tabs and spaces. I cannot abide by python for the same reason.

[–] [email protected] 3 points 2 months ago (2 children)

You can set those things to be visible in many editors. Its ugly tho

[–] [email protected] 4 points 2 months ago (1 children)

Until you're doing an online course in a simplistic web editor. Don't ask me how I know 🥲

[–] [email protected] 1 points 2 months ago

How do you... Oh sorry

But yeah that sounds unpleasant

[–] [email protected] 3 points 2 months ago (2 children)

The language should just let me specify which character I want for that. I would use ">".

[–] [email protected] 2 points 2 months ago

That'd be an editor thing rather than a language thing, I would have thought. It's probably configurable in some

[–] [email protected] 2 points 2 months ago

It would be a compiler directive, I think. Or let me type "end if" and just disregard the coding indentation

[–] [email protected] 3 points 2 months ago

We're we are going we don't need any comments.

[–] [email protected] 2 points 2 months ago (2 children)

I don't know much apart from the basics of YAML, what makes it complicated for computers to parse?

[–] [email protected] 14 points 2 months ago* (last edited 2 months ago) (1 children)

the spec is 10 chapters. everything is unquoted by default, so parsers must be able to guess the data type of every value, and will silently convert them if they are, but leave them alone otherwise. there are 63 possible combinations of string type. "no" and "on" are both valid booleans. it supports sexagesimal numbers for some reason, using the colon as a separator just like for objects. other things of this nature.

[–] [email protected] 1 points 2 months ago

Yes, the classic "no" problem of YAML. But the addition of the comments is very nice.

[–] [email protected] 9 points 2 months ago

Sometimes it's a space, sometimes its a tab, and sometimes it's two spaces which might also be a tab but sometimes it's 4 spaces which means 2 spaces are just whack And sometimes we want two and four spaces because people can't agree.

But do we want quotes or is it actually a variable? Equals or colon? Porque no los dos?

[–] [email protected] 1 points 2 months ago

Those formats are not for humans to read or write. Those are for parsers to interpret.

[–] jimitsoni18 8 points 2 months ago

Just a while ago, I read somewhere: XML is like violence. If it doesn't solve your problem, maybe you are not using it enough.

[–] [email protected] 3 points 2 months ago (3 children)

There are people who find XML hard to read?

[–] [email protected] 5 points 2 months ago

Over time I have matured as a programmer and realize xml is very good to use sometimes, even superior. But I still want layers between me and it. I do output as yaml when I have to see what’s in there

[–] [email protected] 3 points 2 months ago* (last edited 2 months ago) (1 children)

Depends on how complex it is. Ever see the XML behind SharePoint? 🤮

[–] [email protected] 4 points 2 months ago

But is that the fault of XML, or is the data itself just complex, or did they structure the data badly?

Would another human readable format make the data easier to read?

[–] [email protected] 3 points 2 months ago

I see you've never worked with SOAP services that have half a dozen or more namespaces.