gtkapplang: Pages 3 and 4, final edits

This commit is contained in:
Charles Magahern
2025-08-24 18:09:05 -07:00
parent 0f0bba5e1b
commit 1e9cb584c5
6 changed files with 57 additions and 2 deletions

View File

@@ -46,8 +46,15 @@ h1, h2, h3 {
h3 { h3 {
font-weight: normal; font-weight: normal;
font-style: italic;
} }
.code { .code {
font-family: monospace; font-family: monospace;
} }
.endmark {
text-align: center;
margin-top: 1em;
color: #555;
}

View File

@@ -4,4 +4,6 @@
- bouba.html - bouba.html
- gtkapplang-1.html - gtkapplang-1.html
- gtkapplang-2.html - gtkapplang-2.html
- gtkapplang-3.html
- gtkapplang-4.html

View File

@@ -27,7 +27,7 @@
<p>The first language I decided to try is an oldie-but-goodie. Just plain ol' C. Linux guys really like C, and really hate pretty much every other language, and the GTK toolkit itself is implemented in C, so it seemed like a good first choice.</p> <p>The first language I decided to try is an oldie-but-goodie. Just plain ol' C. Linux guys really like C, and really hate pretty much every other language, and the GTK toolkit itself is implemented in C, so it seemed like a good first choice.</p>
<p>One cool thing about GTK is that it is based on runtime library called <strong>GLib,</strong> which implements a bunch of object-oriented design patterns in C. It defines an object model, lifetime semantics, and a bunch of commonly used data structures that you can use in your app. Object-oriented programming is definitely out of style nowadays but I still think it is a solid paradigm for developing user interfaces. For example, it makes sense conceptually for all widgets to inherit from a base class that defines things like screen geometry and parent-child relationships.</p> <p>One cool thing about GTK is that it is based on runtime library called <strong>GLib,</strong> which implements a bunch of object-oriented design patterns in C. It defines an object model, lifetime semantics, and a bunch of commonly used data structures that you can use in your app. Object-oriented programming is definitely out of style nowadays but I still think it is a solid paradigm for developing user interfaces. It makes sense conceptually for all widgets to inherit from a base class that defines things like screen geometry and parent-child relationships.</p>
<p>My first couple of hours with C were glorious. The code was just falling out of my hands. The language is so simple, it's nearly impossible to waste any time on design.</p> <p>My first couple of hours with C were glorious. The code was just falling out of my hands. The language is so simple, it's nearly impossible to waste any time on design.</p>

View File

@@ -11,7 +11,7 @@
<p>Linux guys are going to hate me for even mentioning C++, but I of course had to give it a try. Despite its numerous flaws, it's still the best bang for your buck when it comes to offering reasonably good object-oriented features with very fast performance.</p> <p>Linux guys are going to hate me for even mentioning C++, but I of course had to give it a try. Despite its numerous flaws, it's still the best bang for your buck when it comes to offering reasonably good object-oriented features with very fast performance.</p>
<p>For using GLib and GTK in C++ I decided to use the <strong>gtkmm</strong> library, which implements a variety of C++ bindings for all of the classes in the toolkit. Along with that I also used glibmm and giomm which are required to use the GLib and GIO dependencies in C++ code.</p> <p>For using GLib and GTK in C++ I decided to use the <strong>gtkmm</strong> library, which implements a variety of C++ bindings for all of the classes in the toolkit. Along with that I also used <strong>glibmm</strong> and <strong>giomm</strong> which are required to use the GLib and GIO dependencies in C++ code.</p>
<p>I was immediately disappointed to learn that a ton of boilerplate was still required just for defining some basic data types with properties. Properties are an important abstraction in GObject that let you bind data to various widgets, so this isn't something that can be easily avoided. Basically for each data member in your class, you need <strong>three accessor functions</strong>: two that 'get' and 'set' the data itself, and a third that returns a reference to the <span class="code">Glib::Property</span> object representing that member.</p> <p>I was immediately disappointed to learn that a ton of boilerplate was still required just for defining some basic data types with properties. Properties are an important abstraction in GObject that let you bind data to various widgets, so this isn't something that can be easily avoided. Basically for each data member in your class, you need <strong>three accessor functions</strong>: two that 'get' and 'set' the data itself, and a third that returns a reference to the <span class="code">Glib::Property</span> object representing that member.</p>

29
pages/gtkapplang-3.html Normal file
View File

@@ -0,0 +1,29 @@
<link rel="stylesheet" href="assets/css/gtkapplang.css" />
<div id="body" class="page-base">
<div id="article-body">
<h4>Rust (Rating: C+)</h4>
<p>Of course I cannot go without mentioning the fad language of the decade: <strong>Rust.</strong> I was actually pretty excited to try using Rust to write a GTK app. The users and designers of the language alike are very opinionated, Rust programs are usually very high quality, and I generally like the overall design of the language and the standard library.</p>
<p>I decided to use the <strong>gtkrs</strong> crate for my Rust app, which was trivial to setup using Rust's excellent build system. From what I can tell, a majority of the code in gtkrs is automatically generated, so there isn't a lot of manual wrapping done, which is quite nice.</p>
<p>First impressions were very positive. Just like with C++, memory management was straightforward and conventional. I didn't waste a lot of time allocating objects and passing them around the library. The designers of gtkrs did a really good job in creating the bindings while also making them memory safe, which is very much concordant with the Rust philosophy.</p>
<p>Significantly less boilerplate was required with Rust as well, thanks to macros provided by the <span class="code">glib</span> crate like <span class="code">property</span> and <span class="code">object_subclass</span>. Getter and setter functions are optional and mostly for convenience.</p>
<p>So why did I give Rust a <strong>C+</strong> rating? The main reason is because Rust is not an object-oriented language. It feels really unnatural to shoehorn object-oriented design patterns into Rust when it was clearly designed not to support that. Of course, it <em>kinda works,</em> and you can finish your app with some pretty nice code to maintain, but it feels sort of like writing classical poetry in LaTeX.</p>
<p>I finished writing my app in Rust and felt pretty good about it, but to be honest I did have to rewrite large parts of it multiple times. It took me a few tries to figure out how to make the compiler happy while still keeping things "Rusty" if you'll pardon the phrase.</p>
<h4>Vala (Rating: B)</h4>
<p>The last language I tried was one I've never heard of before, and probably you haven't either. <strong>Vala</strong> is an object-oriented language that is built by the GNOME team and sits on top of the GLib runtime. It has the standard set of nice-to-have features in modern languages such as async/await, generics, and type inference. It also has a few features that are specifically designed to interact nicely with the GObject runtime, such as signals and properties.</p>
<p>Another cool thing about Vala is that all of your code gets cross-compiled to decently human-readable C code. So there isn't a lot of worry about cross-platform support, debuggability, or performance, at least compared to C.</p>
<p>Vala has by far the least amount of boilerplate of all the languages I tried. Because it natively supports properties, your data classes and widget subclasses are extremely minimal and easy to understand.</p>
</div>
</div>

17
pages/gtkapplang-4.html Normal file
View File

@@ -0,0 +1,17 @@
<link rel="stylesheet" href="assets/css/gtkapplang.css" />
<div id="body" class="page-base">
<div id="article-body">
<p>Documentation for Vala and its libraries is pretty good too. All of it is hosted at the <strong>Valadoc</strong> website which is really easy to search and has a nice layout. I can tell that quite a lot of it is autogenerated from the C documentation, so sometimes it's a bit awkward to read the parts written in prose, but overall not bad.</p>
<p>It's quite easy to create Vala bindings to C libraries, especially if those C libraries are also implemented using the GLib runtime and use GObjects. You create these little files called <strong>VAPI</strong> files and the compiler does most of the work for you. By far one of the easiest FFI's I've ever used.</p>
<p>I think the only thing I really don't like about Vala is that the language itself doesn't really <em>spark joy.</em> For language connoisseurs like myself, it just feels kind of <em>meh.</em> From what I can tell that was actually one of the goals of the language. The designers didn't really set out to push the boundaries of programming language theory with Vala, and instead just wanted a simple language that makes it easier to write apps. I respect that.</p>
<p>Another weird and perhaps surprising disappointment is that every LLM I tried is very poor at generating Vala code. There is actually quite a lot of Vala code out on the Internet, and so statistically speaking it seems likely that it would be part of some training data. My theory is that because a lot of these Linux guys still have a beef with Microsoft, they refuse to upload a lot of code to Github which is the primary website from where code gets scraped. If someone trains an LLM with all the code on these little Gitlab instances, I'm excited to try it.</p>
<p>Overall I found Vala very pleasant to use. I think if the community hivemind were to select a language as its primary language for GTK development, it would be Vala. Just make sure to brush up on your hands-on-the-keyboard coding skills, since you won't be able to <em>vibe-code</em> your way out of some problems with Vala. <span class="endmark"></span></p>
</div>
</div>