Programming language experts told Andrew Kelley, the creator of the Zig programming language, that having code which could run at compile time was a r

What Makes the Zig Programming Language Unique?

submited by
Style Pass
2022-10-06 01:30:06

Programming language experts told Andrew Kelley, the creator of the Zig programming language, that having code which could run at compile time was a really dumb idea. But he went ahead and implemented it anyway. Years later, this has proven to be one of the killer features of Zig. In the Zig world, we call it comptime, from the keyword used to mark code required to run at compile time or variables to be known at compile time.

The ability to run Zig code during compilation allows Zig developers to write generic code and do meta programming without having any explicit support for generics or templates.

Erik Explores is a reader-supported publication. To get updates and access full content become a subscriber or read this full article on Medium.

Let me walk you through some code examples to better explain what the whole idea is and why it matters. Consider the following simple function to find the maximum of two values a and b. Without generics or comptimecode, we would need to hardwire such a function to operate on a specific variable types, such as 32-bit integers referred to as i32 in Zig.

Leave a Comment