Why I like V programming language

It is dead simple

The syntax is really simple. I can even say it is minimalist. I can learn language fundamentals in a whole day, from a single-page documentation. This is an example of a hello world program in V:

fn main() {
    print("Hello world!")
}

Using the function is simple. You can do as follows.

fn add(a int, b int) int {
    return a + b
}

If you come from go or rust, learning V will be a piece of cake. If you think go is syntactically simple, then you will feel that V is even more simpler.

There is only one (well, almost) way to do one thing. For instance, there is only one style of variable declaration: a := 1. There is only one way to return a value from a function: return value. In pascal, you can use result := 1, or Exit(1).

It is compiled

This is maybe the best deal. No sane guy distributes software that includes a full-blown interpreter along with bus-sized dependencies. You just give people a single file that does the job well, with minimum to no dependency.

No hassle in project and dependency management

Invoking v . is sufficient to build everything in the project folder. No matter how complex your project is, as long as at least one of the files contains a main function, V can handle compilation properly. You will end up with a single executable file.

Installing libraries is as simple as executing v install library_name. Updating V compiler can be done simply by v up. It includes a testing framework, and tests can be run by v test. There is no debate on how to format codes. Everyone should obey v fmt ..

It is safe

By default, all variables are immutable. We need to use mut keyword to specify otherwise. All variables have to be initialized with :=. See example below:

a := 42

mut name := "Unknown"
name = "Bill"

a = 0 // errorneous since a is immutable

No global variable is allowed, so it will not mess up the name space. No variable shadowing is allowed, so less chance you mess up your life by messing up with your code.

It's print() (and println()) can print anything

Admit it. You cannot live without printing stuff to stdout during debugging. V's print() can print anything, from primitives, arrays, struct, etc. It seems there is a representation for everything.

It has an auto-free engine and an option to turn it off

I have had enough of memory leaks. Maybe it is me that's not capable enough of handling such an issue. But V is kind enough to do memory management in my stead. It has built-in memory management that automatically inserts free calls in compile-time which can be enabled using -autofree flag.

If you like garbage collectors, you can turn it on using -gc boehm flag.

Some other things that might pique your interest


My favorite bits

Pattern matching as expression

animal := "dog"

sound := match animal {
    "cat"      { "meow" }
    "dog"      { "bark" }
    "antelope" { "snort"}
    else       { "..." }
}

Array initialization with a certain value

a := []int {len: 5, init: 3} 
println(a)
// Outputs [3, 3, 3, 3, 3]

Array initialization with access to iterator

a := []int {len: 5, init: it * 2} 
println(a)
// Outputs [0, 2, 4, 6, 8]

map and filter chaining

a := [1, 2, 3, 4, 5]
b := a.filter(it % 2 != 0).map(fn (x int) int { return x * 10 })
println(b)
// Outputs [30, 50, 50]

All in all, I find V simple to use, easy to start, expressive like python, and thus, makes me productive. This language is not a production-grade quality since it is still in active development, so be careful. I hope the developers keep their promise to keep this language as minimal as possible. That said, V will be my go-to language for my side projects.