gtkapplang: First two pages

Conflicts:
	pages.yaml
This commit is contained in:
Charles Magahern
2025-08-24 17:21:11 -07:00
parent a2d5b8cb44
commit 1afb4d5fa6
5 changed files with 115 additions and 0 deletions

53
assets/css/gtkapplang.css Normal file
View File

@@ -0,0 +1,53 @@
#article-header {
background-color: #0d0d0d;
color: white;
text-align: center;
padding: 5pt 0 5pt 0;
}
#article-header > div {
display: inline-block;
vertical-align: middle;
margin: 5pt;
}
img#gtk-logo {
width: 50px;
}
#article-body {
columns: 2;
font: 10pt/1.40 Helvetica, sans-serif;
padding: 5pt;
}
#article-body p {
text-indent: 2em;
}
#article-body p:first-child {
margin-top: 0;
text-indent: 0;
}
/*
span.first-word {
font-size: xx-large;
font-weight: bold;
line-height: 0;
}
*/
h1, h2, h3 {
margin: 2pt;
text-align: left;
font-family: Helvetica, sans-serif;
}
h3 {
font-weight: normal;
}
.code {
font-family: monospace;
}

BIN
assets/img/logo-gtk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

View File

@@ -2,5 +2,7 @@
- cover.html - cover.html
- bouba.html - bouba.html
- gtkapplang-1.html
- gtkapplang-2.html
- drivingmissmuni.html - drivingmissmuni.html

35
pages/gtkapplang-1.html Normal file
View File

@@ -0,0 +1,35 @@
<link rel="stylesheet" href="assets/css/gtkapplang.css" />
<div id="body" class="page-base">
<div id="article-header">
<div>
<img id="gtk-logo" src="assets/img/logo-gtk.png" />
</div>
<div>
<h1>Linux GTK Apps</h1>
<h2>A Language Comparison</h2>
<h3>by P. Michael Cho</h3>
</div>
</div>
<div id="article-body">
<p><span class="first-word">A</span> famous hacker once said, "Linux is only free if your time has no value." Well, anyone who knows me knows that my time is about as worthless as a bag of salt. Thus, I really had nothing to lose when I decided to ditch the glitzy, glamorous commercial OS'es and go all-in on Linux this year.</p>
<p>It's really not that bad in 2025. Maybe it really is the <em>Year of the Linux Desktop.</em> A lot of stuff just works out of the box. You don't have to waste a whole weekend getting sound to work in YouTube videos. X11 isn't really a thing anymore, so fiddling with ancient hieroglyphic <strong>Xorg config files</strong> is no longer required just to get your anime girlfriend wallpaper desktop to show up on the screen.</p>
<p>Emboldened with a new sense of optimism for the Linux desktop, I decided to try writing a few <strong>native apps</strong> to see what the developer ecosystem is like. <strong>GTK,</strong> formerly known as the <strong>GIMP ToolKit,</strong> appears to be the de-facto widget toolkit for creating native GUI apps on Linux, so I decided to learn and explore how to develop apps using this toolkit.</p>
<p>The first problem I encountered was a severe sense of language paralysis. There are many, many choices of programming languages when developing GTK apps, which isn't necessarily a good thing. Apple doesn't always do everything right, but upholding Swift as the one true language for developing macOS and iOS apps reduces a lot of fragmentation for developers. A walled garden keeps the snakes out! Nevertheless, I decided to try and write a few small apps in a variety of different languages to see which one feels the best.</p>
<h4>C (Rating: B-)</h4>
<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>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>
</div>
</div>

25
pages/gtkapplang-2.html Normal file
View File

@@ -0,0 +1,25 @@
<link rel="stylesheet" href="assets/css/gtkapplang.css" />
<div id="body" class="page-base">
<div id="article-body">
<p>Unfortunately this honeymoon phase quickly came to an end. Writing in C requires a <strong>lot</strong> of boilerplate code, and significant use of <strong>macros,</strong> against which I am generally ideologically opposed. For every "class" type that you define in your app, you have to implement several functions: one that initializes the class itself with the runtime, another for handling dynamic setting of properties, another to handle getting those properties, one for initializing instances of that class, and one for destroying or "finalizing" instances of that class. Confusingly there are two different functions for destroying objects, one called <strong>finalize</strong> and another called <strong>dispose,</strong> and I guess this was done to eliminate cycles in the reference counting mechanism implemented by GObject. Big yuck.</p>
<p>I eventually did finish the app I was writing in pure C, but it was a shitload of code. There are probably a couple of memory leaks too. One great thing about writing in C is that compiling the code is basically instantaneous. I actually started to feel angry and upset thinking about how much time we waste compiling code in newer languages. Do people know that complex C programs take only a few seconds to compile? Debugging was excellent too. GDB just works and I can see everything. Overall a pretty good experience I would say.</p>
<h4>C++ (Rating: C-)</h4>
<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>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>Another disappointment was the documentation for gtkmm and glibmm. Just atrocious. Looks like autogenerated Doxygen slop. Come on guys, it's not 2008 anymore.</p>
<p>One positive thing I will say about using C++ is that memory management is a lot more tolerable than C. Using the <span class="code">Glib::RefPtr</span> smart pointer class instead of manually managing GObject lifecycles is a blessing.</p>
<p>I did end up finishing this project as well and the end result was satisfactory. Overall I didn't really have a lot of fun writing C++, but then again, who does.</p>
</div>
</div>