I feel that Yaml sucks. I understand the need for such markup language but I think it sucks. Somehow it’s clunky to use. Can you explain why?

82 points

Any language in which whitespace has syntactic value is intrinsically flawed.

Can’t speak to your specific issues, but that’s why yaml will always suck.

permalink
report
reply
1 point

It’s the only time that tabs Vs spaces really riles me up. So annoying when everyone has different tab lengths

permalink
report
parent
reply
25 points

As a serialization format, agree 100%, but would Python really be better if it switched to braces?

permalink
report
parent
reply
28 points

Yes it would - look at optional braces for short if expressions in C family languages and why it’s so discouraged in large projects. Terminating characters are absolutely worth the cost of an extra LoC

permalink
report
parent
reply
4 points

I’m fine with python, because it’s consistent. In C I get nervous every time I see it.

obligatory goto fail;

permalink
report
parent
reply
15 points

I started in C before moving on to C++, Java, Ruby and Python.

I’ve had more bugs from missing braces than from misaligned whitespace because the latter is far more obvious when looking at a block of code.

permalink
report
parent
reply
7 points
*

False dichotomy. Optional braces are bad practice because they mislead the programmer that is adding an additional clause to the block.

This misleading behavior wouldn’t happen in Python, as it would either be invalid syntax, or it would be part of the block.

Indentation problems are pretty obvious to the reader. Even more than missing or unbalanced braces.

permalink
report
parent
reply
61 points

Yes, I think so. The downside with Python comes when refactoring the code. There’s always this double checking if the code is correctly indented after the refactor. Sometimes small mistakes creep in.

It’s really hard to tell when Python code is incorrectly indented. It’s often still valid Python code, but you can’t tell if it’s wrong unless you know the intention of the code.

In order languages it’s always obvious when code is incorrectly indented. There’s no ambiguity.

permalink
report
parent
reply
6 points

It’s only hard to tell indentation in Python when the code block gets longer than about a screen, which is usually a sign the code should be refactored into smaller methods.

permalink
report
parent
reply
1 point
*

Can address it by writing code that doesn’t depend much on indentation, which also makes code more linear and easier to follow.

permalink
report
parent
reply
13 points

I think this is just familiarity. I never have issues with indentation, but when refactoring js I’m always like hey who’s fucking brace is this

permalink
report
parent
reply
5 points

To be pendantic, it’s level of indentation in Python that has semantic meaning, not whitespace.

permalink
report
parent
reply
13 points

The end of line also has semantic meaning. Both indentation and eol are whitespace.

permalink
report
parent
reply
16 points
*

would Python really be better if it switched to braces?

Yes. A thousand times, yes.

permalink
report
parent
reply
2 points

If nothing else it enforces readable code which I think is a good thing.

permalink
report
parent
reply
-1 points

I now use Scala 3, and very happy with syntactic whitespace (combined with an intelligent compiler)

permalink
report
parent
reply
6 points
*

YAML sucks because, among other things, indenting it is not obvious.

In contrast, the only mistake of Python when it comes to whitespaces was allowing hard tabs, which makes it too easy to mix them if your editor is not configured.

Improper indentation stands out more than missing or unbalanced braces and it’s really not an issue to delimit code blocks.

permalink
report
parent
reply
8 points
Deleted by creator
permalink
report
parent
reply
1 point

In any modern editor it is configurable with spaces too

permalink
report
parent
reply
7 points
*

Haskell supports both semantic whitespace and explicit delimiters, and somehow almost everybody that uses the language disagrees with you.

But anyway, for all the problems of YAML, this one isn’t even relevant enough to point out. Even if you agree it’s a problem. (And I agree that the YAML semantic whitespace is horrible.) If YAML was a much better language, it would be worth arguing whether semantic whitespace breaks it or not.

permalink
report
parent
reply
0 points

Yeah but Haskell is mostly used by mathematicians…

permalink
report
parent
reply
2 points

Not any language. I code professionally in F# which has semantic whitespace and it has literally never been an issue for me or my team. In contrast to Python, it’s a compiled language and the compiler is quite strict, so that probably helps.

permalink
report
parent
reply
34 points

Because people over use it. YAML is pretty good for short config files that need to be human readable but it falls apart with complex multi line strings and escaping.

I think there are much better clearly delimited for machine reading purposes formats out there that you should prefer if you’re writing a really heavy config file and, tbh, I think for everything else .ini is probably “good enough”.

permalink
report
reply
13 points
*

I agree - YAML is not suitable for complex cases that people use it in, like Terraform and Home Assistant. My pet peeve is a YAML config in a situation that really calls for more abstraction, like functions and variables. I’d like to see more use of the class of configuration languages that support that stuff, like Dhall, Cue, and Nickel.

