Zig interfaces closely with existing C code, but helps avoid common programming problems and security hazards Conventional wisdom has it that the C/C++ family of languages are a trade-off. All its power and speed comes at the cost of being a potential breeding ground for instabilities and security hazards. (Heartbleed and Shellshock, anyone?) Option No. 1 is to fix the way that C/C++ apps are written, using better tooling or adding safety syntax. Option No. 2 is to ditch C entirely in favor of a new language — Rust, for instance, or the newly proposed Zig. Zig, from developer Andrew Kelley, is intended as a language for systems development “which prioritizes optimality, safety, and readability.” It keeps some connections with the existing culture of C software development, to allow the graceful migration of existing C software, but its ultimate goal is to supplant C. “I am nothing if not ambitious,” Kelley says in his introduction to the language. One of the key changes outlined in Zig is the “maybe type,” a variable with optional null typing. By default, variables cannot be assigned null values, meaning that one of the most common bugaboos that plagues C/C++ programmers is avoided at the compiler level. The preprocessor is another aspect of C that inspires a love/hate relationship. Directives to the C preprocessor have to be supplied in a syntax separate from the code itself. In Zig, however, preprocessor directives are part of the language’s native syntax, so it’s less difficult to reason about the generated code. “It’s one language, not two,” says Kelley. Zig can interface directly with existing C code in both directions. Header files from C projects can be parsed in Zig, and Zig can be used to generate libraries with C ABIs. “You could write part of your application in C and part in Zig, link all the .o [or. DLL] files together and everything plays nicely with each other,” Kelley writes. Because the language is still in a very early, prototype stage, it’s missing features — like generics and macros — found in more heavily developed counterparts like Rust and D. Both features are planned but not yet implemented in Zig. Currently Rust stands as one of the most aggressively developed and better-known languages aimed specifically at systems and native applications. A few of Zig’s ideas seem inspired by Rust, such as avoiding null types. But Zig is aimed slightly to the left of Rust, where people are more inclined to wean themselves off C piece by piece rather than all at once. This goes beyond Zig’s syntax adhering more closely to C; it’s also in Zig’s memory management model, which is highly reminiscent of C. Rust aggressively promotes a different model for handling memory, which requires users to learn new metaphors. Zig still allows for unsafe behaviors, but makes it relatively easy to adopt safer ones. Rust’s biggest advantage right now is in momentum and brand-name recognition. In addition to springing from Mozilla, Rust is building up a vast library of third-party libraries (aka crates) and is starting to appear in actual shipping software (mainly Firefox). Zig is still a prototype with very little to call its own beyond a minimal standard library, but it’s already possible to build running software with the language — such as a simple Tetris clone. Related content news TypeScript 5.7 arrives with improved error reporting Microsoft’s strongly typed JavaScript is now available in a production release, featuring new checks for variables that were never initialized. By Paul Krill Nov 22, 2024 3 mins JavaScript Typescript Programming Languages news JDK 24: The new features in Java 24 24 features are proposed for the next version of Java including a fourth preview of structured concurrency and crypto features designed to secure Java apps against future quantum computing attacks. By Paul Krill Nov 22, 2024 13 mins Java Programming Languages Software Development analysis AWS prepares to command an army of AI agents AWS Labs’ Multi-Agent Orchestrator open source project rethinks distributed computing to make it easier to build sophisticated, efficient, and cost-effective AI systems. By David Linthicum Nov 22, 2024 5 mins Generative AI Cloud Native Artificial Intelligence news Angular 19 bolsters server-side rendering with incremental hydration Now available in a developer preview, incremental hydration allows Angular devs to annotate parts of a template to be loaded lazily on specific triggers. By Paul Krill Nov 21, 2024 3 mins Angular JavaScript Web Development Resources Videos