I’ve started to use Kotlin professionally, and keeping an eye on Rust. Both offer a lot of niceties that I wish we could adapt for Vala, but there’s one that keeps popping up my mind everytime: pattern matching.
The simplest pattern matching we have is C unions, and a lot of c-libs use them. Unfortunately, the current handling of unions in Vala is a disgrace, and there’s no alternative for it. But I believe we can import some syntax from both Kotlin and Rust. Here is my proposal of how should unions work in Vala:
The internal structure (C-wise) of my proposed tagged union is not anything new, it has been done a lot before in C land (here is an explanation from the Rust viewpoint)
I needed a way to emit the
notify signal of one of my objects from another place, and Vala didn’t show me a straightforward way to do it. If you need it for some reason, here’s a code snippet showing you how:
There was a time when Vala was really popular, and a plethora of Vala apps spawned. A lot of them are dead right now, so since i don’t have time to revive any of them, i’ll publish this list of interesting projects in case someone is interested in bringing back one of them:
If you want to use the GTK+ composite templates in Vala, please remember : you have to use a GResource. The syntax is not exactly hard, here’s an example:
<?xml version="1.0" encoding="UTF-8"?>
Which is pretty simple. Let’s say you called that file project.gresource.xml, so to include it, you do (at compile time)
valac --target-glib=2.38 --gresources project.gresource.xml --pkg your_package1 --pkg you_package2 ...
Of course, it can’t be that simple, so first you have to _compile_ that xml file (crazy, isn’t it?), doing
and then include the generated C file. As this won’t scale, and you probably aren’t compiling that way, the documentation suggest to include a make rule for this. So, our make rule should look like this:
project-gresource.c: project.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies project.gresource.xml)
and we can include the generated C file in our valac call:
valac --target-glib=2.38 --gresources project.gresource.xml --pkg your_package1 --pkg you_package2 file1.vala file2.vala project-gresource.c ...
Please don’t forget to read the announcement here for more info.