DEV Community

Cover image for The V programming language
Vic Shóstak
Vic Shóstak

Posted on • Updated on

The V programming language

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 (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"!

// hello_world.v

fn main() {
  w := 'World'
  println('Hello $w!')
}
Enter fullscreen mode Exit fullscreen mode

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:

// hello_world.v

w := 'World'
println('Hello $w!')
Enter fullscreen mode Exit fullscreen mode

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 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?":

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())
}
Enter fullscreen mode Exit fullscreen mode

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) — it's package management tool similar to NPM by Node.js, Cargo by Rust, Go Modules and many more.

$ v install [module]
Enter fullscreen mode Exit fullscreen mode

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

Plugins for V syntax on popular code editors

  1. VS Code
  2. Vim
  3. Vid (1 MB editor written in V)

Okay, time to try V on your computer!

  • First, go to console and clone V repository:
$ git clone https://github.com/vlang/v.git
Enter fullscreen mode Exit fullscreen mode
  • Next, go to v folder and run make:
$ cd v && make
Enter fullscreen mode Exit fullscreen mode

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

  • Third, let's create symlink for it:
$ sudo ./v symlink
Enter fullscreen mode Exit fullscreen mode
  • 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:

$ v up
Enter fullscreen mode Exit fullscreen mode

More about V language

Fresh news

Exercises

  1. Find in V official web site comparison to other languages;
  2. Go to official V Playground 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

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: 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: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.
  • 🏃 yatr: 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: 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: 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: 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.

Top comments (12)

Collapse
 
tarekas profile image
tas

If Go and Rust had a baby it would be this language. Grandpa C should be proud.

Collapse
 
koddr profile image
Vic Shóstak

Haha 😂

Collapse
 
bitsnaps profile image
bitsnaps

The most important thing about vlang, is it has (it should) only "One way to do thing", so the produced code is predictable, hence the possibility of translation from/to C (or possible C++ in the future).

Collapse
 
jeikabu profile image
jeikabu • Edited

I’ve seen a couple other articles about it and am intrigued. It seems to borrow heavily from golang and address several long-standing gripes: null, generics, etc.

They talk about memory safety and management akin to rust, seemingly without the complication of lifetimes. That’s something I’ve wanted to learn more about.

Collapse
 
metalmikester profile image
Michel Renaud

No aliens. :(

Looks interesting. I likely don't have a use for it at the moment, but I like some of the features/goals listed in the introduction.

Collapse
 
koddr profile image
Vic Shóstak

Yes, V is very interesting! When I first read their site, I was pleasantly surprised by everything that was described. No to nil, yes to generics and many more 🎁

Then I tried build some app, but decided not to rush and postponed this article for a couple of months... but after release V UI kit, I understand: V language is not going to be someone else's "pet project"! He's growing!

And I need to help him with this... 😅

Collapse
 
ecmeysam profile image
meysam.ec

Thanks for introducing

Collapse
 
hasii2011 profile image
Humberto A Sanchez II

Thanks for the introduction

Collapse
 
koddr profile image
Vic Shóstak

You're welcome 🙂

Collapse
 
joshuaamaju profile image
Joshua Amaju

Really like the idea, and its simplicity. I can't wrap my head around writing code without any form of classes.

Collapse
 
mudassirbloom profile image
Mudassir

Good to know :) thanks.

Collapse
 
koddr profile image
Vic Shóstak

Yep, this is name of article's series. Hope it helps to learn something new! 🙂