The V Programming Language 0.4 beta

Simple, fast, safe, compiled. For developing maintainable software.

github.com/vlang/v 35k

The first printed book on V!

The second printed book on V!
fn main() {
    areas := ['game', 'web', 'tools', 'science', 'systems',
              'embedded', 'drivers', 'GUI', 'mobile']
    for area in areas {
        println('Hello, ${area} developers!')
    }
}

Latest news & blog posts

Jan 9, 2024
Nov 11, 2023
Sep 30, 2023
Sep 3, 2023
July 1, 2023
June 29, 2023
April 30, 2023
April 17, 2023
January 30, 2023
October 31, 2022
August 31, 2022
June 30, 2022
June 10, 2022
June 9, 2022
As of today, programs built with the V compiler no longer leak memory by default.
May 29, 2022
7000 pull requests have been merged!

Simple language for building maintainable programs

You can learn the entire language by going through the documentation over a weekend, and in most cases there's only one way to do something.

This results in simple, readable, and maintainable code.

Despite being simple, V gives a lot of power to the developer and can be used in pretty much every field, including systems programming, webdev, gamedev, GUI, mobile, science, embedded, tooling, etc.

V is very similar to Go. If you know Go, you already know ≈80% of V. Things V improves on Go: vlang.io/compare#go.

Safety

Performance

  • C interop without any costs
  • Minimal amount of allocations
  • Built-in serialization without runtime reflection
  • Compiles to native binaries without any dependencies: a simple web server is only about 250 KB
  • As fast as C (V's main backend compiles to human readable C), with equivalent code.
    V does introduce some overhead for safety (such as array bounds checking, GC free), but these features can be disabled/bypassed when performance is more important.

Fast compilation

V compiles ≈80k (Clang backend) and ≈400k (x64 and tcc backends) lines of code per second.
(Apple M2, no optimization)

V is written in V and compiles itself in under a second (0.45s on Mac mini M2).

Most of the compiler is still single threaded, so it's going to be 2-3x faster in the future!

Small and easy to build compiler

V can be bootstrapped in under a second by compiling its code translated to C with a simple

cc v.c
No libraries or dependencies needed.

For comparison, space and time required to build each compiler:

Space  Build time
Go525 MB1m 33s
Rust30 GB45m
GCC8 GB50m
Clang90 GB [0] 60m
Swift70 GB [1] 90m
V< 20 MB [2] <1s

Building V in 0.3 seconds and then using the resulting binary to build itself again:

Try it yourself:

wget https://github.com/vlang/v/releases/latest/download/v_linux.zip
unzip v_linux && cd v
time ./v self

Flexible memory management

V avoids doing unnecessary allocations in the first place by using value types, string buffers, promoting a simple abstraction-free code style.

There are 4 ways to manage memory in V.

The default is a minimal and a well performing tracing GC.

The second way is autofree, it can be enabled with -autofree. It takes care of most objects (~90-100%): the compiler inserts necessary free calls automatically during compilation. Remaining small percentage of objects is freed via GC. The developer doesn't need to change anything in their code. "It just works", like in Python, Go, or Java, except there's no heavy GC tracing everything or expensive RC for each object. Autofree is still experimental and not production ready yet. That's planned for V 1.0.

For developers willing to have more low level control, memory can be managed manually with -gc none.

Arena allocation is available via v -prealloc.

V's autofree demo. All objects are freed during compilation. Running the Ved editor on an 8 MB file with 0 leaks:

C translation

V can translate your entire C project and offer you the safety, simplicity, and compilation speed-up (via modules).

v translate file.c

std::vector s;
s.push_back("V is ");
s.push_back("awesome");
std::cout << s.size();
mut s := []
s << 'V is '
s << 'awesome'
println(s.len)

A blog post about translating DOOM will be published.

C++ to V translation is at an early stage.

Translating DOOM from C to V and building it in under a second:

You can read translated code here: github.com/vlang/doom

Hot code reloading

Get your changes instantly without recompiling.

Since you also don't have to get to the state you are working on after every compilation, this can save a lot of precious minutes of your development time.

github.com/.../examples/hot_reload

A powerful graphics library

Cross-platform drawing library, using OpenGL/Metal/DirectX 11 for rendering 2D/3D applications.

The following features are planned:

  • Loading complex 3D objects with textures
  • Camera (moving, looking around)
  • Skeletal animation

A simple example of the graphics library in action is tetris.v.

For 3D examples, check out this.

Light and fast cross-platform GUI library

Build native UI apps with V UI. You no longer need to embed a browser to develop cross-platform apps quickly.

V has a UI module that uses custom drawing, similar to Qt and Flutter, but with as much similarity to the native GUI toolkit as possible.

It has a declarative API similar to SwiftUI and React Native and runs on Windows, Linux, macOS, and Android.

Coming soon:

  • a Delphi-like visual editor for building native GUI apps
  • iOS support

github.com/vlang/ui

Volt, a 300 KB Slack client built with V and V UI:

Easy cross compilation

To cross compile your software simply run v -os windows or v -os linux. No extra steps required, even for GUI and graphical apps!

(Compiling macOS software only works on macOS for now.)

Building V for Windows using V for macOS, and then testing resulting v.exe on a Windows VM:

Painless deployments and dependency management

To build your project, no matter how big, all you need to do is run

v .

No build environments, makefiles, headers, virtual environments, etc.
You get a single statically linked binary that is guaranteed to work on all operating systems (provided you cross compile) without any dependencies.

Installing new libraries via vpm, a centralized package manager written in V, is as simple as
v install ui
		

Run everywhere

V can emit (human readable) C, so you get the great platform support and optimization of GCC and Clang. (Use v -prod . to make optimized builds.)

Emitting C will always be an option, even after direct machine code generation matures.

V can call C code, and calling V code is possible in any language that has C interop.

REPL

v
>>> import net.http
>>> data := http.get('https://vlang.io/utc_now')?
>>> data.text
1565977541

Cross-platform shell scripts in V

V can be used as an alternative to Bash to write deployment scripts, build scripts, etc. The advantage of using V for this is the simplicity and predictability of the language, and cross-platform support. "V scripts" run on Unix-like systems as well as on Windows.

for file in ls('build/') {
  rm(file)
}
mv('v.exe', 'build/')

v run deploy.vsh

Read more about V script

Code formatting with vfmt for consistent style

No more arguments about coding styles. There's one official coding style enforced by the vfmt formatter.

All V code bases are guaranteed to use the same style, making it easier to read and change code written by other developers.

v fmt -w hello.v

A built-in code profiler

Build and run your program with

v -profile profile.txt x.v && ./x
and you'll get a detailed list for all function calls: number of calls, average time per call, total time per call.

JavaScript and WASM backends

V programs can be translated to JavaScript:

v -o hello.js hello.v

They can also be compiled to WASM (for now with Emscripten). V compiler compiled to WASM and running V programs by translating them to JavaScript:

v-wasm.vercel.app

A game written using V's graphical backend and compiled to WASM:

v2048

Automatic documentation

Use vdoc to get instant documentation generated directly from the module's source code. No need to keep and update separate documentation.

v doc os

Built-in testing framework

Writing tests is very easy: just start your test function with test_

fn get_string() string { return 'hello' }

fn test_get_string() {
  assert get_string() == 'hello'
}
      

Friendly error messages

Helpful error messages make learning the language and fixing errors simpler:

user.v:8:14: error: `update_user` parameter `user` is mutable, you need to provide `mut`: `update_user(mut user)`

    7 |     mut user := User{}
    8 |     update_user(user)
      |                 ~~~~
    9 | }
	

