Zig: Documentation: what does optimality mean?

Created on 24 Sep 2017  路  4Comments  路  Source: ziglang/zig

I'm filing this because the docs say:

If you search for something specific in this documentation and do not find it, please file an issue...

The very first line of the docs states that zig is

designed for robustness, optimality, and clarity

but as an outsider, I don't know what optimality means. Is that just talking about performance or does it mean something else? My naive guess would be that it's not just about performance because then you could just say "performance"?

question

All 4 comments

that is an actual word, go ahead and look it up

It's pretty unusual and also not particularly meaningful to see optimal use without specifying some criteria to optimize, unless you're referring to a specific field like "optimality theory", optimization in the OR sense, etc.

Optimal meaning if you tried to improve the code by rewriting it in assembly, you wouldn't be able to do much better. The language doesn't add any unnecessary overhead to your program. "Optimal runtime performance" is a pretty good short explanation.

Why didn't we just say "performance" instead of "optimality"? To me, the two have different connotations. Performance is when you try to make your code faster. Optimality is when your code is as good as it's going to get. With optimal programs, you don't measure performance; you already know the performance is maxed out.

So obviously this "perfect first try" philosophy doesn't work for all problems, but Zig is designed to make it work when it can. Sometimes you need to "optimize" your program after you've written it, and there's nothing a language can do to eliminate all cases of that. But if you've ever considered that you could make something faster by "rewriting it in C" or "in assembly", then Zig is supposed to already be that fast.

The Rust community uses the phrase "zero cost abstraction" quite a bit. That's the kind of thinking the term "optimality" is supposed to evoke.

If a language was designed for "performance", i would expect support for empirical runtime analysis and fine tuning. Zig may want those someday, but it's not a core design principal of the language.

@andrewrk, please chime in with your opinion. And eventually we should update the docs with the conclusion here.

@Kosti1 please be kind to other users. We're all in this together.

Thanks for the report. To me "optimal" means if you think of the best way a program can behave and perform, Zig is well-suited for creating that program. I also agree with everything @thejoshwolfe said.

Here's my proposal for adding to the docs, suggestions welcome:

  • Robust - behavior is correct even for edge cases such as out of memory.
  • Optimal - write programs the best way they can behave and perform.
  • Clear - precisely communicate your intent to the compiler and other programmers. The language imposes a low overhead to reading code.

docs updated

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jayschwa picture jayschwa  路  3Comments

jorangreef picture jorangreef  路  3Comments

jorangreef picture jorangreef  路  3Comments

bheads picture bheads  路  3Comments

dobkeratops picture dobkeratops  路  3Comments