Zig's new I/O: function coloring is inevitable?

https://news.ycombinator.com/rss Hits: 5
Summary

Background Blog post What Color is Your Function? (2015) by Bob Nystrom highlighted problems of async computation handling in programming language design. It has started heated discussions on Hacker News and Reddit. Although many solutions to this problem were suggested, none of them seemed to be a silver bullet. Zig’s new I/O In the Zig Roadmap 2026 stream Andrew Kelley announced a new way of doing I/O, and Loris Cro wrote a Zig’s New Async I/O blog post describing it in more details. This is the example Zig code from that post, that writes data to two files asynchronously: const std = @import("std"); const Io = std.Io; fn saveData(io: Io, data: []const u8) !void { var a_future = io.async(saveFile, .{io, data, "saveA.txt"}); defer a_future.cancel(io) catch {}; var b_future = io.async(saveFile, .{io, data, "saveB.txt"}); defer b_future.cancel(io) catch {}; // We could decide to cancel the current task // and everything would be released correctly. // if (true) return error.Canceled; try a_future.await(io); try b_future.await(io); const out: Io.File = .stdout(); try out.writeAll(io, "save complete"); } fn saveFile(io: Io, data: []const u8, name: []const u8) !void { const file = try Io.Dir.cwd().createFile(io, name, .{}); defer file.close(io); try file.writeAll(io, data); } Loris later claims that this approach to I/O solves function coloring… and I don’t agree. To see why, let’s compare function signatures of red (blocking) and blue (non-blocking) versions of saveData with a few modifications that make my argument a bit more clear: // red fn saveData(data: []const u8) !void fn saveFile(file: std.File, data: []const u8) !void // blue fn saveData(io: Io, data: []const u8) !void fn saveFile(io: Io, file: std.File, data: []const u8) !void And compare it to semantically similar functions in Node.js: // red function saveData(data: Uint8Array): void function saveFile(file: string, data: Uint8Array): void // blue async function saveData(data: Uint8Array): Promise<void> async...

First seen: 2025-07-13 23:57

Last seen: 2025-07-14 03:58