What does Zig mean by "No hidden control flow"?

Hi @videbar, welcome to ziggit :slight_smile:

No hidden control flow means that “what you see is what you get”, there is no operator overloading, no fields that call functions, no destructors, no exceptions.
Example:

{
    auto x = doit();
    stdout << x.foo;
}

x destructor is called on } (you must know that the object that doit returns have a destructor, but the code of the destructor is elsewhere and you don’t know what it calls), << is a shift operator (that does not shift anything but is overridden and used as printf alternative), in x.foo you expect that there are no side effects but foo actually is a block of code that changes variables and then returns something.

In zig defer the enclosed code is executed on }. The code is near its execution point and is visible.

{
    const x = init();
    defer {
        x.deinit();
    }
}

Hope it helped.
A good starting point is:

Since you are seeking for the philosophy of the language, start from the first two links in Zig Learning Resources. (both from Andrew Kelley)

2 Likes