Getting Started With V

Hit the ground running with this collection of resources

Hero image

Introduction

V is a simple, fast, safe, compiled general purpose programming language for developing maintainable software. There are several compelling reasons for using V, which you can learn more about here: The V Programming Language

In this post, we focus on getting new users up to speed so that they can start working with V right away.

Installing (and Updating) V

Since V is in active development, there will be a lot of breaking changes often. Therefore, it is recommended that you install V from source.

Installing V from source

git clone https://github.com/vlang/v
cd v
make # make.bat on Windows

V compiles itself really fast and requires no dependencies and libraries for self compilation. For more information, see Installing V from source. You can optionally leverage established C compilers like GCC, Clang, or MSVC to generate optimized binaries.

Weekly Release

V makes weekly releases (besides the normal semantic version update releases) if you do not prefer compiling from source. You can find the releases here: Releases.

Symlinking

The V executable generated (or obtained) is not automatically added to your PATH. V provides a convenient solution to this.

# On Linux, Mac OS, and other similar systems
sudo ./v symlink

# On Windows, open an Administrator shell and run the following.
# NOTE: This is the ONLY command that neeeds to be run from an Administrator shell.
.\v.exe symlink

Refer to this section for more information: Symlinking.

Updating V

Similar to rustup, V supports the following command:

v up

This command updates the V compiler to the latest version available from the main Github repository.

Learning V

Syntactically, V is similar to Go. Therefore GoLang devs can feel at home when they write V code. Knowledge of Go is not necessary; the language is very simple and the main concepts can be learned over a weekend.

The official documentation for the language is written in a single markdown document: V Documentation.

The documentation for all of the modules included in the V standard library (vlib) is available here: vlib Documentation. You are encouraged to use the search bar to find the functions and structs you need for your project.

For a taste of V here is a truncated example of TOML file parsing. The sample TOML file is available here: TOML Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import toml
import toml.to

// Multiline string
const toml_text = '# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
...
Truncated
...
'

fn main() {
	doc := toml.parse(toml_text) or { panic(err) }
	title := doc.value('title').string()
	println('title: "$title"')
	ip := doc.value('servers.alpha.ip').string()
	println('Server IP: "$ip"')

	toml_json := to.json(doc)
	println(toml_json)
}

Source code: toml.v

Setting up your Development Environment

Code Editor

You are free to use any code editor you prefer. We recommend Visual Studio Code for beginners because we support it officially through the VSCode extension. For help with other editors, please join our Discord Server.

Language Server

The V Language Server (WIP) is an LSP compatible language server. The VSCode extension should be able to automatically download and install VLS. In case of errors, check out the pre-built binaries, or build VLS from source. If your find any bugs, get them confirmed in the #vls channel on our server and then report them on Github. We are also open to contributions!

Running a V Program

Your project should have at least one main function. Then you can compile and run you code in one of two ways:

  1. Directly run the program with v run file.v or v run directory. You can even do v run . to run the only main function in the directory.
  2. Compile the program with v file.v (optionally as v -prod file.v) and then run the generated executable.

Miscellaneous

You need git to clone and update V. Make sure that it is installed on your machine.

Additionally, use v new and v init as necessary, and use v fmt -w /path/ to automatically format your source code. Consult v help init and v help fmt for more information.

Getting Help and Reaching Out

It is recommended that you make frequent use of v help, consult the language documentation and the modules documentation. If you want to get specific help, reach out to us directly, or just hang out with the V community members, join our Discord Server. Use the appropriate channels for your needs.

While developing in V, you may encounter bugs. Please report them in the #bugs channel, and file Github issues about them with v bug file.v.

Article by Subhomoy Haldar
Published on