Why Zig When There is C++, D, and Rust?
ziglang.org·2d·
Discuss: Hacker News
💧Liquid Types
Preview
Report Post

← Back to Learn

No hidden control flow

If Zig code doesn’t look like it’s jumping away to call a function, then it isn’t. This means you can be sure that the following code calls only foo() and then bar(), and this is guaranteed without needing to know the types of anything:

var a = b + c.d;
foo();
bar();

Examples of hidden control flow:

  • D has @property functions, which are methods that you call with what looks like field access, so in the above example, c.d might call a function.
  • C++, D, and Rust have operator overloading, so the + operator might call a function.
  • C++, D, and Go have throw/catch exceptions (sometimes also called panic/recover), so foo() might throw an exception, and prevent bar() from being calle…

Similar Posts

Loading similar posts...