NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Zig is everything I want C to be (mrcat.au)
up2isomorphism 2 hours ago [-]
What is the benefit of changing

int main(void) {

to:

pub fn main() !void {

Except making it looks like a "new" language and requires other people spends 15min to get to used to it?

tmtvl 2 hours ago [-]
There are tradeoffs:

Use of the pub keyword means you can tell whether a function is public in the module without needing to look at a separate place for listing exports (like, say, a header file). Though that itself has tradeoffs, so it's hard to say whether one or the other is better.

Use of the fn keyword makes it easy to find function definitions by grepping for it, whereas finding functions in regular C syntax needs semantic awareness.

What I don't understand is the !void at the end of the declaration, if we're meant to be returning an int, surely !int would be the expected syntax (although I would prefer returns int instead).

jiripospisil 1 hours ago [-]
> What I don't understand is the !void at the end of the declaration, if we're meant to be returning an int, surely !int would be the expected syntax (although I would prefer returns int instead).

`!void` means the function can return an error (e.g. return error.BadArgument) but doesn't produce any value itself. In the case of an error in the main function, the process will exit with 1, otherwise 0. The main function can also return a value directly (return type u8 / !u8).

TUSF 58 minutes ago [-]
In Zig, the main function can return either a u8 or void (which always returns 0) or it can return an error union !void, where if you allow an error to bubble up to main, it'll print an error trace and return 1.
jonathrg 2 hours ago [-]
C's function declaration syntax is pretty weird and makes the language harder to parse. Most languages have a function keyword.
c2xlZXB5Cg1 47 minutes ago [-]
I'd go with for loop syntax:

    for (string, 0..) |character, index| {
        _ = character;
        _ = index;
    }
d_tr 1 hours ago [-]
Probably not much, but this is not the only change the language brings.
elteto 1 hours ago [-]
15 minutes… the horror.
lowbloodsugar 18 minutes ago [-]
What's the Zag gonna be?
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 19:03:56 GMT+0000 (Coordinated Universal Time) with Vercel.