Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am continuously surprised by the amount of work zig committers manage to put out every release. It is actually inspiring. How do they get to appear so productive?

Anyway, here's a nitpick. In this release they've removed varargs, and now this is how a printf call looks like in zig:

    std.debug.warn("{}+{} is {}\n", .{1, 1, 1 + 1});
The ergonomics of typing .{} for every print seems pretty awful if you're a heavy user of debug printing. I was hoping that maybe some sort of a syntax sugar is planned so that tuples could be used without .{} -- emulating varargs, but the bug tracker doesn't turn up anything in that direction.

In the previous release (0.5.0) one didn't need the .{}, but instead integer literals needed explicit casts, because the vararg implementation was limited:

    std.debug.warn("{}+{} is {}\n", i32(1), i32(1), i32(1 + 1));
Both of these options seem like a regression compared to the usual

    printf("%d+%d is %d\n", 1, 1, 1 + 1);
... and there doesn't seem to be a way to work around it by e.g. using a function overloaded in the number of arguments (no such thing in zig) or some preprocessor tricks (again, no such thing).

PS. I'm also surprised to find out that zig seems to take 2.6 seconds to compile the above example.



To be honest typing and remembering %d %f %c %s etc. seems like more hassle than typing {} and typing it for every case.

I think the real gotchas are that { is escaped as {{ and } as }} instead of \{ and \} (though it does follow from the old %%) and you must either include , .{} or rewrite the function call to something significantly different to do unformatted print.


Fwiw, the "{}" formatting is common in python, so that might be a reason they went that route.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: