Why I use the V language

 


Why do I use V? It is new, not proven, nor particularly popular. In this post I will explain why I use it, and why you should too!

First, a quick introduction to the language. V is, quoting from the official documentation, a "statically typed compiled programming language designed for building maintainable software. It's similar to Go and its design has also been influenced by Oberon, Rust, Swift, Kotlin, and Python.". It is a modern language, and prides itself on simplicity. However, I think it achieves the balance between powerful and easy. But not every language does, in my opinion.

For example, Python. The first language I learnt, you can learn the basics of Python fairly quickly, and I would imagine if I had learnt another language first I would have learnt the basics even faster. However, there are a few things I don't like about Python. 

Here are two:

  1. It is interpreted. Though there exist methods to try to solve this problem, (for instance pyinstaller), the truth is that Python was not designed to wind up in one little executable.
  2. It has many ways to do one thing. For example, take printing the elements of a list. Here are 4 ways that the average Python dev would probably know:  
my_list = [1, 2, 3, 4, 5]

# Using a For Loop
print("Using a For Loop:")
for item in my_list:
print(item)

# Using List Comprehension
print("\nUsing List Comprehension:")
[print(item) for item in my_list]

# Using Map and Lambda Function
print("\nUsing Map and Lambda:")
list(map(lambda x: print(x), my_list))

# Using While Loop
print("\nUsing While Loop:")
index = 0
while index < len(my_list):
print(my_list[index])
index += 1

Take a second language, C. I learnt C, and I think it is still a very valuable and relevant skill today, though some people disagree with me on this! Though C has problems too. One that is often mentioned is the lack of a package manager and a modular ecosystem. This probably contributed to the below stereotype!

 

 

 

 

 

 

 

 

 

Another problem with C lies in the language design. C is full of unpredictable behaviour, for example:

// Uninitialized Variables
int x;
printf("%d\n", x);

// Out-of-Bounds Array Access
int my_array[5] = {1, 2, 3, 4, 5};
int value = my_array[5];
printf("%d\n", value);

// Null Pointer Dereference
int *ptr = NULL;
printf("%d\n", *ptr);

// Division by Zero
int a = 10;
int b = 0;
int result = a / b;
printf("%d\n", result);

// Modifying String Literals
char *str = "Hello";
// This line would result in a compilation error
str[0] = 'h';
printf("%s\n", str);

// Type Mismatch in Format Specifiers
int y = 10;
printf("%f\n", y);

This leads to code that is in many places unintelligible, or hard to maintain. C also does not have sufficient error catching mechanisms, leading to undefined behaviour that could potentially get pushed to prod, and cause major issues. C's vast array of libraries and headers are also ripe for confusion if you don't know the man command!

 

Having learnt both these languages pretty well and having built a decent amount of stuff in them, I knew it was time to branch out into a modern language. The first one I tried was the one that probably comes to mind at the phrase "modern language" - Rust. I did not like Rust, as it seemed to be very complex, like C++ which I have never really liked. After persisting for a bit, I switched course to Zig. I liked Zig more, as it made more sense and allowed me to work with my existing code, written in C, more. However, I disliked the way it used imports, and it still had the problem that Python has, in that there are multiple ways to do things. Also, Zig does not support strings very well, which in my opinion disqualifies it from the following claim on their website - being a "general-purpose programming language". Strings are very much the norm now, and while Zig might be good for low level software, it lacks support even at the level of the char * in C.

After trying Zig, I found V. I had previously written my own toy language in Python, which compiled to C, and V, I found, was not dissimilar in terms of syntax. It felt very powerful, and had all the features I wanted. One claim stood out to me: that there was usually only one way to do things. V is a self-described very simple language, yet is obviously very powerful, and compiles to human readable C code, allowing for interoperability. There are some key differences in V to languages like Python, one big one I found was immutability by default. At first, I had trouble accepting this, but I think having done some more programming in V, I have come to appreciate why this is a useful feature. It makes for more predictable software, and less runtime errors. If I was writing, for example, a web server using vweb, I would want no errors, no undefined behaviour. V does this for you! Since V compiles down to C, this is quite a feat, and even so it does not lose much speed - compiled with the -prod flag, V is just as fast as C or C++, and even with just "Hello, world!" is at least thrice as fast as Python!

V is not perfect yet, but since it has not reached v1.0, that makes sense. Another useful element of the V ecosystem is its package manager, vpm, and its vast array of builtin libraries. However, I would not recommend V yet for mission critical applications, as it is still at v0.4 at time of writing. But as a student of programming, I have no such qualms just yet!

I hope you enjoyed, and see you next time!





Comments

Popular posts from this blog

Upcoming Guest Opinions Post!

color gets updated!