DEV Community

Cover image for Testing Vlang, Rust and Zig and more!
Vincenzo
Vincenzo

Posted on

Testing Vlang, Rust and Zig and more!

Been quite bored recently after a bit of a dip in my personal interest in Game dev, so I decided to get on with my list of "Things to do in 2023".

One of them was Finally learn Rust properly, so I did (again).

Rust

I had done a few online courses 2 years ago on Rust.

I had finished this Udemy course, which was a bit too fast towards the end but still enjoyable, I read THE BOOK and done the Rustlings (here are my old solutions and here the new ones).

I did it all over again and fell in love with it, again.

Yet, I wanted to try something different.

I wanted to do a small cli program exercise to solve some problems and find out whether it would be easy to solve simple problems using Rust.

No, it was not and it was annoying and frustrating, again, and once again I decided that even though I love Rust, it just frustrates me more than helps me.

The exercise is this:

User Store Bank

Small exercise for a cli tool.

  • User class
  • Money class
  • Money Math
  • App lifecycle with state
  • Catch Ctrl+C
  • User journey - Login
  • User journey - Logout
  • User journey - Withdraw
  • User journey - Deposit
  • User journey - Change Password
  • User journey - Quit
  • App persistency with JSON file
  • Encrypt password whilst persisted
  • Manage Secrets with env files or similar
  • App persistency with db
  • Admin journey - Create User
  • User Journey - Add Complex money with fractional unit to movements
  • User Journey - Move Money between users

Easy no? well no, especially the CTRL+C bit.
Basically I want that when my app runs, when I intercept SIGINT I save the db, then kill the app.

And nothing easy seems to work (PR here).

The way that crate suggests to handle it is to use messaging between threads rather than share App instance, which will make me want to puke as I need to exit few nested loops.

Apart from this little hurdle (which I simplified in here if you want to try to solve it) I got really annoyed with how much time I spent on petty little things and even though I love the way the code looks, I hate the syntax (especially those lifetimes shenanigans).

So I decided to look for alternatives.

Vlang

V caught my eye straight away, it feels like a go mixed with Rust.
Vlang if you want to look a bit more in depth.

Man it is so small and self contained, the testing framework is easy to use, it has already a package manager vpm and it comes with a HUGE std lib (it even has a multiplatform GUI and an ORM).

This is what that same exercise looks with it.

There are only few little problems.

  1. It is still in alpha so there are not many tutorials around, even though the docs are amazing.

  2. It does not YET compile to binary code, it does transpile to C and then build. But the native code compiler is in the work, still in alpha.

  3. There are different memory management by default is autofree and you can choose different ones but they are all still a bit undocumented.

On this last 2 posts, I got some messages on mastodon about it and had to try it myself.

Tested my silly app with Valgrind and for few minutes run I had around 2 MB of memory leak.

Tweeted about it and I got a response from Vlang People themselves.

Few days later someone used my code to open an issue, investigate and suggest a fix PR.

Which is now merged and working, I updated V and the leak disappeared.

I will definitely go back and explore a bit more and keep following this programming language closely.

Zig

I loved Zig syntax and tutorial with tests straight from the beginning.

The fact that there are no native strings and you have to pass allocators everywhere annoyed the shit out of me and did not even started my project.

GOing back

One thing I said after all of those tests was:

Man vlang is so much like GO, makes me feel like I miss GO

I studied golang few years back, along side Rust, we had to do some microservices at work, and we decided to test both of those to see which one would make the code more readable and easier to maintain.

We went with go, I went back to my repositories with code examples, all of those are still easy to understand and read even though I hadn't touched go in years.

Everyone complains about the Garbage Collector spikes, but our microservice was in production for years and was the most stable one, we never had any issue with it and the code was so nice and easy to read.

I don't know, every programming language has pros and cons, I just feel like the cons on Go to me are not really the GC spikes, but mostly the fact that it is missing a cargo and even though the module system is now way better than it used to be (no more gopath and everything installed there) it is still missing the variety of third party packages that rust has.

Anyhow this is the same exercise with go.

Try to tell me that Rust read better...

Conclusions

There are no conclusions, I still love rust and I wish I loved it more, I think Go is great and Vlang might get interesting when v1 is out.

Zig? Why don't you do strings and basic allocators by default? please!

Top comments (1)

Collapse
 
helpisdev profile image
Καπαρελιώτης Ηλίας (Kapareliotis Ilias)

Oh ny God, I feel you so much on that strings note about Zig. The language is spectacular and it is truly a shame that there isn't builtin-in support for strings/string templating. An absolute stopper for most of my projects. Please Zig team, reconsider builtin strings.