The V programming language
Tags: vlang, v, news, beginners
Published: 2020-01-15 09:52:38

## Introduction

Hello! I'm starting “_Good to know_” series. 

I so excited to show you very young, but simple, fast, safe & compiled programming language called **V** (or **vlang** for Google Search bots).

## Objectives of the article

1. Story of V;
2. Hello World;
3. Main features of language;
4. How to install and update;

## What's "V" mean?

No, [Alexander Medvednikov](https://github.com/medvednikov) (author of V programming language) do not fan of "V for Vendetta" movie or Vue.js! But it's very interesting story:

> Initially the language had the same name as the product it was created for: Volt. The extension was ".v", I didn't want to mess up git history, so I decided to name it V :)
>
> It's a simple name that reflects the simplicity of the language, and it's easy to pronounce for everyone in the world.
>
> — _Alexander Medvednikov_

## The V's "Hello World"!

```js
// hello_world.v

fn main() {
  w := 'World'
  println('Hello $w!')
}
```

Clear and simple, uh? What if I tell you that this code can be written in even shorter form? If your program is only single file (all code in one file), V allows you to drop `fn main() {...}`. 

Like this:

```js
// hello_world.v

w := 'World'
println('Hello $w!')
```

Yes, this is a **valid V code** too!

## Main features

> **Please note:** this article was written when V version was `0.1.24`.

### V is written in V

The entire language and its standard library are less than 1 MB and can be built in less than 0.6 seconds.

> V compiles between ≈100k and 1.2 million lines of code per second per CPU core (without hardware optimization).

### As fast as C

Minimal amount of allocations, plus built-in serialization without runtime reflection. Compiles to native binaries without any dependencies.

Is V still fast? Look [monitoring compilation speed](https://fast.vlang.io/) table.

### Safety

- **NO** 👎
  - `null` (`nil`, `None`, ...)
  - global variables
  - variable shadowing
  - undefined values + behavior
- **YES** 👍
  - bounds checking
  - option/result types
  - generics
- **By default** 👌
  - immutable variables + structs
  - pure functions

### Similar to another languages

If you work with C, Go, Rust or JavaScript, you're ready to write code on V! Don't trust me, read program code near and answer "_what does each line do?_":

```js
import time
import http

fn main() {
  resp := http.get('https://vlang.io/utc_now') or {
    println('failed to fetch data from the server')
    return
  }

  t := time.unix(resp.text.int())
  println(t.format())
}
```

This program go to external HTTP server and return UNIX timestamp or print `failed to fetch data from the server`. OK! We set to `t` variable normalized date and time by standard V library `time` and print result. 

> Simple to read, easy to write and can be learned in less than an hour!

### Build-in package manager

The V Package Manager ([vpm](https://vpm.best/)) — it's package management tool similar to NPM by Node.js, Cargo by Rust, Go Modules and many more.

```console
$ v install [module]
```

### Cross-platform UI library

> UI is a cross-platform UI toolkit written in V for Windows, macOS, Linux, and soon Android, iOS and the web (JS/WASM). 
>
> V UI uses native widgets on Windows and macOS, on all other platforms the widgets are drawn by V UI.

![Cross-platform UI library](https://thepracticaldev.s3.amazonaws.com/i/7kfg9njf5dsrqkmf7ixj.png)

### Plugins for V syntax on popular code editors

1. [VS Code](https://marketplace.visualstudio.com/items?itemName=0x9ef.vscode-vlang&ssr=false)
2. [Vim](https://github.com/ollykel/v-vim)
3. [Vid](https://github.com/vlang/vid) (1 MB editor written in V)

## Okay, time to try V on your computer!

- First, go to console and clone V repository:

```console
$ git clone https://github.com/vlang/v.git
```

- Next, go to `v` folder and run `make`:

```console
$ cd v && make
```

> On Windows, `make` means running `make.bat`, so make sure you use `cmd.exe`.

- Third, let's create symlink for it:

```console
$ sudo ./v symlink
```

- That's all! 😉 V was installed to `/usr/local/bin/v` path and available to call by `v`. 

### Update V

For update V to latest version, simply type on console:

```console
$ v up
```

## More about V language

- GitHub repository — [https://github.com/vlang/v](https://github.com/vlang/v)
- Official docs — [https://vlang.io/docs](https://vlang.io/docs)

### Fresh news

- Twitter — [https://twitter.com/v_language](https://twitter.com/v_language)
- Telegram — [EN](https://t.me/vlang_en), [RU](https://t.me/vlang_ru), [IT](https://t.me/vlang_it), [ZH](https://t.me/vlang_zh)

## Exercises

1. Find in V official web site comparison to other languages;
2. Go to official V [Playground](https://vlang.io/play) and write some code;
3. Install V on your computer, go to `example` folder on GitHub repository and run "_Game of life_";

## Photo by

[Title] Annie Spratt https://unsplash.com/photos/QckxruozjRg

<a name=""></a>
## P.S.

If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻

And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!

My projects that need your help (and stars) 👇

- 🔥 [gowebly][gowebly_url]: A next-generation CLI tool for easily build amazing web applications with Go on the backend, using htmx & hyperscript and the most popular atomic/utility-first CSS frameworks on the frontend.
- ✨ [create-go-app][cgapp_url]: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.
- 🏃 [yatr][yatr_url]: Yet Another Task Runner allows you to organize and automate your routine operations that you normally do in Makefile (or else) for each project.
- 📚 [gosl][gosl_url]: The Go Snippet Library provides snippets collection for working with routine operations in your Go programs with a super user-friendly API and the most efficient performance.
- 🏄‍♂️ [csv2api][csv2api_url]: The parser reads the CSV file with the raw data, filters the records, identifies fields to be changed, and sends a request to update the data to the specified endpoint of your REST API.
- 🚴 [json2csv][json2csv_url]: The parser can read given folder with JSON files, filtering and qualifying input data with intent & stop words dictionaries and save results to CSV files by given chunk size.

<!-- Footer links -->

[gowebly_url]: https://github.com/gowebly
[cgapp_url]: https://github.com/create-go-app
[yatr_url]: https://github.com/koddr/yatr
[gosl_url]: https://github.com/koddr/gosl
[csv2api_url]: https://github.com/koddr/csv2api
[json2csv_url]: https://github.com/koddr/json2csv