Powerful built-in web framework Vweb

Vweb is very fast, it compiles into a single binary (html templates are also compiled), supports hot code reloading (the website is automatically updated in the browser once you change any .v/.html file).

github.com/vlang/v/tree/master/vlib/vweb

['/post/:id'] fn (b Blog) show_post(id int) vweb.Result { post := b.posts_repo.retrieve(id) or { return vweb.not_found() } return vweb.view(post) }

Gitly, a light and fast alternative to GitHub/GitLab is built in V and vweb.

Built-in ORM

import db.sqlite struct Customer { id int name string nr_orders int country string } fn main() { db := sqlite.connect('example.sqlite') or { panic('could not create/find example.sqlite') } nr_customers := sql db { select count from Customer }! println('number of all customers: ${nr_customers}') // V syntax can be used to build queries uk_customers := sql db { select from Customer where country == 'uk' && nr_orders > 0 }! for customer in uk_customers { println('${customer.id} - ${customer.name}') } // by adding `limit 1` we tell V that there will be // only one object customer := sql db { select from Customer where id == 1 limit 1 }! println(customer.name) // insert a new customer new_customer := Customer{name: 'Bob', nr_orders: 10} sql db { insert new_customer into Customer }! }

Built in V

V

V itself is written in V.

Volt

Native desktop client for Slack, Skype, Matrix, Telegram, Twitch and many more services.

Vinix

A minimalistic open-source OS that can already run Bash, GCC, and V.

Ved

Open-source 1 MB editor with the performance of Sublime Text.

Vox Browser

An early stage HTML+CSS renderer which can already render sites like Hacker News 20x faster than Chrome while using 4x less RAM.

Volt.im instant messaging and social platform

An upcoming open source alternative to Discord and Telegram that combines the best features of the two while being ultra fast and light.

vsql

A single-file SQL database written in pure V with no dependencies.

coreutils in V

Programs equivalent to GNU coreutils, written 100% in V.

C to V translator

This tool can already translate entire original DOOM. C++ support is planned as well. It does full automatic conversion to human readable code.

V UI

Cross-platform widget toolkit.

Gitly

Open-source light and fast alternative to GitHub/GitLab.

Vorum

Right now it's very basic forum/blogging software, but in the future it will be a full featured light alternative to Discourse.
The V forum runs on Vorum.

vgram

A bot library for Telegram Bot API.

Awesome V

A curated list of awesome V frameworks, libraries and software

The V Tensor Library

An n-dimensional Tensor data structure, sophisticated reduction, elementwise, and accumulation operations, data Structures that can easily be passed to C libraries, powerful linear algebra routines backed by VSL.

The V Scientific Library

A Scientific Library with a great variety of different modules.

Are you using V to build your product or library? Have it added to this list.

Web design by Leah. logo by Sonovice and Don.