V (programming language)

General-purpose programming language From Wikipedia, the free encyclopedia

V, also known as vlang, is an in-development statically typed, compiled programming language created by Alexander Medvednikov in early 2019.[4] It was inspired by Go, and other programming languages including Oberon, Swift, and Rust.[5][6][7] It is free and open-source software released under the MIT License, and currently in beta.[8]

DesignedbyAlexander Medvednikov[1]
Firstappeared20 June 2019; 6 years ago (2019-06-20)[2]
Stable release
0.5[3] Edit this on Wikidata / December 31, 2025; 2 months ago (December 31, 2025)
Quick facts Paradigms, Designed by ...
V
A capitalized letter V colored blue
The official V logo
ParadigmsMulti-paradigm: functional, imperative, structured, concurrent
Designed byAlexander Medvednikov[1]
First appeared20 June 2019; 6 years ago (2019-06-20)[2]
Stable release
0.5[3] Edit this on Wikidata / December 31, 2025; 2 months ago (December 31, 2025)
Typing disciplinestatic, strong, inferred
Memory managementoptional (automatic or manual)
Implementation languageV
OSLinux, macOS, Windows, FreeBSD, OpenBSD, NetBSD, DragonflyBSD, Solaris
LicenseMIT
Filename extensions.v, .vsh
Websitevlang.io
Influenced by
Go, Kotlin, Oberon, Python, Rust, Swift
Close

The goals of V include ease of use, readability, and maintainability.[9][10][11]

History

The new language was created as a result of frustration with existing languages being used for personal projects.[12] It was originally intended for personal use, [12] but after being mentioned publicly and increasing interest, it was decided to make it public.[13] V was initially created to develop a desktop messaging client named Volt.[6] On public release, the compiler was written in V, and could compile itself.[4][12] Key design goals in creating V were being easy to learn and use, higher readability, fast compiling, increased safety, efficient development, cross-platform usability, improved C interoperability, better error handling, modern features, and more maintainable software.[14][15][10][16]

V is developed, maintained, and released through GitHub[17][6] by developers and contributors internationally.[4] In 2025, V started being ranked on the TIOBE index.[18]

Veasel is the official mascot of the V programming language[19]

Features

Safety

V has policies to facilitate memory-safety, speed, and secure code,[14][20][6] including various default features for greater program safety.[7][14][12] It employs bounds checking, to guard against out of bounds use of variables. Option/result types are used, where the option data type (?) can be represented by none (among possible choices) and the result type (!) can handle any returned errors. To ensure greater safety, error checking is mandatory. By default, the following are immutable: variables, structs, and function arguments. This includes string values are immutable, so elements cannot be mutated. Other protections, which are the default for the language, are: no use of undefined values, variable shadowing, null pointers (unless marked as unsafe), or global variables (unless enabled via flag).

Performance

V uses value types and string buffers to reduce memory allocations.[21][22][14] The language can be compiled to human-readable C,[7][4] and in terms of execution and compilation, it's considered to be as performant.[14][15][12]

Memory management

V supports four memory management options:[23][6][12][4]

  1. A garbage collector. This is the default.
  2. Manual memory management via disabling the garbage collector.
  3. Autofree, which is experimental, for invoking the necessary calls to automatically free up objects during compilation.
  4. Arena allocation.

Source code translators

V supports a source-to-source compiler (transpiler) and can translate C code into V.[15][24][10]

Working translators are also being developed for Go, JavaScript, and WebAssembly.[25][26][4]

Syntax

Hello world

The "Hello, World!" program in V:[14][27]

fn main() {
	println("Hello, World!")
}

Variables

Variables are immutable by default and are defined using := and a value. Use the mut reserved word (keyword) to make them mutable. Mutable variables can be assigned to using =:[28][27]

x := 1
mut y := 2
y = 3

Redeclaring a variable, whether in an inner scope or in the same scope, is not allowed:[28][27]

x := 1
{
    x := 3 // error: redefinition of x
}
x := 2 // error: redefinition of x

Structs

Struct example:[9][7][27]

struct Foo {
    number int
	name string
    score f32
}

// Struct fields can be initialized by name
var1 := Foo {
    number: 21
    name: "baz"
    score: 2.5
}

// or by position
var2 := Foo{50, "taz", 3.14}

Heap structs

By default, structs are allocated on the stack. When structs are referenced by using the prefix & or have the [heap] attribute, they are allocated on the heap instead:[4][27]

struct Foo {
    number int
}

@[heap]
struct Baz {
    number f32
}

// Structs that are referenced are heap allocated
var1 := &Foo{2}

// Baz is always heap allocated because of its [heap] attribute
var2 := Baz{4.5}

Methods

Methods in V are functions defined with a receiver argument. The receiver appears in its own argument list between the fn keyword and the method name. Methods must be in the same module as the receiver type.

The enrolled_status method (below) has a receiver of type Client named x. The convention is not to use receiver names like self or this, but preferably a short name. For example:[9][10][27]

struct Client {
    enrolled bool
}

fn (x Client) enrolled_status() bool {
    return x.enrolled
}

println(Client{enrolled: true}.enrolled_status())  // true
println(Client{enrolled: false}.enrolled_status()) // false

Error handling

Result types may represent an error returned from a function. Result types are declared by prepending !: !Type

Optional types may represent none. Option types prepend ? to the type name: ?Type.[9][7][23][27]

fn something(t string) !string {
	if t == "foo" { return "foo" }
	return error("invalid")
}

x := something("foo") or { "default" } // x will be "foo"
y := something("baz") or { "default" } // y will be "default"
z := something("baz") or { panic("{err}") } // z will exit with an error

println(x)
println(y)

See also

References

Bibliography

Further reading

Related Articles

Wikiwand AI