This is a live session from the Low-Level Programming Workbench.
Today's focus is: refactoring the Zig codebase of my version of `wc` command.
The goal of the stream is explratory, and you might expect detours. I'm learning in public, and may change direction.
📖 References
Build your own wc: https://codingchallenges.fyi/challeng...
Repository of the project: https://github.com/sourcery-zone/toolbox
📓 Notes
Parsing Arguments in Zig: https://sourcery.zone/articles/2025/1...
Printing a file's byte count in Zig: https://sourcery.zone/articles/2025/1...
Printing a file's character count in Zig: https://sourcery.zone/articles/2025/1...
Re-thinking wc encoding support: https://sourcery.zone/articles/2025/1...
💬 Reach out and Chat
Matrix: https://matrix.to/#/#sourcery-zone:matrix.org
🎬 Timestamps
00:00:00 Stream Warm Up
00:01:43 Welcome and workbench intro
00:02:18 What “workbench” means; no delivery promises
00:02:54 Goal of the session; refactoring `wc` in Zig
00:03:16 Problems with current design and character counting
00:03:57 Rethinking state and structure (less OOP)
00:05:30 Deciding to code first and refactor live
00:06:05 Thoughts on subcommands and CLI structure
00:07:35 Initial refactor; counters and state setup
00:10:05 Initialization questions and file handling
00:11:25 Argument parsing and class responsibilities
00:13:13 Refactoring argument parsing into a single unit
00:15:02 Simplifying parameters and return values
00:16:09 Allocators and memory ownership discussion
00:17:47 Zig syntax struggles and struct initialization
00:20:37 Parsing arguments and handling errors
00:23:20 Maintenance concerns and API shape
00:27:19 Debugging return types and error unions
00:31:39 String types and byte slices in Zig
00:34:22 Error handling and compiler feedback
00:37:26 Macro ideas and enum extraction
00:40:44 Making file input optional and compiling
00:41:44 Verifying parsed arguments output
00:44:26 Switching focus to file reading strategy
00:45:12 Introducing memory-mapped IO (mmap)
00:46:54 Researching mmap examples and platform limits
00:49:38 Implementing mmap in Zig step by step
00:52:13 Understanding mmap arguments and flags
00:57:08 Successfully reading file via mmap
01:01:31 Deep dive into mmap parameters and page alignment
01:05:42 Memory protection and mapping types explained
01:08:23 Final understanding of mmap usage
01:08:42 Wrap-up; why mmap fixes Unicode chunking issues
01:10:01 Outro and next steps
#zig #ziglang #zigtutorial #ziglivecoding #systemsprogramming #wc #coreutils #codinglivestream #learnzig #clitools #unixcommands