175 points

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.

permalink
report
reply
51 points

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.

permalink
report
parent
reply
8 points

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.

permalink
report
parent
reply
25 points

Strong competition from yaml and json on this point however

permalink
report
parent
reply
42 points

JSON not supporting comments is a human rights violation

permalink
report
parent
reply
15 points

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

permalink
report
parent
reply
9 points

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.

permalink
report
parent
reply
5 points

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

permalink
report
parent
reply
32 points

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!

permalink
report
parent
reply
9 points

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

permalink
report
parent
reply
8 points

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.

permalink
report
parent
reply
3 points

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

permalink
report
parent
reply
2 points

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

permalink
report
parent
reply
1 point

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

permalink
report
parent
reply
9 points

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.

permalink
report
parent
reply
3 points

There are people who find XML hard to read?

permalink
report
parent
reply
5 points

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

permalink
report
parent
reply
3 points

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

permalink
report
parent
reply
3 points
*

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

permalink
report
parent
reply
3 points

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?

permalink
report
parent
reply
142 points

I mean, it’s not wrong

permalink
report
reply
20 points

Disagree. I prefer XML for config files where the efficiency of disk size doesn’t matter at all. Layers of XML are much easier to read than layers of Json. Json is generally better where efficiency matters.

permalink
report
parent
reply
16 points

TOML or bust

permalink
report
parent
reply
2 points

yes.

permalink
report
parent
reply
4 points

Aren’t most XML parsers faster than JSON parsers anyway?

permalink
report
parent
reply
3 points

Wishful thinking

permalink
report
parent
reply
89 points

Wow, that’s a very passive aggressive reaction. I enjoyed a lot.

permalink
report
reply
46 points

This is what happens when stack overflow is used for training.

permalink
report
parent
reply
21 points

Not long before AI just tells me to google it, or read the manual.

permalink
report
parent
reply
2 points

Yea, the Bing chat (or what it was originally called) sometimes used to tell people to learn coding instead of asking it to generate code.

permalink
report
parent
reply
5 points

This is what happens when people make content for points.

OP already admitted he made it up.

permalink
report
parent
reply
72 points
*
Deleted by creator
permalink
report
reply
28 points

IMHO: XML is a file format, JSON is a data transfer format. Reinventing things like RSS or SVG to use JSON wouldn’t be helpful, but using XML to communicate between your app’s frontend and backend wouldn’t be either.

permalink
report
parent
reply
21 points
*
Deleted by creator
permalink
report
parent
reply
4 points

The amount of config.jsons I’ve had to mess with…

Yeah, json is not a good config format. As much as xml is not. Please use something like YAML or TOML.

permalink
report
parent
reply
1 point

Of course you can use XML that way, but it is unnecessarily verbose and complex because you have to make decisions, like, whether to store things as attributes or as nested elements.

I stand by my statement that if you’re saving things to a file you should probably use XML, if you’re transferring data over a network you should probably use JSON.

permalink
report
parent
reply
9 points

We were using XML for that before JSON.

permalink
report
parent
reply
3 points

Yes and it is a good thing we don’t anymore.

permalink
report
parent
reply
25 points

That’s my biggest peev about JSON actually. No comments!! WTH!

permalink
report
parent
reply
15 points
*

On one hand I agree, on the other hand I just know that some people would immediately abuse it and put relevant data into comments.

permalink
report
parent
reply
9 points

do they do that in xml? never seen that

permalink
report
parent
reply
5 points

This is why there are none, but I still think it’s dumb. Parsers can’t see comments anyways.

permalink
report
parent
reply
0 points

There’s comments in the specs and a bunch of parsers that actually inore //

permalink
report
parent
reply
13 points
*
{ "key": "six",
  "value": 6,
  "comment": "6 is a bad number. Use five." }
permalink
report
parent
reply
28 points
*
Deleted by creator
permalink
report
parent
reply
2 points
*

Yes, it’s a field. Specifically, a field containing human-readable information about what is going on in adjacent fields, much like a comment. I see no issue with putting such information in a json file.

As for “you don’t comment by putting information in variables”: In Python, your objects have the __doc__ attribute, which is specifically used for this purpose.

permalink
report
parent
reply
17 points

Please don’t. If you need something like json but with comments, then use YAML or TOML. Those formats are designed to be human-readable by default, json is better suited for interchanging information between different pieces of software. And if you really need comments inside JSON, then find a parser that supports // or /* */ syntax.

permalink
report
parent
reply
11 points

And there are some truly magic tools.

XSDs are far from perfect, but waaay more powerful than json schema.

XSLT has its problems, but completely transforming a document to a completely different structure with just a bit of text is awesome. I had to rewrite a relatively simple XSLT in Java and it was something like 10 times more lines.

permalink
report
parent
reply
8 points
*
Deleted by creator
permalink
report
parent
reply
3 points

And don’t forget about namespaces. Look at formats like HAL and ODATA that try to add HATEOAS onto JSON.

permalink
report
parent
reply
1 point

Did you write your transform logic ground-up or use a third-party library? I’m not a Java dev, but I feel like someone has to have already solved this problem in pretty much every language anyone actually uses.

permalink
report
parent
reply
6 points

People may hate on SOAP but I’ve never had issues with setting up a SOAP client

permalink
report
parent
reply
4 points
*
Deleted by creator
permalink
report
parent
reply
2 points

I came into the industry right when XML fever had peaked as was beginning to fall back. But in MS land, it never really went away, just being slowly cannibalize by JSON.

You’re right though, there was some cool stuff being done with xml when it was assumed that it would be the future of all data formats. Being able to apply standard tools like XLT transforms, XSS styling, schemas to validate, and XPath to search/query and you had some very powerful generic tools.

JSON has barely caught up to that with schemes and transforms. JQ lets you query json but I don’t really find it more readable or usable than XPath. I’m sure something like XLT exists, but there’s no standardization or attempt to rally around shared tools like with XML.

That to me is the saddest thing. VC/MBA-backed companies have driven everyone into the worst cases of NIHS ever. Now there’s no standards, no attempts to share work or unify around reliable technology. Its every company for themselves and getting other people suckered into using (and freely maintaining) your tools as a prelude to locking them into your ecosystem is the norm now.

permalink
report
parent
reply
71 points

finally accurate ai

permalink
report
reply
15 points

Except for obvious typos

permalink
report
parent
reply
2 points

XML is fine. Namespaces have a special place in hell though

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

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

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 4.2K

    Monthly active users

  • 947

    Posts

  • 10K

    Comments

Community moderators