Skip to content

Comment on Zig’s Io.Threaded is neatparent

Comments

This is the weirdest basis for comparing a language I've ever seen. Zig is one line as well, `std.debug.print("Hello, world!\n", .{});`, unless you're counting defining main and its brackets as 4 lines, in which case... Rust has that too, Java is 7 lines and C# is 8 lines to import System library and define the Program class as well if you're not using top-level statements / implicit usings.

---

Edit for replies complaining I used debug.print:

Okay, `try std.io.getStdOut().writer().print("Hello, world!\n", .{});`. Still one line, more explicit with chained methods, but that still just goes to show you how arbitrary this metric is -- Zig's standard library makes you be more explicit with one function, but it doesn't make you be as explicit with another one that works essentially the same way but writes to a different stream, ergo this has nothing to do with the language's inherent explicitness but rather comparing the implementation of a single random function.

As the name suggest `std.debug.print` is a short hand for debug printing. In a CLI app for example you should use IO.

(reply to edit)

small typo fix:

instead of `std.io`, it should be `init.io`. `init` is first parameter in `main` function.

std.debug.print is, as its name suggests, for debug output, not for program output.

In Zig, you create a buffered writer for the stdout file handle, write hello world to the buffer, and then flush it. It exposes what's actually happening underneath.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.