Is Zig the Long Awaited C Replacement

Is Zig the Long Awaited C Replacement.
Comparison with previous C contenders such as C++, D, Java, C#, Go, Rust and Swift

https://erik-engheim.medium.com/is-zig-the-long-awaited-c-replacement-c8eeace1e692

This thread was posted by one of our members via one of our automated news source trackers.

3 Likes

Corresponding tweet for this thread:

Share link for this tweet.

1 Like

I like this article - lots of praise for languages like Julia, Go, Rust, Swift and also mentions V - which I hadn’t heard of before.

Where Zig Fits in the Programming Landscape?

So Swift never really worked out as my ultimate all purpose programming language. If I want to program at a higher abstraction level, get high performance and get stuff done I will go with Julia.

But that still leaves an unfilled space for a C like alternative. Julia cannot really replace C. It gobbles memory, cannot produce small binaries, isn’t that suitable for making libraries other languages can use. You would not want to use it to create an OS kernel or do microcontroller programming.

Both Go and Rust got really close to being a replacement of C. Go pulled off the getting the simplicity and a lot of the feeling of using C. But it uses garbage collection which doesn’t make it fully C replacement. It is worth nothing that you still have more control over memory usage in Go than in Java, since you got pointers and can actually create your own secondary allocators.

Rust got the manual memory allocation bit down, but failed in replicating the simplicity and feel of C. Is there perhaps something that fills the space between these two languages?

Indeed there is. That is exactly what I think Zig is. Zig is more complex than Go, but much simpler than Rust to learn and use.

But such a summary of Zig does not do the language justice. Zig brings a lot of new ideas to table which makes a lot of sense and which makes the experiencing of coding Zig quite unique. But before diving into that let us look at the basics.

And where V is mentioned:

Getting the Basics Right

If we are to pick up another C like language we cannot repeat the worst of C++ such as atrocious compilation times. How does Zig stack up?

I came across this test by Alexander Medvednikov, the creator of the V programming language. This is a test of compiling a file with a 400 K function:

  • C 5.2s gcc test.c
  • C++ 1m 25s g++ test.cpp
  • Zig 10.1s zig build-exe test.zig
  • Nim 45s nim c test.nim
  • Rust Stopped after 30 minutes rustc test.rs
  • Swift Stopped after 30 minutes swiftc test.swift
  • D Segfault after 6 minutes dmd test.d
  • V 0.6s v test.v

Rust, Swift and D all fail at this. Medvednikov does further tests of these languages with fewer lines, where again Rust does worst as expected.

As you can see in the list, Zig is among the star performers. Although it is hard to not notice that the V language does it all in less than a second. Which reminds me to explore V, in more detail. A quick scan suggests it is sort of Go with manual memory allocation, generics and optionals (null pointer must be explicitly allowed).

It’s a really good article well worth a read :+1: