this post was submitted on 13 Nov 2023
92 points (81.9% liked)

Programmer Humor

19555 readers
1346 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 

And I'll show you YAML

(a continuation of this post)

top 50 comments
sorted by: hot top controversial new old
[–] suy@programming.dev 53 points 1 year ago (1 children)
[–] magic_lobster_party@kbin.social 51 points 1 year ago (2 children)

JSON for serialization all the way. It’s simple and to the point. It does one thing and does it well. There’s little room for annoying surprises. Any JSON can easily be minified and prettified back and forth. If you want it in binary format you can convert it to BSON.

Yaml is too much of a feature creep. It tries to do way too many things at the same time. There are so many traps to fall into if you’re not cautious enough. The same thing can be written in multitudes of ways.

[–] jjjalljs@ttrpg.network 28 points 1 year ago* (last edited 1 year ago) (6 children)

Yes, but whoever decided that json can't have trailing commas has my ire.

{ "a": 1,
  "b": 2,  <-- nope
}

There was some other pitfall I can't remember around missing keys and undefined, too, but I can't remember it now.

[–] OmnipotentEntity@beehaw.org 11 points 1 year ago (1 children)

Change to Haskell formatted commas and the problem goes away :D

{ "a": 1
, "b": 2
, "c":
    [ 3
    , 6
    , 9
    ]
}
[–] ursakhiin@beehaw.org 29 points 1 year ago

Where is the nearest fire to dump this comment in?

[–] adambowles@feddit.uk 8 points 1 year ago

Trailing commas are supported in json5, as well as comments

load more comments (4 replies)
[–] kool_newt@lemm.ee 2 points 1 year ago (1 children)

There should be a "Simple YAML" that is just scalars, lists, and dicts.

[–] interolivary@beehaw.org 43 points 1 year ago* (last edited 1 year ago) (2 children)

There's a special place in hell for the inventor of semantically significant whitespace.

YAML itself is one of the circles of hell. You have to copy-paste YAML from web etc sources with dubious formatting for all eternity, and the editor doesn't have YAML support. Also you can only use Python

[–] magic_lobster_party@kbin.social 12 points 1 year ago* (last edited 1 year ago) (1 children)

Indenting copy pasted yaml is always a pain in the butt. Any indentation you give is likely a valid yaml. Especially bad considering indentation has a significant meaning. You have to double check back and forth to ensure nothing bad has sneaked in.

With JSON there are no such discrepancies. It’s likely the editor has figured it out for you already. If it hasn’t it’s easy to prettify the JSON yourself.

[–] interolivary@beehaw.org 4 points 1 year ago

Semantic whitespace problems can easily be literally impossible to solve automatically. One of the dumbest fucking ideas anybody ever came up with in computing and its inventor if anyone belongs in YAML Hell. As a fuckup it's not quite as bad as null, but that ain't exactly a high bar

[–] synae@lemmy.sdf.org 3 points 1 year ago (1 children)

Sounds like a good time to me!

[–] interolivary@beehaw.org 3 points 1 year ago (1 children)

I'm not sure which thought is scarier: that you don't know what you're signing up for, or that you do know and you enjoy fixing undecidable formatting fuckups manually

[–] synae@lemmy.sdf.org 2 points 1 year ago

There's a bonus third option: I started writing python professionally in 2007 and nowadays spend 75% of my "hands on keyboard" time working on kubernetes YAML and I am indeed having a good time.

I admit, I hastily misread the tail end of your comment as (e.g.) "A reason YAML is bad because you have to copy-paste from the web and that sucks"; not as you probably meant it "in this special hell, you must deal with copy-pasted nbsp and other trash". So maybe I did not know exactly what I was signing up for ;)

I don't deal with anything like that and not entirely sure how it happens to people enough that it is a common complaint. "undecidable formatting fuckups" are a non-issue in my life, I really don't understand how people encounter such things. Maybe they need to fix their editor/IDE/tools? Skill issue? IDK.

As a tangent- I don't care what language code is written in, it had better be indented properly (and linted, and follow the project's codestyle, ...). Our juniors learn pretty early that their change requests will be blocked on formatting alone by CI, and a human won't even bother reviewing the substance of their change if they don't follow convention. I don't hear them ever complaining about any of these things, least of all semantic whitespace ... and we have a rich culture of bitching about menial/pedantic things ;)

[–] calcopiritus@lemmy.world 36 points 1 year ago (4 children)

Serializing? For serializing you probably want performance above all else. I'm saying this without checking any benchmark, but I'm sure yaml is more expensive to parse than other formats where indentation don't have meaning.

For human readability: it has to be readable (and writeable) by all humans. I know (a lot of people) that dislike yaml, toml and XML. I don't know of a single person that struggles to read/write json, there is a clear winner.

[–] DrM@feddit.de 15 points 1 year ago (3 children)

JSON would be perfect if it allowed for comments. But it doesn't and that alone is enough for me to prefer YAML over JSON. Yes, JSON is understandable without any learning curve, but having a learning curve is not always bad. YAML provides a major benefit that is worth the learning curve and doesn't have the issues that XML has (which is that there is no way to understand an XML without also having the XSD for it)

[–] Michal@programming.dev 24 points 1 year ago (1 children)

Json should also allow for trailing commas. There's no reason for it not too. It's annoying having to maintain commas.

