C & Free Software & Hacking Gustavo Sverzut Barbieri on 09 Aug 2006 09:46 pm
GLib is a technical disaster
Yes, you read it right: GLib is a technical disaster. After some time working with it, both using, building upon and hacking its internals, you can see the mess.
One thing that really piss me off is people that, instead of solving problems, create more problems that they call a “work-around”. GLib just do that: compiler-aided OO languages were badly supported in GCC? Let’s fix GCC? No, let’s create OO atop C, using a lot of pre-processor, make things cumbersome, error-prone, … POSIX and its GNU/LibC implementation lacks features? Let’s create a whole new string, list and hash implementation! Oh, and do not forget that missing printf(), make it g_print()!
I’m not a C++ enthusiast, but I do think it or ObjectiveC or any other compiler-aided Object Oriented language would help. Anyone that already implemented GObject subclasses know what I’m talking about. The very first thing you’ll notice is that you have to copy and paste too much code, but still have to change little bits here and there, making the process error-prone. Then you have the pre-processor macros and if you already worked with them or read Linux kernel position on it, you know it’s a mess and should be avoided. And how about a dynamic type system using C? Yes, GLib does have that, making things slower, bigger and impossible to compiler to optimize virtual-tables and dispatchers! And back to GCC, it’s now good enough and improving support for OO languages, but GLib/GObject will win nothing, GCC still handle it as regular procedural code.
Insanity doesn’t stop there, some Software Engineer Guru wanted to have “private” fields and yes, they also did it, even worse: they seem to incentive that! Any experienced hacker must know that this is just bullshit… and when you’re dealing with barebone C, where you have direct access to memory, you just think “they’re playing jokes”. Let’s suppose you could protect memory regions, why would you protect it? Against developers? Why? This idea must came from a non-programmer, because any programmer should know what to do and this just make debugging and testing more difficult. But let’s face it: C doesn’t offer any way to protect memory regions, so all you have to do is to have pointer to an area and use it… but they like the ClassNamePrivate, that just make things bigger, slower and painful to debug. If Operating System Kernels, that deals with critical data, don’t do any fancy stuff to “protect” it, why GLib guys do?
Still looking how BSDs and Linux relates to GLib and GObject, you can see that the kernels have saner implementation of linked lists, trees and hash tables. They also have clever Object Oriented code (vfs and others). Weird enough, hacking Linux or BSDs kernels are much easier when you compare easy-of-use and consistency of APIs.
How about namespaces and method resolution? Why would I use a language that supports that? It’s so cool to use gtk_label_set_text() or filling your mind with Object Hierarchies! Of course it’s gtk_misc_get_padding() if I’m dealing with a GtkLabel. When using these functions you may also opt to use casts and make it even more error prone or to use those GTK_LABEL()-like macros, that do function calls and some branches.
Just to make it clear: I know other languages and libraries have problems too. Qt is another good example on how-to-not-fix-the-proper-problem: stl is broken, let’s re-implement it! Why use namespaces, it’s just one letter! Let’s require user to pre-process their code (moc). However any of these are excuse, GLib has is a technical disaster because it tries to solve the wrong problem.
6 Responses to “GLib is a technical disaster”
Leave a Reply
You must be logged in to post a comment.
on 10 Aug 2006 at 3:40 am 1.lemody said …
this was quite nice to read … and i bet it was written after coding something in frustration
i have to agree that if there are object oriented languages available why try to force C act like one? after all, you can always use C from C++ (like pretty much every C++ developer does).
on 10 Aug 2006 at 4:52 am 2.Cwiiis said …
I’ll have to disagree with this, I’ve been using GLib for a while, and while I agree that some bits are clunky (especially GObject), I’ve found it nothing but a joy to use over straight C, C++ with stl and Java.
GLib re-implements a lot of standard functions and objects for cross-platform compatibility - There aren’t many frameworks that are as easy to use and can boast such wide platform support.
Even taking your points on board, I think the phrase ‘technical disaster’ is a bit much too
on 10 Aug 2006 at 8:16 am 3.Gustavo Sverzut Barbieri said …
cwiis:
I agree GLib has useful basic data structures, but POSIX does have that and POSIX is a standard, so you can implement it anywhere you want. Also, GNU/LibC guys do have extensions, check for _GNU_SOURCE, so you can do more if you want.
But my main rant about these basic data structures is that they’re not that easy to use, if you check Linux Kernel implementation you’ll see they have a much nicer API.
on 10 Aug 2006 at 2:38 pm 4.Pete said …
To complain that Glib reinvents many standard c library functions is to forget that Glib runs on such a wide variety of platforms that these functions become far from “standard”.
So the applications can now use the one definition of Glibs standard functions. Or rely on a mountain of “./configure” and preprocessor macros to get everything right.
I’ll take Glib’s functions. Thanks.
on 10 Aug 2006 at 3:11 pm 5.Gustavo Sverzut Barbieri said …
“The nice thing about standards is that there are so many of them to choose from.
“ — Andrew S. Tanenbaum
Why not just implement POSIX standard where it lacks? Makes more sense to me.
In that fashion, why we should port GCC for another arch, we should write our own compiler.
on 04 Sep 2006 at 7:53 am 6.ecky.l said …
Nice post - perfectly right ;-).
The idea o glib as a platform independent library is fine - still there are others, with a much cleaner and better documented API (I am talking of Tcl)
Making C object oriented is just ridiculous and stupid, IMO. The whole GObject branch.. keep it away! But well, being a computer professional always means to get the best out of compromises between different subjective opinions - and it was this way for sure, when GObject was invented…