Code in V

ยท

3 min read

What the V?

You might have heard of the new kid in town. V. The forbidden love-child of Go and Rust in my mind, that is.

Really it's not some new obscure language, that won't stay around. It has a couple of years in the bag. Working hard to come build version 1. As of this writing the latest version is 0.1.29, which was released on August 6. 2020.

Fun fact #0:

It was initially written in Go, but now able to compile itself, thus making it possible to be written in 100% V - and Go is now obsolete of any V compiler.

What makes V special?

As I mentioned earlier, V is Go and Rust. Also in speed. Actually it's as fast as C. Compiled and safe to write. Along with the ability to write unsafe code - like the parts in Rust. Yet simple to write as Go.

Another feature it uses, that is quite popular in the Rust ecosystem, is the fast that it can catch run-time errors at compile time.

V can compile V in under a second. As for disk required, you do not even need large TB disk, not even half a TB. Actually, you can install the complete language on an small SD-card as the actual size is less than 0.025% of the space required to install GCC, a C++ compiler.

It's as easy as v fmt . -w to format a project in V. Pretty much as in Go. Making it super simple to agree in a company of a coding style for V.

WASM is also at the core of V, it compiles - as lots of other languages - to WASM, for the web.

Fun fact #1:

The creator, Alexander Medvednikov, dubbed the language V, to not conflict with any other language extensions he were using.

Is V fast?

Is this a joke. No, the simplicity of Go and speed of C. Super simple to understand. V even have a site to check if V is (still) fast: fast.vlang.io.

It has C interop without any costs along with a minimal amount of allocations. Thus not just fast, but also makes a small impact on the machine that has to run the V program(s).

One of V's proudest libraries, if you ask me, is the pico.v one of the fastest web-frameworks out there! (techempower.com/benchmarks)

Fun fact #2:

V has a [live] macro for functions in the language. Meaning they are live-reloaded!

A taste

I've decided the best way to give a proper taste in V, is to implement a big, sophisticated AI. Namely, one that can guess if coding is fun or not.

We start the code simply by naming our main-function, no package names or any bloat like that.

fn main() {

Next, we add some choices.

  choices := 'Choose `Yes` or No'

Notice, I'm not making it easy for the AI.

Now to fire-up the AI.

  answer := choices.find_between('`',. '`')

And finally, let's see the result.

  println('Is coding fun? $answer!')
}

And the complete code is as follows.

fn main() {
  choices := 'Choose `Yes` or No' 
  answer := choices.find_between('`', '`')

  println('Is coding fun? $answer!')
}

Phew! That was quite an exercise. Now, though, you know how to program in V.

Note: This has just been a small introduction to V. It should in no where near be used as production code.


{ Best, Mads Bram Cordes }

Did you find this article valuable?

Support madco by becoming a sponsor. Any amount is appreciated!

ย