[–] DerArzt@lemmy.world 4 points 1 year ago (1 children)

And also a standard date time type!

[–] dfyx@lemmy.helios42.de 5 points 1 year ago (1 children)

What is wrong with ISO 6801 strings?

[–] intensely_human@lemm.ee 3 points 1 year ago (1 children)

11-2023-14

I dunno it just kinda looks weird to me

[–] Hexarei@programming.dev 2 points 1 year ago (1 children)

Dunno what format you've got there, but ISO 6801 looks like 2023-11-15T18:28:31Z

[–] her01n@lemmy.world 3 points 1 year ago (1 children)

It's a joke, because the standard is 8601, not 6801.

[–] Hexarei@programming.dev 2 points 1 year ago

Oh. Egg on my face then lmao I didn't even notice

[–] kogasa@programming.dev 2 points 1 year ago (2 children)

If a comment isn't part of the semantic content of a JSON object it has no business being there. JSON models data, it's not markup language for writing config files.

You can use comments in JSON schema (in a standardized way) when they are semantically relevant: https://json-schema.org/understanding-json-schema/reference/comments

For the data interchange format, comments aren't part of the JSON grammar but the option to parse non-JSON values is left open to the implementation. Many implementations do detect (and ignore) comments indicated by e.g. # or //.

load more comments (2 replies)
[–] frezik@midwest.social 2 points 1 year ago* (last edited 1 year ago)

JSON5 has comments, among fixing a few other shortsighted limitations of the original.

[–] kool_newt@lemm.ee 14 points 1 year ago

I don’t know of a single person that struggles to read/write json, there is a clear winner.

Really? Any JSON over 80 chars becomes a nightmare to read for me, especially if indention is not used to make it more readable.

load more comments (2 replies)
[–] NewPerspective@lemmy.world 35 points 1 year ago (1 children)

My problem with yaml is if you truncate it at any random spot, there's a high likelihood it's still valid yaml. I don't like the idea that things can continue without even knowing there's a problem. The single opening and closing curly braces enclosing a json object is all it takes to at least know you didn't receive the entire message. Toml has the same issue. I'll stick with json when it makes sense.

[–] pimeys@lemmy.nauk.io 8 points 1 year ago (1 children)

Add a schema to it and you get XML. The ultimate serialization format.

[–] marcos@lemmy.world 13 points 1 year ago

Quite like YAML, XML has too many stuff in it. While a lot of parsers are not standard compliant and safe, if there's any chance the stuff you include on your code can evolve into a fully featured parser, including it is something to avoid.

There is this language called KDL that looks interesting.

[–] synae@lemmy.sdf.org 23 points 1 year ago (1 children)

For serializing? I'd probably just go with json.

For content meant to be written or edited by humans? YAML all day baby

[–] Andy@programming.dev 5 points 1 year ago (1 children)

Ever tried NestedText? It's like basic YAML but everything is a string (types are up to the code that ingests it), and you never ever need to escape a character.

[–] synae@lemmy.sdf.org 9 points 1 year ago (1 children)

I've got too many consumers that I don't control which dictate their input formats. And to be quite honest, "types are up to the code that ingests it" sounds like a huge negative to me.

[–] Andy@programming.dev 3 points 1 year ago

Ah, well I love that policy (types being in code, not configs). FWIW I sometimes use it as a hand-edited document, with a small type-specifying file, to generate json/yaml/toml for other programs to load.

[–] MagnoliaMayhem@programming.dev 17 points 1 year ago (1 children)
[–] theterrasque@infosec.pub 10 points 1 year ago (1 children)

puts the json in the yaml parser

Your move, foolish mortal

[–] derpgon@programming.dev 6 points 1 year ago

For those uninitiated, every JSON is a valid YAML, since YAML is just a superset of JSON.

[–] colourlessidea@feddit.de 15 points 1 year ago (2 children)

YAML is pretty good for readability, pretty awful for writability

[–] synae@lemmy.sdf.org 10 points 1 year ago

Interesting, I find that the other reasonable options are far less writable than yaml

[–] NewPerspective@lemmy.world 5 points 1 year ago (1 children)

Rule of thumb: valid json is valid yaml. If you're ever unsure, do it the old fashioned way.

[–] intensely_human@lemm.ee 1 points 1 year ago (1 children)

I really don’t see how that’s true.

You’re telling me this is valid yaml?

{ firstName: “Intensely” }

How is that yaml?

load more comments (1 replies)
[–] nxdefiant@startrek.website 9 points 1 year ago

If you have a choice to start from scratch, TOML is probably the better option.

[–] urquell@lemm.ee 8 points 1 year ago

So much json here. All wrong, it's csv

[–] Artyom@lemm.ee 6 points 1 year ago* (last edited 1 year ago)

Yaml is a great, human-readible file format. Unless there's an exclamation point in it, then it is an illegible Eldrich horror.

[–] Windex007@lemmy.world 5 points 1 year ago

Genuinely curious what features OP is looking for, specifically for serialization as per the post, that has resulted in the conclusion being yaml.

[–] kool_newt@lemm.ee 3 points 1 year ago (1 children)
[–] onlinepersona@programming.dev 5 points 1 year ago (1 children)
[–] kool_newt@lemm.ee 4 points 1 year ago (1 children)

What, you can't read binary? Noob

lol, ya I guess I didn't notice that part

load more comments (1 replies)
load more comments
view more: next ›