Meet Val: A New Language Alternative to C++, Rust

Val is a new high-level programming language that runs close to the metal. It’s the brainchild of Dimi Racordon, a post-doc researcher at Northeastern University who focuses on language design and type-based approaches for memory safety.
It started as a byproduct of research she did with Google and Adobe on the Swift programming language and the discipline of mutable value semantics, which upholds the independence of values to support local reasoning. Haskell, Rust and R are other examples of languages that use mutable value semantics.
“This is a project that started around two years ago. I wrote the paper, I collaborated with great people at Google and Adobe,” Racordon told The New Stack. “After this paper, I had a small idea in the back of my head and I thought, oh, we’ll try implementing some stuff, it will be a two, three weeks project. And it’s been two years.”
Why Another Programming Language?
Nothing else does quite what Racordon wanted. She started with Swift, because she already knew it and Swift supports mutable value semantics. It checked a lot of other boxes she wanted as well, such as compiling to machine code, making it good for systems programming. But also undermines the value semantics because it mixes it with other things, she added. That made Racordon wonder what would happen if she made a language that was purely about mutable value semantics.
“Mutable value semantics is a programming discipline that really focuses on notional values. So if I have an array of things, for example, the value of this array is the most important concept that I want to manipulate,” she said. “That gives me local reasoning.”
To really understand why the approach is needed, Racordon said, consider reference semantics, which is the other approach used by modern programming languages, especially imperative languages, such as C++, JavaScript, Python and Java. These languages distinguish between primitive data types, such as integers or strings sometimes. Those types behave like values, she said. Changing the value of an integer doesn’t create an observable side effect to some other place in the program. That’s not the case for other data types, such as aggregates, arrays or hash maps, because they have reference semantics.
“What happens is, if you pass an array to a function in Python, and then this function goes on to change the array, maybe adding an element, or removing some element from this array, then this effect can be observed from the outside of the function,” she explained. “The caller of the function will have its own array being changed. You cannot reason locally about values because every time you call a function, some side effect might occur in a seemingly unrelated part of your program.”
That makes it difficult to apply local reasoning for humans, which makes it harder to be sure that programs are correct, she said. But it also makes it difficult for compilers, because optimizers now need to be very conservative about what can happen, she said. The optimizer has to account for the fact that other references might exist and that some seemingly unrelated part of the program might need the value that is being mutated, so it’s best not to do anything rather than compromise that reference architecture.
The Value of Mutable Value Semantics
This is where mutable value semantics becomes useful. Mutable value semantics removes the references from the picture, she explained. But it preserves in-place mutation, which is very efficient.
“For instance, if you want to sort an array in place, you don’t want to build a bunch of new data structures and try to recombine them,” she said. “That kind of pure functional model will put a lot of pressure on your optimizer to recover the lost efficiency. You want to do things in place, because allocating a lot of pieces of memory and recombining them together will be very slow.”
That provides a very transparent performance model, which is very good for humans and compilers, she said.
“Mutable value semantics removes these references from the picture, you only have values and a bunch of techniques that you could use to preserve sufficient expressiveness.t looks like functional programming, but what you really want to preserve is in place mutation, because in place mutation is very efficient,” she said.
Why Val
The language is designed for systems programming — so primarily it’s for any application that runs close to the metal and needs to squeeze the most possible performance from the machine, Racordon said.
That includes uses such as operating systems, memory-intensive applications such as video games or image processing, and other applications that can’t afford a virtual machine or a garbage collector. Embedded applications would also be “a very interesting target,” she said.
“One issue with embedded systems is that it’s a very fractured ecosystem because it’s almost one system, one CPU, one architecture,” Racordon said. “It’s really difficult to have a general-purpose language for all of them. So yes, sure, it might work. But we would have to maybe specialize for a particular target if we really want to squeeze the most possible performance.”
Val isn’t something that would be used on the client’s side, but it might, for instance, be used to embed something like Photoshop in the web browser via LLVM and then Web Assembly. Val has a similar compilation pipeline to C++.
The open source language is available on GitHub but is still being created. Racordon is looking for contributors who want to “get their hands dirty” by evolving the language. The roadmap is online, although a bit behind schedule — they’re still working on creating an alpha version for developers to experiment with, for instance. The goal is to make it possible to download a compiler and write an app by year-end, she said.
Racordon said Val will fit in the same use cases as C++ and Rust, but hopefully without the safety problems of C++ and the complications of Rust.
“They have taken the wrong approach to solve the issue. They’re taking the approach of trying to police references and have a type system that makes using them is safe,” she said. “Whereas with Val, we said, let’s get rid of references, because references are the issue and so we have a far simpler model.”