There is another gotcha which is that YAML has more room for ambiguity than, say, JSON. YAML has a lot of ways to say true and false, and it’s implicit quoting is a bit complex. So some values that you expect to be strings might be interpreted as something els.

permalink
report
parent
reply
5 points
*

For those highly complex situations is Lua still viewed as the ideal solution? Lua is sort of legendary for game configuration and seems to strike a good expressiveness/accessibility balance for modders and the casually technical.

permalink
report
parent
reply
1 point

I think it depends. Lua is great for scripting - like when X happens do Y. I agree that makes sense for a case like Home Assistant. Sometimes you really want the result to be a data structure, not an interactive program, in which case I think more sophisticated configuration (as opposed to scripting) languages might be better.

permalink
report
parent
reply
3 points

What YAML does Terraform use? HCL is similar but different enough to YAML.

permalink
report
parent
reply
4 points

Oh, thanks for calling that out. I think I may have mixed up some of the frustrations I experienced at an old job.

permalink
report
parent
reply
28 points

At least use TOML if you like ini, there is no ini spec but TOML can look quite similar.

permalink
report
parent
reply
10 points

Strong agree. It’s also the absolute best at expressing really long documents of configuration/data.

permalink
report
parent
reply
2 points

Yes, they could’ve just used JSON. Totally pointless waste of time.

permalink
report
reply
5 points

So Poe’s Law and all that… I really hope you’re being sarcastic because having non-technical people hand edit JSON is a nightmare. It’s also quite annoying to read without a lot of extra whitespace which most editors that’d help less technical folks omit… and comments to help highlight what different things mean are hacky, hard to read, and actually read as data.

permalink
report
parent
reply
1 point

No, I’m kind of serious, the comment situation is already solved in JSON… about the rest yeah, Yaml might be easier but the different isn’t that much. Non tech people can’t edit Yaml properly either so.

permalink
report
parent
reply
13 points

JSON does lack comments. And numbers that are not 64 floats.

permalink
report
parent
reply
7 points

TFB, the numbers are not defined as 64 bits floats.

They are just not defined. At all.

permalink
report
parent
reply
1 point

Exactly that’s a job for the parser / consumer.

permalink
report
parent
reply
5 points

Readability in general sucks

permalink
report
parent
reply
4 points

There’s a spec for json with comments. It’s better than yaml in every way.

permalink
report
parent
reply
1 point

And lack of trailing comma’s

permalink
report
parent
reply
1 point
*

There’s a lot of JSON parsers that don’t mind to see comments there, just ignore them. And there’s also the “_comment” / “$comment” thing.

permalink
report
parent
reply
11 points

I don’t hate YAML, but it has the same issues languages like PHP and JS introduce…there are unexpected corner cases that only exist because the designer wanted the language to be “friendly”

https://www.bram.us/2022/01/11/yaml-the-norway-problem/

permalink
report
reply
3 points

Sorry, what’s confusing the fact that "Hi my name is {$this->name}" works and "Hi my name is {self::name}" is unintelligible gibberish! /s

permalink
report
parent
reply

It sucks the same way Python sucks. Some people just really don’t like indentation-based syntax. I’m one of them, so I dislike both formats. However, if you groove on that sort of thing, I don’t think YAML is any worse than any other markup.

Oddly, I get along with Haskell, which also used indentation for scoping/delimiting; I can’t explain that, except that, somehow, indentation-based syntax seems to fit better with functional languages. But I have no clear argument about why; it’s just an oddity in my aesthetics.

permalink
report
reply
11 points
*

You can’t say python’s whitespace usage is as bad as yaml’s. YAML mixes 2 and 4 spaces all the time. Python scripts don’t run if you write this kind of crap.

And whitespaces is really just the tip of the iceberg of YAML problems…

permalink
report
parent
reply

YAML mixes 2 and 4 spaces

I think that’s a user thing and it doesn’t happen if you have a linter enforce 2 or 4.

permalink
report
parent
reply
8 points
*

That’s part of the problem. Different number of whitespaces indicate different nesting levels and the YAML spec does not enforce them. These two horrible YAMLs are valid and are not equivalent:

a:
 b:
     - c
     -  d
      - e
f:
    "ghi"
a:
 b:
     - c
     - d
     -  e
f:
    "ghi"
permalink
report
parent
reply
2 points
*

YAML mixes 2 and 4 spaces all the time. Python scripts don’t run if you write this kind of crap.

Sure it does. You only need to be consistent within a block. Python’s syntax is ridiculous and solves problems that basically don’t exist.

All of my java/kotlin/rust/etc. code is trivially well formatted and can be done by my editor. Moving code blocks is trivial. Refactoring is easier when I didn’t need to hand -format the code just to make it work.

permalink
report
parent
reply
1 point
*
Deleted by creator
permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 2.2K

    Monthly active users

  • 1.8K

    Posts

  • 29K

    Comments