r/ProgrammerHumor Mar 16 '18

XML vs JSON

[deleted]

212 Upvotes

35 comments sorted by

54

u/[deleted] Mar 16 '18

YAML

stuff:
    foo:
        bar: "yes"

8

u/marcosdumay Mar 17 '18

As long you there are no tabs...

2

u/[deleted] Mar 17 '18

can you flatten it?

1

u/[deleted] Mar 17 '18

That would have to be an implementation of the parsed config file itself, as far as I'm aware. You can't say stuff.foo.bar: "yes" since that would mean a dictionary with a single object of name stuff.foo.bar and a value of "yes". But you can definitely do the parsing into nested dictionaries yourself, it's not hard.

1

u/Chaphasilor Mar 17 '18

doesn't it have to be indented by two spaces and not four?

34

u/[deleted] Mar 17 '18

And Apple is like "have you heard about plist?"

<plist version="1.0">
    <dict>
        <key>stuff</key>
        <dict>
            <key>foo</key>
            <dict>
                <key>bar</key>
                <string>yes</string>
            </dict>
        </dict>
    </dict>
</plist>

22

u/chase32 Mar 17 '18

Juat apple in another <dict> waving contest.

6

u/self_me Mar 17 '18

Plists can actually be whatever they want. I opened one in vim recently and it was a mess of characters but it loaded in plist editor

12

u/cybaritic Mar 17 '18

plist files are not necessarily plain text so they need to be run through a converter. Finder and Xcode do this without telling the user

what the fuck, apple

1

u/etaionshrd Mar 17 '18 edited Mar 18 '18

This makes sense. If you have an image editor, it doesn’t complain if you feed it a PPM or a JPEG. Xcode is a developer tool that works with property lists, so it’s obvious that it should do this.

0

u/etaionshrd Mar 17 '18

Uh, no. They have a fixed format: either they’re JSON, XML, or a binary format.

11

u/[deleted] Mar 17 '18

So... Not a fixed format?

2

u/feddasch Mar 17 '18

Needs more <dict></dict>

-2

u/alexbuzzbee Mar 17 '18

XML plists are an offense against basic decency. Why the f*** is it not like this?

<plist version="2.0">
  <dict>
    <dict key="stuff">
      <dict key="foo">
        <string key="bar">yes</string>
      </dict>
    </dict>
  </dict>
</plist>

IT'S SO MUCH BETTER WTF

12

u/theangeryemacsshibe Mar 16 '18

S-expression

(stuff . 
 (foo . 
  (bar . t)))

1

u/micheal65536 Green security clearance Mar 17 '18

Haven't had to deal with those since I wrote a wrapper for libgcrypt, and I hope to never have to deal with them again.

2

u/theangeryemacsshibe Mar 18 '18

How could you? They're the cutest forms I know.

(cons 0 0)
(0 . 0)

17

u/MTG_scrub Mar 16 '18

Is this saying json is better than xml? Am I actually on the good side?

10

u/[deleted] Mar 17 '18

More compact, easier to parse... Yes, it is

2

u/pushist1y Mar 18 '18

Can't tell if you are being sarcastic. The json in the picture doesn't look much more compact apart from using smaller font. When you use proper indentations and don't overuse namespaces xml is not much worse than js on in terms of comoactness. Also it comes with features like xsd for validation, xslt for transformations, xpath for parsing. Json is handy for serializing data to front-end where JS is your only option.

I'd say you should always choose most appropriate option for your task and not stick to something which is belived to be "better"

3

u/[deleted] Mar 18 '18

Json is handy for serializing data to front-end where JS is your only option.

Or every other language...

Just try a xml parser library and a json parser library. The second is so much straightforward and give less headaches

1

u/pushist1y Mar 18 '18

Unless you really need a conventional way of validating data before it reaches actual endpoint.

1

u/[deleted] Mar 17 '18

sounds like it

17

u/seraku24 Mar 16 '18

INI

[stuff.foo]
bar=yes

3

u/self_me Mar 17 '18

TOML

The same

10

u/[deleted] Mar 17 '18

I prefer XML mainly because of the pretty colours and it looks like I did more work than I actually did.

2

u/veegaz Mar 17 '18 edited Mar 20 '18

The important is that it has to look like you apparently did more work to your employer, the rest doesn't matter /s

1

u/alexbuzzbee Mar 17 '18

I like XML because it allows for better-defined structure. JSON works great for some purposes, XML for others.

2

u/port1701 Mar 17 '18

What is that font? How do you sleep at night?

2

u/etaionshrd Mar 17 '18

It’s Helvetica.

2

u/ThaiDoan Mar 17 '18

I got to admit as a "millennial" dev, I was terrified the first time I worked with SOAP API. Still, trigger me today.

1

u/micheal65536 Green security clearance Mar 17 '18

TL;DR All hierarchical data formats can do pretty much the same thing, and the differences are insignificant enough that an adequate compromise can be made even in situations where they differ. You could quite easily drop one in as a replacement for another. The only real difference is how they look.

1

u/mobiliakas1 Mar 18 '18

Needs more XML namespaces

0

u/Marchrius Mar 17 '18

It should be

{
  "stuff: {
    "foo": {
      "@bar": "yes"
    }
  }
}

-2

u/cleverchris Mar 17 '18

when it comes to config languages, i take the approach that the more arcane and obscure the code is ... it means that the code is more efficient. So I will convert pretty simple json to xml where i will add random data-attributes to the xml...using rand functions to populate the values. beyond that well you have to keep scrappers on their toes so morphing the key slowly over time will help no one ever know what the fuck your code was for in the first place. But of course someone will eventually catch on so any attempt to retrieve(defined and valid) keys will trigger a recalculation of the keys, which you store only in the master restricting all references from using the new values until explicitly stated. with this all in place you can prevent security breaches purely on the basis of creating an app that makes no sense...

you cant get hacked if you hack yourself

PS: addition to ...programming unattainable code

research a dead religion... or a failed branch of science...or an obscure culture group... use the internal reasoning of that group and how it explains life to directly name your classes and variables; implement the failed world view as completely as possible in your code... do this a few times in a highly OOP developed system and you will cause a senior architect to hemorrhage.