Interview with Andrew Kelley, creator of Zig

“Zig has all the elegant simplicity of C, minus all the ways to shoot yourself in the foot”

Gabriela Motroc
Zig

C has been around for decades and it’s still the second most popular programming language, according to the TIOBE index. However, if you ask Andrew Kelley, the creator of Zig, he’ll tell you that “anything you can do in C you can do better in Zig.” Why fix C when it’s not broken? In this interview, Andrew will tell you exactly why you should give Zig a chance.

JAXenter: What is the target audience for this new open-source programming language? Why was it designed?

Andrew Kelley: Linux programmers, Windows programmers, MacOS and iOS programmers, Android programmers, web programmers, embedded programmers, operating system programmers, game developers.

It is not for language enthusiasts. It is for people who want to get things done and write robust, high-performing, maintainable software. Zig was designed because other languages make it too difficult to write maintainable, high-performing software that handles every edge case correctly.

SEE ALSO: Tired of C? New programming language Zig aims to be more pragmatic and readable

JAXenter: What is the main difference between Zig and C?

Andrew Kelley: I wrote an article about this. Some of the main differences are:

  • Instead of #include we have @import which is more intelligent than pure text inclusion. Zig has lazy top-level declarations.
  • Zig has generics and compile-time code execution.
  • Most things that are undefined behavior in C are caught in Debug and ReleaseSafe mode in zig. docs
  • Zig ships with a build system (and soon a package manager)

JAXenter: What is its star feature and why? 

Andrew Kelley: I’m going to cheat and name two.

Cross compiling. Zig programs can be built on any machine, for any machine, out of the box. Most of the time you need to painstakingly create a cross compilation toolchain; this is not the case for Zig.

Error handling. Zig has an error type that encourages programmers to handle correctly every little possible thing that could go wrong, with minimal impact on code verbosity. In Zig, the easiest, laziest way to write code is the correct way to write code.

Zig embraces C like the unwanted younger brother who tags along, and you have to make him feel like he’s important, but really your day would just be better off without him.

JAXenter: When should we expect 1.0 to be released?

Andrew Kelley: It depends on how much funding I can get for the project. Right now I’m receiving $103/month on Patreon, which is very much appreciated, but it’s not enough to quit my day job. If I could work full time on Zig, progress would accelerate by a factor of 10.

Working nights and weekends like I’m doing right now, I predict that 1.0.0 will be released in five years.

Note that it took Rust five years to go from initial commit to 1.0.0. But they have a whole team of full-time engineers, and the language is a lot more complicated than Zig.

JAXenter: You said in the intro that “Zig embraces C like the mean older brother who you are a little afraid of but you still want to like you and be your friend.” What do you mean by that?

Andrew Kelley: Looking back on this analogy I think I would make a bolder one: Zig embraces C like the unwanted younger brother who tags along, and you have to make him feel like he’s important, but really your day would just be better off without him.

What’s going on is that Zig is independent from C. We don’t depend on libc, and anything you can do in C you can do better in Zig. However, we recognize that there is so much legacy code in C, we have to be able to use it. And not only that, existing C code has to be able to use Zig code. So Zig supports the C integer types, can translate C code into Zig code, can import .h files directly in the source, and has a built-in way to export functions so that they can be called from C. Building a library with the C ABI is a primary use case of Zig.

In Zig, the easiest, laziest way to write code is the correct way to write code.

JAXenter: What’s the next step for Zig?

Andrew Kelley: The next step is milestone 0.2.0. Some notable issues to solve are:

  • concurrency
  • ability to use zig as a C compiler
  • self-hosting the compiler (note that in Zig’s case this actually solves problems and is not just technical masturbation)
  • figuring out if there will be any kind of virtual function abstraction
  • built-in automatic documentation generation

JAXenter: Why should developers give Zig a try?  

Andrew Kelley: Zig has all the elegant simplicity of C, minus all the ways to shoot yourself in the foot. Zig avoids complicated language issues in order to let developers focus on debugging their application rather than debugging how well they know Zig.

Thank you!

 

If you want to help Andrew work full-time on Zig and increase the productivity of the project, letting him spend more time testing, completing features, and live coding, become a patron today.

Author
Gabriela Motroc
Gabriela Motroc is editor of JAXenter.com and JAX Magazine. Before working at S&S Media she studied International Communication Management at The Hague University of Applied Sciences.

Comments
comments powered by Disqus