Testing Vlang, Rust and Zig and more!
Tags: vlang, zig, rust, learning
Published: 2023-04-29 19:07:58

---
title: Testing Vlang, Rust and Zig and more!
published: true
description: I have been learning new programming languages
tags: vlang, zig, rust, learning
cover_image: https://pbs.twimg.com/media/Ft3Ha-yXoAImD9S?format=png
# Use a ratio of 100:42 for best results.
# published_at: 2023-04-29 11:06 +0000
---

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](https://www.rust-lang.org/).

I had finished [this](https://www.udemy.com/course/ultimate-rust-crash-course/) Udemy course, which was a bit too fast towards the end but still enjoyable, I read [THE BOOK](https://doc.rust-lang.org/book/) and done the [Rustlings](https://github.com/rust-lang/rustlings) ([here](https://github.com/vikkio88/my_rustlings_solutions) are my old solutions and [here](https://github.com/vikkio88/my_rustlings_solutions/tree/v2023_update) 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](https://github.com/vikkio88/rustLearning/pull/1)).

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](https://gist.github.com/vikkio88/ce94e6ba4b907f1d33f3a345964314ee) 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](https://vlang.io/) 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](https://vpm.vlang.io/) and it comes with a HUGE std lib (it even has a multiplatform GUI and an ORM).

[This](https://github.com/vikkio88/vlang_learn/blob/main/user_store_exercise/src/main.v) 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](https://github.com/vlang/v/blob/master/doc/docs.md) 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](https://mastodon.gamedev.place/@profan/110210923119320543) about it and had to try it myself.

Tested my silly app with [Valgrind](https://valgrind.org/) and for few minutes run I had around 2 MB of memory leak.

Tweeted about [it](https://twitter.com/vikkio88/status/1649029396429172743) and I got a [response](https://twitter.com/v_language/status/1649168381432537088) from Vlang People themselves.

Few days later someone used my code to [open an issue](https://twitter.com/yanas_ral/status/1649357730958782464), investigate and suggest a [fix PR](https://github.com/vlang/v/pull/18022/files).

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](https://ziglearn.org/chapter-1/).

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](https://go.dev/) 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](https://github.com/golang/go/issues/14812), 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](https://vsupalov.com/switch-to-go-modules/)) it is still missing the variety of third party packages that `rust` has.

Anyhow [this](https://github.com/vikkio88/go_learn/tree/main/user_go) 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!