CommunityNews

CommunityNews

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.

4 1935 1

First Post!

AstonJ

AstonJ

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:

Where Next?

Popular Backend topics Top

dimitarvp
Apparently he decided to live-stream how he’s going to create a semver library.
12 1173 5
New
tomekzawada
Greetings from Membrane Framework team! Check out our case study based on our latest projects at Software Mansion. https://blog.swmansi...
7 1069 1
New
New
DevotionGeo
There are 3 main formatters for Erlang which you can use from the command-line, rebar3_format, Steamroller elmfmt. Visual Studio Cod...
10 2148 3
New
New
First poster: bot
Rails Best Practices I. Today I share some of my favorite practices applicable to Ruby on Rails (and to web development on small teams g...
0 1086 0
New
First poster: bot
Over the last few years, due in large part to the hype surrounding blockchain and cryptocurrencies, decentralized applications have gaine...
0 1700 0
New
New
elbrujohalcon
A long time ago, I wrote an article about The Asymmetry of ++, thanks to Fede Bergero’s findings. Let’s add a few more asymmetries to th...
17 1284 5
New
tonyxrandall
As DoorDash transitioned from Python monolith to Kotlin microservices, our engineering team was presented with a lot of opportunities to ...
5 2831 1
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
201 4638 102
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
30 3963 10
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
14 7927 8
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
14 6073 7
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
200 3586 78
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
3 3675 3
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
91 5152 43
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
87 6021 49
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
8 3528 3
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
0 1782 0
New