bramaudi

Learning vlang, exploring vweb

Table of contents

For context, I'm web developer and my first programming language was PHP and recently mostly writing on Javascript since they grow too fast and let you write fullstack app with just one language that are already familiar for all web devs.

Currently I looking at V language, it is compiled language similar to C++ and Go, already try Go little bit and I got it confusing especially about the syntax, for me Go it's kinda weird.

So far I really enjoy coding in V, remind me when I was learn PHP for the first time but this time since I already have a fundamental knowledge about programming it goes smoother.

Here are what I learned so far about V:

Differences from other languages

Unlike language I already know like Javascript/Typescript, Java, Python, and PHP, the V language have a few different things on:

How it works

V are compiled language like C++, Go, and etc. If I want to develop web project I must write, compile, then run in order.

That's mean there are no feature like hot-reload when you edit the code and instantly see a page changes, you must do server restart and browser restart to see changes, but fortunately V have built-in powerful web framework called vweb that have live reload features.

Live reload is different from hot-reload, it's just allow you to automatically recompile and restart the http server on code changes but still this is very important & useful things.

Project Structure

In V, all files under the same folder are considered as a module and have ability to share function/method, no need to import or export things between files if it's in same module.

Your app will always run main function in main module, you can have multiple modules in your project and import it in your main module but otherwise it impossible to import main in other module under the same project, if you want you only can passing down the main context to others.

No class, use struct

There is no concept of class in V, but they have struct which seems like a types for me but with actual ability to impact the actual code, yeah since it compiled language.

You can add a method in struct, doing that like so:

struct App {
  name string
}

fn (app App) say() {
  println(app.name)
}

fn main() {
  x := App{
    name: 'Bram'
  }
  x.say()
}

My personal reasons of choosing V

Every language have it own pros and cons, some even best for their own purpose, like PHP for the Web, Python for data scientist, etc. But V from what I see V is general purpose programming even supporting wide context of programming (Web, Native App, Machine Learning).

Easy styntax

Compared to similar language, the V syntax is pretty easy and clean in my view, I want to try lern Rust before but damn that syntax are scary, but I heard they have nice performance & good error message. Go, once try it a bit and really similar to V but syntax are kinda weird to me, but they are stable and have mature ecosystem tho.

I even already created blog engine just in a month from scratch.

Small size compiler

V claim the have a small compiler size, here are the table from their table from their official site vlang.io:

SpaceBuild time
Go525 MB1m 33s
Rust30 GB45m
GCC8 GB50m
Clang90 GB60m
Swift70 GB90m
V< 20 MB< 1s

Above comparison got when this post is written.

Have many built-in libraries

With that such small compiler it included a lot of built-in libraries that will useful to develop your project.

It's different from "standard library", let say I want to develop a web project, most language will only provide standard library like example http package to work with http request / response and running http server, you still need to implement the basics like route, middleware & auth, etc or simply by using third-party library to have better experience when code is getting more complex in your project, in V they have vweb module, a built-in web framework that provide the fundamental needed for web development.

Having something like vweb is like you have an official way of developing rather than implement in your own way, but you can still always have the freedom to create an abstraction to you application if you want or inventing a new framework.

Compiled language

This my first time using compiled language and I enjoy V, as web developer I start my first programming in PHP and then JavaScript with all of their ecosystem like frontend / backend library, devtools, buildtools, etc.

And this my first time compiling a web app into one single binary, something that I don't even know before, I know that because I'm installing miniflux, I was inspired by it then and start looking new way of developing web project and found V.