Live code reloading, without losing your application’s state. A shorter path from idea to what you see.
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.
fn main() {
areas := ['game', 'web', 'tools', 'science', 'systems',
'embedded', 'drivers', 'GUI', 'mobile']
for area in areas {
println('Hello, ${area} developers!')
}
}
// Print file lines that start with "DEBUG:"
import os
// `read_file` returns an optional (`?string`), it must be checked
text := os.read_file('app.log') or {
// `err` is a special variable that contains the error
// in `or {}` blocks
eprintln('failed to read the file: ${err}')
return
}
lines := text.split_into_lines()
for line in lines {
if line.starts_with('DEBUG:') {
println(line)
}
}
import time
import net.http
resp := http.get('https://vlang.io/utc_now') or {
println('failed to fetch data from the server')
return
}
t := time.unix(resp.body.int())
println(t.format()) // 2019-08-16 17:48
import json
struct User {
name string
age int
mut:
is_registered bool
}
fn main() {
s := '[{"name":"Frodo", "age":25}, {"name":"Bobby", "age":10}]'
mut users := json.decode([]User, s) or {
eprintln('Failed to parse json')
return
}
for user in users {
println('${user.name}: ${user.age}')
}
println('')
for i, mut user in users {
println('${i}) ${user.name}')
if !user.can_register() {
println('Cannot register ${user.name}, they are too young')
continue
}
// `user` is declared as `mut` in the for loop,
// modifying it will modify the array
user.register()
}
// Let's encode users again just for fun
println('')
println(json.encode(users))
}
fn (u User) can_register() bool {
return u.age >= 16
}
fn (mut u User) register() {
u.is_registered = true
}
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.
No global variables
(can be enabled for low level apps like kernels via a flag)
Performance & Fast compilation
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.
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:
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:
A powerful graphics library
A powerful graphics library
Cross-platform drawing library gg, using OpenGL/Metal/DirectX 11 for rendering 2D applications.
There's also a 3D engine in development with the following features already available:
Loading complex 3D objects with textures
Camera (moving, looking around)
Skeletal animation
A simple example of the graphics library in action is
tetris.v.
Painless deployments and dependency management & Run everywhere
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 binary that is guaranteed to work on all operating systems (provided you cross compile) without any external dependencies.
This binary is self-contained except for the OS-provided system library (libc), which is linked dynamically.
To achieve fully static binaries on Linux, you can use
v -cc musl-gcc .
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 & Cross-platform shell scripts in V
REPL
v
>>> import net.http
>>> data := http.get('https://vlang.io/utc_now')!
>>> data.body
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
Code formatting with vfmt for consistent style & A built-in code profiler
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 & Automatic documentation
JavaScript and WASM backends
V programs can be translated to JavaScript (WIP):
v -o hello.js hello.v
The JS backend is at an early stage.
They can also be compiled to WASM (for now with Emscripten, but native WASM support is planned). V compiler compiled to WASM and running V programs by translating them to JavaScript:
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 Veb
Powerful built-in web framework Veb
Veb is very fast (built on top of pico.v which has been at the top of TechEmpower benchmark), 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).
['/post/:id']
fn (b &Blog) show_post(id int) veb.Result {
post := b.posts_repo.retrieve(id) or {
return veb.not_found()
}
return veb.view(post)
}
Gitly, a light and fast alternative to GitHub/GitLab is built in V and Veb.
Built-in ORM
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 customers: ${nr_customers}')
// V syntax can be used to build queries
uk_customers := sql db {
selectfrom 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 {
selectfrom 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
}!
}
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.
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.
As of today, programs built with the V compiler no longer leak memory by default.
May 29, 2022
7000 pull requests have been merged!
Made for people who love to build
In good company.
What developers say about V
I just stumbled into V the other day, and I've been working on a couple of personal projects. I'm really loving it so far. I spent a lot of time with Go, so it feels super familiar. That said, I actually have a module I made last night for interacting with MeshCore. I've not had this much fun programming in a long while.
The V development team does an amazing job. I've never seen a language evolve that fast; I suspect you guys never sleep. I hope V will remain a simple, clean language and have a bright future. Thanks for all your hard work.
I like V a lot. The abstraction over the syntax is so nice that made me enjoy writing the syntax as a whole. V has come a lot further than when I tried it in 2023. I’ll be actively using it from now on.
I'm mostly surprised by how many things "just work". Channels and closures made implementing asynchronous callbacks for C functions such a breeze. Thanks for that! 😄
Been programming for around 30 years. Have done some C/C++, VB, and lots of Delphi years ago. Then PHP/Ruby for over 15 years. Bash, Python too. Recently I've wanted to start using a compiled language for reasons, and have looked at Rust, Go, and a couple others. I stumbled upon V a few weeks ago and have been very surprised by how easy it is to pick up. I am really enjoying writing V and feel like I am already productive. Even to the point I'm now looking at making a small ...
I buy my son's diaper with C#, but every project I start today is in V. Because every project in C# has an initial load of bureaucracy that in V I don't have to deal with at the beginning, and I can plug bureaucracy into the project throughout the creation process.
Gotta say that V's syntax is amazing (especially the error handling aspect for me since I strongly dislike Go's error handling approach but liked its other aspects).
After V, developing a kernel in C results in more bugs, honestly more so because V catches a set of bugs and memory leakage that C simply doesn't.
mint, maintainer of Vinix
Just want to say thank you for continuing to improve the language. Adding the GC was very nice and I find V my all-time favorite language. Using V is fun due to great syntax and tooling but also makes you a better developer as you try to understand how things work underneath.
Just wanted to say thank you to everyone contributing to V! Before September 2023 I never really coded nor completed any project as the tools I had were less than ideal. In September I started learning V and now I have a really good prototype and a professional developer even reached out to me saying my code was really good! That's why I wanted to thank V and all the contributors 🥰
It's obvious that Alex was able to bring his experience of many other languages to V, giving the language a very solid foundation. It's difficult for me to list all the positive qualities I like about V because I'm sure I'll forget some. I'll try it anyway.
Thank you very much to everyone contributing to V! It's been 1.5 years since I've discovered it. I really enjoy the kind and helping community, the simplicity philosophy and lots of other things. I was pleasantly surprised by the easiness of creating an HTTP server: just a few lines and then handling the request is very easy by following the example. A big thank you from the bottom of my heart ❤️
I mastered Python when I worked as a Data Scientist a few years ago. Since I discovered V I stopped using Python almost entirely, and now I look back and... it's awful. Never had so much fun programming as I am now.
V is seriously impressive. After years of Go development, V brings the simplicity I love, but with true low-level control and raw speed — exactly what I’ve been missing. Looking forward digging deeper with this tech, just started ❤️