Introduction

V is a statically typed compiled programming language designed for building maintainable software. It's similar to Go and is also influenced by Oberon, Rust, Swift.

V is a very simple language. Going through this documentation will take you about half an hour, and by the end of it you will learn pretty much the entire language.

Despite being simple, it gives a lot of power to the developer. Anything you can do in other languages, you can do in V.

Found an error/typo? Please submit a pull request.

Hello World

fn main() {
println('hello world')
}

Functions are declared with fn. Return type goes after the function name. In this case maindoesn't return anything, so the type is omitted.

Just like in C and all related languages, main is an entry point.

println is one of the few built-in functions. It prints the value to standard output.

fn main() declaration can be skipped in one file programs. This is useful when writing small programs, "scripts", or just learning the language. For brevity, fn main() will be skipped in this tutorial.

This means that a "hello world" program can be as simple as

println('hello world')

Comments

// This is a single line comment.

/* This is a multiline comment.
/* It can be nested. */
*/

Functions

fn main() {
println(add(77, 33))
println(sub(100, 50))
}

fn add(x int, y int) int {
return x + y
}

fn sub(x, y int) int {
return x - y
}

Again, the type comes after the argument's name.

Just like in Go and C, functions cannot be overloaded. This simplifies the code and improves maintainability and readability.

Functions can be used before their declaration: add and sub are declared after main, but can still be called from main. This is true for all declarations in V and eliminates the need of header files or thinking about the order of files and declarations.

Source: https://vlang.io/docs