AI 摘要The author, while developing a 4-player arcade game for the Raspberry Pi 3 to test Zig's suitability for OS and embedded development, implemented bit-fields in the Zig language to support USB controller drivers, avoiding the pitfalls of C's implementation-defined and poorly regarded bit-field syntax. Zig achieves this with no syntax additions by combining packed structs (where fields occupy exact memory layout with no padding) with arbitrary bit-width integer types created via the @intType builtin. Unlike C, Zig allows taking addresses of bit-fields, with the bit offset and length encoded in the pointer type so the compiler can catch misuse.
AI 摘要The author, who believes in lowering barriers to creating rich interactive experiences and improving programming usability, has written an article for Smashing Magazine. The article targets JavaScript library developers who want their libraries to be usable directly through HTML without requiring users to write JavaScript. Interested readers are directed to the article for more information.
AI 摘要The article translates tricky code examples from a 2015 post titled 'I Do Not Know C' into Zig, showing that Zig catches many of C's pitfalls—such as variable redefinition, misuse of nullable pointers, integer overflow, and ambiguous division—either at compile time or through runtime safety checks that crash with a traceback in debug mode. It highlights that Zig's operators make behavior explicit, with '+' asserting no overflow, '+%' providing wraparound, and division requiring an explicit choice between truncating, flooring, or exact semantics. The author concludes that Zig is on track to replace C as the simple, straightforward language for writing systems code.
AI 摘要The author needed a simple tool to compare the loading progression of two websites side by side, and after finding that tools suggested on Twitter were too complicated and unlikely to work with local URLs, they quickly built Duoload themselves. The minimalist tool's small codebase is available on GitHub, though the author cautions it is somewhat inaccurate and not suitable for mission-critical performance comparisons. The name 'Duoload' was coined by Chris Lilley.
AI 摘要The article explains how the Zig programming language centers on whether an expression is known at compile-time, introducing comptime parameters (used to implement generics via compile-time duck typing, similar to C++ templates), comptime variables, and comptime expressions. These features let the same function be evaluated at both compile-time and run-time without modification, enabling compile-time code execution like implicitly inlined if and loop constructs, complex static data initialization, and catching errors such as undefined behavior or infinite recursion during compilation. The compiler enforces limits on compile-time evaluation (such as a 1000 backward branch quota adjustable via @setEvalBranchQuota), and this approach provides expressiveness that in other languages requires macros, code generation, or preprocessors.
AI 摘要The article addresses the challenge of defining a 'handshake' protocol between two traits, Alpha and Omega, so that any type implementing Alpha can be composed with any type implementing Omega. For instance, if Foo and Bar are Alphas and Baz and Quux are Omegas, each Alpha should work with each Omega. The author emphasizes that achieving this kind of cross-trait composability is not a trivial problem.
AI 摘要The author rewrote the Zig compiler to insert an intermediate representation stage, which caused a Tetris game used for testing to break visually. By comparing OpenGL traces with apitrace, they traced the bug to how the compiler emitted compile-time constant arrays, where a pointer to the array's first element did not reference the data contiguously. They fixed the issue by updating constant arrays to refer to their parent data structures, added a test case, and got the game working again.
AI 摘要The author observes that discussions among language designers and implementers, including those about Go, are rarely dogmatic because they remember weighing good arguments on both sides of each decision. In contrast, language users sometimes argue zealously as if design choices were infallible, likely because they lack that experience of evaluating trade-offs. He urges the Go community to explain engineering reasons fairly—including the case for alternatives—and to avoid argument by authority, since no decision in Go is wisdom received on stone tablets.
AI 摘要The author tweeted about an idea concerning Rust's module system, which sparked a spirited discussion about the system's pain points, including debate over whether such pain points exist at all. The author notes that the full Twitter discussion may be difficult to read depending on how well one can navigate Twitter's UI.
AI 摘要The article explores how to resolve a JavaScript Promise from outside its constructor, which is normally impossible for architectural (throw safety) reasons. The author experiments with approaches like getter/setter tricks before settling on a simple, reusable defer() function that attaches resolve() and reject() methods directly onto the Promise object, allowing external code to resolve it cleanly.
AI 摘要The author, a big fan of GitHub Pages for static hosting, wanted clean custom URLs (like play.csssecrets.io/pie-animated) for a book companion site without using server-side code. They discovered that GitHub Pages serves a custom 404.html for any nonexistent URL, so they used vanilla JavaScript in that file to read the requested path, look up the slug in a JSON mapping file, and redirect to the correct destination (such as a dabblet demo). The author notes this client-side URL rewriting hack could enable proper URLs for single-page sites and many other uses.