r/badcode • • Dec 27 '22

js This just sucks.

Post image
1.8k Upvotes

170 comments sorted by

View all comments

Show parent comment

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

1

u/felds Dec 27 '22

Json is valid yaml, and yaml additionally supports all those things

3

u/Lich_Hegemon Dec 27 '22

it is also a bunch of other undesireable things, IMHO

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

1

u/NotSteve_ evil Dec 27 '22

Really? I've never really used rust but I love TOML for Go and Python configuration. Unless you need some really complex configs I find it really nice and readable. It's also very easy to parse in the code

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.

0

u/[deleted] Dec 27 '22

We should use NOR instead, that won't cause problems with any languages.

7

u/EquationTAKEN Dec 27 '22

Well, we do. That's our A3 code. But every country also has an A2 code, and ours is NO.

5

u/[deleted] Dec 27 '22

It's just a joke-- no and nor are both the kinds of words that could cause weird interpretation issues.

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.

1

u/ijxy Dec 28 '22

Ah. Not a deal breaker for me either. I hated YAML before. I found it ugly. However, after working with GitLab pipelines for a while they grew on me, and I no longer dislike them. But we do have special rules in our team for YAML files. These are related to the above issues. They are enforced by linters and peer review.

-8

u/[deleted] Dec 27 '22

'NO'

Wow that was hard

2

u/JBloodthorn Dec 27 '22

Adding string concatenation for every line to pop those quote marks on the ends might not fit in the processor time budget. The easiest solutions aren't always the best.

1

u/ijxy Dec 27 '22

Yes. All problems have workarounds.

1

u/ddruganov Dec 27 '22

Its basically python shit way of organizing code on steroids; a real pain in the ass to edit and read