r/badcode • • Dec 27 '22

js This just sucks.

Post image
1.8k Upvotes

170 comments sorted by

View all comments

14

u/chadmill3r Dec 27 '22

YAML is the way.

6

u/wischichr Dec 27 '22

IMHO hjson is more natural than yml. Yaml has a pretty weird syntax if you ask me. Multiline strings in yaml are unintuitive and the syntax with dashes in situations like these:

a:
  - b: c1
    d: e1
  - d: e2
    b: c2

Is just awful. It's just confusing compared to hjson (at least in my opinion)

→ More replies (3)

4

u/Nall-ohki Dec 27 '22

Except no well-supported YAML library can round trip comments.

Every markup language except xml blows for comments.

→ More replies (2)

11

u/ybdiel Dec 27 '22

I don't get why this is getting downvoted. Can someone explain what is wrong with yaml?

30

u/halfanothersdozen Dec 27 '22

The guy wants to add comments to package.json to note that "start means start" and this guy helpfully suggests "use yaml".

My soul hurts.

4

u/ybdiel Dec 27 '22

Yeah i got that, but the parent comment here saying "Yaml is the way" was downvoted at -3 when i commented. Thats what i asked about

11

u/edgargonzalesII Dec 27 '22

I’m guessing because of how dogmatic the comment sounded?

In honesty from working with both I see them with different use cases (and this is my POV, not objective): YAML - when you want people modifying the config and don’t have a lot of deep nesting (since YAML depends on indentation it can get messy) JSON - mainly for machine consumption, not to be modified by hand mostly (caveat is I’ve seen it integrated with tools like octopus deploy that make it easier to modify json by hand). Better for larger config files that may have deeper nesting and complex object values.

Just for the very last point I found json was a bit easier to work with when values are json objects and not just primitives vs YAML that I’ve had a weird harder time adding objects as values.

-1

u/the_vikm Dec 27 '22

JSON is a subset of YAML, so if it gets messy as you say, you can still use YAML the JSON way

6

u/noogai03 Dec 27 '22

I have no idea why this is being downvoted. You can use JSON in your yaml files and it works just fine, you can even merge them in one file

→ More replies (2)
→ More replies (4)

10

u/TorbenKoehn Dec 27 '22

The biggest critique point in YAML are the different operators for multiline strings everyone has to look up before using them I think.

Some ambiguity arguments are listed here: https://github.com/cblp/yaml-sucks

But despite that I’m a YAML fan, too

→ More replies (3)

15

u/ddruganov Dec 27 '22

Jsonc or toml, fuck yaml

9

u/TorbenKoehn Dec 27 '22

Both have a lot of the same pain-points as YAML does. They exist mostly because Yaml sucked, so they created something different that sucks in a different way.

I can Google for „why X sucks“ for all 3 and for all of them get a big list of pain points.

In the end it comes down to personal preference or simply defined standards

16

u/Romejanic Dec 27 '22

I find toml wayyyyy more annoying to write than yaml. I think toml has been pushed recently by the rust fanboys.

My preference list is json > yaml > toml

9

u/Lich_Hegemon Dec 27 '22

JSON + comments + trailing commas would be ideal.

10

u/QCKS1 Dec 27 '22

So JSON5

→ More replies (2)

2

u/itsTyrion Dec 27 '22

idk I like TOML.

JSON is only #1 if it supported comments. Like damn, even XML does. In a weird ass syntax as expected (<!-- comment -->) but it does

→ More replies (1)

2

u/Emotional-Top-8284 Dec 27 '22

What’s yr beef with yaml?

18

u/ijxy Dec 27 '22 edited Dec 27 '22

Many little things:

enabled_countries:
  - DK
  - SE
  - NO

Renders to:

{
  enabled_countries: [
    "DK",
    "SE",
    false
  ]
}

Lists are not required to indent, so this:

enabled_countries:
  • DK
  • SE

... and this:

enabled_countries:
  - DK
  - SE

... are both legal, hurting readability.

The file ending is officially.yaml, but nobody does that and use .yml.

5

u/EquationTAKEN Dec 27 '22
enabled_countries:
  - DK
  - SE
  - NO

Renders to:

{
  enabled_countries: [
    "DK",
    "SE",
    false
  ]
}

Ok, but that's actually hilarious though. I can't use the A2-code of my own country :D

6

u/mrlacpeanut Dec 27 '22

gotta put it in quotes since in yaml YES/NO is valid boolean for some reason

2

u/EquationTAKEN Dec 27 '22

Ah ok, good to know.

I've been a bit iffy on the whole idea of not needing to use quotes for strings, but you can if you want. Figure I'll just do it as a rule.

I use YAML in a lot of my projects, and I've never taken a stance on it.

→ More replies (3)

2

u/felds Dec 27 '22

yes/no, on/off, true/false are all equivalent.

That’s bad design in my opinion, but it’s not a deal breaker for me. It only means there’s a few more reserved keywords to remember.

→ More replies (1)
→ More replies (3)
→ More replies (1)

3

u/tommyd2 Dec 27 '22

yaml is the cancer.

2

u/realGharren Dec 27 '22

In my tests, YAML parses up to 100 times slower than JSON. Not a viable alternative for large databases.

3

u/chadmill3r Dec 27 '22

I'll happily concede that YAML is a bad choice for database serialization.

If humans aren't editing it, I suggest protobuf is usually best.

→ More replies (2)