Shubham Kumar Software artist and internet cowboy!

Vlang vs. Rust: Comparing build languages

3 min read 1102

Vlang v Rust

Introduction

Vlang or Rust? How are they different from each other? How do they compare in their performance, memory management, compilation speed, and other important functionalities?

In this article, we will explore the answers to all of these questions as we compare Vlang (referred to as “V”) and Rust based on a variety of key attributes.

Vlang vs. Rust

Rust is a statically and strongly typed language designed to build reliable and efficient software. V, on the other hand, is a simple language that enables building maintainable and predictable programs.

Although widely known for its safety and concurrency, Rust also guarantees fast performance and compile-time memory management. Rust therefore avoids some of the drawbacks — like data races and crashes — of other systems languages like C++.

A newer player in the game, V is a compiled programming language that promises high-performance features for simple, readable, and maintainable code. It is very similar to Go and Rust, and also has a few similarities with Swift and Oberon. Better yet, it also supports C code translation to V (with C++ translation features in progress).

The first stable release of Rust dates back to May 15, 2015. Rust has been voted five times as the most-loved programming language by developers in Stack Overflow’s survey. On the other hand, V is a relatively new programming language that has been gaining rapid popularity due to its impressive performance, innovative memory management, and C/C++ translation promises.

Although V and Rust share some common features, their programming approach is radically different from each other. This is to be expected; they have each been developed to target different use cases, which will discuss in more detail in the sections that follow.

Global variables

A global variable is a variable with global scope, meaning that it is integral to the whole program.

Rust does not recommend the use of global variables, but there are some cases where global variables are more desirable (and practical). Global variables can be used in Rust using static mutable variables or unsafe Rust.

On the other hand, V was built to enable building maintainable and predictable software and is widely known for its strict approach, so it does not allow global variables at all. There is also no null or undefined in V.

We made a custom demo for .
No really. Click here to check it out.

By default, then, if you’re looking to use global variables, you should use Rust over V.

Memory management

The way a programming language handles memory management matters greatly. Both Rust and V guarantee compile-time memory safety, however, their way of dealing with this is quite different by comparison.

Unlike many other programming languages that use a garbage collector, Rust ensures memory management via ownership and borrowing rules (also called lifetimes). These rules can be pretty hard to wrap your head around at first.

V takes a different approach, using its auto-free engine which adds necessary free calls implicitly at compilation. This simplifies the memory management process significantly. Check out the demo in the video of V’s compile-time memory management below:

Result and option types

In addition to the standard types available in Rust(boolean, numeric, textual, etc.), there is also an option type. This type can either contain a value or not contain any value (and therefore be none). Result and option types are very commonly used in Rust, but it can be difficult to understand these types and use them effectively.

In V, the process is very simplified. A ? can be used in place of a function’s return type, letting it either return a value, an error, or a none. Thus, V combines option and result type into ?. With this functionality, error handling is also a lot easier to tackle.

Take a look at the use of ? in the sample code below, taken from the V docs:

fn (r Repo) search_user_by_id(id int) ?User {
        for user in r.users {
                if user.id == id {
        // V automatically wraps this into an option type 
                        return user
                }
        }
        return error('User $id not found')
}

References and values

In Rust, you must explicitly choose between value, reference, ref-counted, atomic-ref-counted, and a few other types before passing it to a function.

With V, you can simply use objects and leave it to the compiler to decide whether to use values or references. This saves the programmer time by not needing to explicitly name values or references in their code.

In the example below, you can see how V gives you the freedom to pass an immutable function argument (like foo) either by value or by reference:

struct Foo {}
fn (foo Foo) bar_method() {
        // ...
}
fn bar_function(foo Foo) {
        // ...
}

Lambda expressions

Compared to V, Rust is a more all-purpose language that supports a wide variety of features, including support for Lambda expressions.

Sticking to its strict and simplified approach, V has very minimal support for Lambda and Lamda-like syntax, and does not allow Lambda expressions for more than one parameter.

Safety

V has no support for things such as null, global variables, undefined values, variable shadowing, or bounds checking. It offers highly safe functionalities such as option/result types, generics, immutable variables by default, pure functions, and immutable structs. Given this, V is considered to be an exceedingly type-safe and memory-safe language.

Rust, by comparison, still allows a few features (even though it highly discourages their use); these include, for example, the aforementioned global variables and unsafe Rust, which should be used selectively.

Performance

As all of us in programming know well, performance is an essential factor of using any language.

V’s official documentation claims that it is as fast as C, with the least amount of allocations and an in-built serialization without any run-time reflection. Moreover, V claims compilation performance of around 80k (Clang backend) and 1 million (x64 and tcc backends) lines of code per second per CPU core.

Not that Rust is slow — Rust offers great compilation speed as well. However, compared to V, Rust has a ways to go in reaching the outstanding speeds now available in the marketplace.

Conclusion

Both Vlang and Rust are top-notch languages for building software. They are modern, compact, powerful, high-performance languages with great support for compile-time memory management. Each programming language is deliberately optimized for different things.

