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
- Story of V;
- Hello World;
- Main features of language;
- 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!')
}
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!')
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())
}
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]
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.
Plugins for V syntax on popular code editors
Okay, time to try V on your computer!
- First, go to console and clone V repository:
$ git clone https://github.com/vlang/v.git
- Next, go to
v
folder and runmake
:
$ cd v && make
On Windows,
make
means runningmake.bat
, so make sure you usecmd.exe
.
- Third, let's create symlink for it:
$ sudo ./v symlink
- That's all! 😉 V was installed to
/usr/local/bin/v
path and available to call byv
.
Update V
For update V to latest version, simply type on console:
$ v up
More about V language
- GitHub repository — https://github.com/vlang/v
- Official docs — https://vlang.io/docs
Fresh news
- Twitter — https://twitter.com/v_language
- Telegram — EN, RU, IT, ZH
Exercises
- Find in V official web site comparison to other languages;
- Go to official V Playground and write some code;
- 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)
If Go and Rust had a baby it would be this language. Grandpa C should be proud.
Haha 😂
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).
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.
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.
Yes, V is very interesting! When I first read their site, I was pleasantly surprised by everything that was described. No to
nil
, yes togenerics
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... 😅
Thanks for introducing
Thanks for the introduction
You're welcome 🙂
Really like the idea, and its simplicity. I can't wrap my head around writing code without any form of classes.
Good to know :) thanks.
Yep, this is name of article's series. Hope it helps to learn something new! 🙂