As is often the case in programming, the choice of language entirely depends on what you’re working on and what problems you are trying to solve. Both first-class in their own ways, V and Rust are worth the time and effort you will invest in learning these languages in your journey as a developer.

LogRocket: Full visibility into production Rust apps

Debugging Rust applications can be difficult, especially when users experience issues that are difficult to reproduce. If you’re interested in monitoring and tracking performance of your Rust apps, automatically surfacing errors, and tracking slow network requests and load time, try LogRocket.

LogRocket is like a DVR for web apps, recording literally everything that happens on your Rust app. Instead of guessing why problems happen, you can aggregate and report on what state your application was in when an issue occurred. LogRocket also monitors your app’s performance, reporting metrics like client CPU load, client memory usage, and more.

Modernize how you debug your Rust apps — .

Shubham Kumar Software artist and internet cowboy!

10 Replies to “Vlang vs. Rust: Comparing build languages”

  1. V actually allows global variables through the – -enable-globals flags. It was added mostly for driver based work and not recommended in most cases – but it’s still there to use.

  2. Your comparison comes across very biased, please make sure you do your research. I am by no means an expert in rust (and no nothing about v), but you clearly are biased to v. For example you state “There is also no null or undefined in V” but also state ” A ? can be used in place of a function’s return type, letting it either return a value, an error, or a none”. Is none not a synonym null? This sounds eerily similar rust’s “Some” enum. Also ” Rust has a ways to go in reaching the outstanding speeds now available in the marketplace” you cannot blindly state this without data. Considering rust is being adopted into the linux kernel (where speed matters) i highly doubt this statement is true. See [1] for proper comparison rather than a vague comparison.

    [1] https://kornel.ski/rust-c-speed

  3. Forbidding global variables doesn’t magically provide you with any kind of safety. In this context, global variable can be seen as special implicit parameter to any function that uses it directly or indirectly. Any unsafety (memory related or caused by data races) that can be exploited with globals can be exploited with regular parameters.
    Speaking of unsafety the language is riddled with UBs kindly provided by C which it transpiles to. Plus data races UBs which are unfixable in general without severe changes to the language semantics. Plus memory model impossible to efficiently implement. Plus low quality of design and implementation: there’s probably not a single slightly complex feature that doesn’t break if you try something that’s not exactly covered by tests. Generics impl is simply a joke, but sure “we will support them soon”.
    One thing this “will lang” great in is how it got hyped to 20k stars on github and created a cult of followers that blindly follow their leader, defy reality and kill any critics on sight (https://imgur.com/a/vz49G5A). Truly amazing.

  4. This comparison looks biased.

    > “Rust and V top-notch languages for building software”

    Rust is being funded by some of the biggest software companies in the world, and used by many in production (Microsoft, Google, Amazon, Mozilla and Facebook at the start of the list). Rust is also being used by Android and Firefox, which are widely used and impactful technologies. There are people investing time and money on it, so you can feel safe learning it.

    V, on the other hand, is yet to prove anything, it’s actually unfair to compare it with Rust, the project page had some false claims (search for “V is for Vaporwave” if you want the explanation), because of that I don’t know if we should start trusting the informations on that page right away. As that incident gets older we can expect changes in the technology, and on the behavior of those involved.

    I really hope that V can grow to a point where it can be battle-tested and fairly compared with Rust.

  5. Comparison comes across very biased +1.

    For one, an overwhelming amount of attention is given to aspects in which V supposedly has an advantage, whereas where Rust is supposedly better it’s just glossed-over with one or two sentences. Also where is Rust code? You can’t write a “comparison” between V and Rust while only ever showing V code.

    And two, a huge part of any programming language is its ecosystem, which this article “conveniently forgets” to mention at all. Well, given the author’s apparent position on the matter, I’d say good call because there’s simply no comparison. Rustup, Cargo, crates.io, developer community, documentation, variety of build targets, etc. – all of which V simply doesn’t have an answer to.

    I’m sorry but at the moment I will pick Rust any day of the week. Maybe we can revisit this topic 10 years later or something.

  6. V doesn’t have a working memory management, it leaks memory at every possible occasion. Autofree is so unstable that even v compiler doesn’t use it. All v compiler code is full of `voidptr`; now tell me how is V more type and memory safe than Rust?

  7. Vlang is considered a threat to various corporate interests and those heavily invested in Rust and Go, so they are going hard on the attack and get angry when any flaws or alternatives are shown.

    By default, any new language “shaking the tree”, and trying to put the interests of common folk first (like cross-platform application building) is going to face heavy “directed” media criticism. Vlang is for the people and is progressing rapidly, as its GitHub shows.

  8. Yes True. People are going completely biased towards Rust. No doubt Rust is a great language. But we can see how Vlang goes 🙂

    Both languages has its own pros and cons.

  9. You are criticisms are a bit unfair.

    1. None is not the same as null. In languages like js, any variable can be set to null while V like in Rust
    uses a Union type to to express if a value can contain Some(value), None or an Err(msg). If a variable is not defined as a Result/Option type it cannot be None.

    2. I have been using V for a few months now and Rust for 2 years. Rust complilation speeds don’t come
    close to V. That said, it seems like Rust runtime speeds are slightly better.

Leave a Reply