
GObject - tosh
https://en.wikipedia.org/wiki/GObject
======
pavlov
GObject always felt like a poor man's Objective-C to me.

It's a shame that the language was so completely sidetracked in '90s open
source Unix development. I suspect part of the blame goes to GNUstep's
ambitious overreach. Maybe if they had just focused on an Obj-C widget toolkit
instead of building an entire NeXT look-a-like desktop, it would have been
more palatable to the wider community.

~~~
camus2
Obj-C is nice, but it's not like they couldn't use C++.

So why not just C++? why this obsession with C even when it makes no sense?

~~~
pavlov
Traditionally C++ hasn't had a stable ABI. Object code from different
compilers and even compiler versions has been incompatible. That made it a no-
go for system frameworks.

It's the same in Apple land: macOS uses a lot of C++ internally, but it's all
wrapped into plain C APIs using an object system called CoreFoundation (which
is IMO better than GObject because it was designed for "toll-free bridging"
with Objective-C, so there is a low-friction path to a higher level language).

There have been operating systems that built their APIs in C++. BeOS and
Symbian are the most notable ones. Both ran into serious trouble with the ABI
being tied to a specific compiler, which in practice made it hard to port
newer GCC or Clang.

~~~
andrioni
How did Microsoft solve it with their C++ APIs? I've never ventured much into
Windows programming, but I remember hearing that MFC uses C++, and newer stuff
is mostly C++-based.

~~~
thriftwy
They carry around their bridge library called MSVC redistributable, and that
one is tied to compiler version. Fortunately for them they don't release
compiler versions too often, but stuff you have on your Windows install
perhaps carries around half dozen of MSVC redistributable library sets.

All Windows APIs are still C (stdcall to be precise) with some COM.

~~~
pjmlp
> All Windows APIs are still C (stdcall to be precise) with some COM.

Only if we are speaking about until Vista.

With Vista the majority of Win32 API are only COM, not "with some COM", even
the userspace drivers are COM.

WinRT introduced in Windows 8, nowadays rebranded as UWP, is also COM.

Of course one can be masochist and make use of the low level C compatible COM
bindings, or embrace ATL, WTL, C++/CX or the new C++/WinRT and enjoy
productivity.

~~~
thriftwy
During my life I didn't meet a single person who understood COM and could
program with it.

That's it, just sayin'. Maybe it IS awesome. It's just unreachable.

Borland made a fortune by making COM go away for a subset of tasks. After
that, DotNet.

~~~
gecko
I don't think it's unreachable, and I know plenty of devs who understood COM.
I think the issue was a mixture of failing to match expectations combined with
very poor marketing (specifically, shoving too many things under the umbrella
of COM).

What people _wanted_ COM to be was a way to share binary objects as
DLLs—basically what the grandparent was assuming was actually the case on
Windows. And at its simplest, COM is _almost_ that. But what it actually did
was provide something very different: a way to tell the OS, "Hey, I need you
to give me an object that does X," where X was an interface you wanted the
object to conform to, and then the OS would give you such an object, which you
could address only by its interface. This is nothing more than factories/IoC
in modern parlance, but it was new and confusing then, and people got
frustrated.

Then, on top of that, Microsoft threw in a pile of other concepts. For
example, if you want to use COM for system services, then, in the right
situations, multiple people asking for a given interface could be given _the
exact same object_ —and this at a time when lots of devs weren't used to
working with threading. And also, to accomplish that, you were doing local
RPC, so here's also a full serialization framework, which you're probably also
not used to. And also because now things are multithreaded a lot of the time,
here's a way you can make your COM object single-threaded (think Java's
synchronized keyword).

Nowadays, most of this isn't a big deal. Devs are used to RPC (via HTTP/JSON
or things like gRPC and Thrift). They're used to factories and IoC. They're
used to a single shared "object" being used by multiple processes in multiple
services. But at the time, it was a lot of new stuff _all at once_ , and I
think it was just too much.

~~~
pjmlp
Ah the days of DCOM and MTS. :)

------
jonathankoren
Shudder. I remember looking st this 15 years ago, and it's a cruel joke. I
understand why writing in C made multilingual bindings easy, but the
ergonomics of GObject are horrible. You're stuck doing all the crap that real
OO type system does, setting up vtables and what not. Most insulting, they
dismiss(ed) all complaints as mere "syntactic sugar".

Ironically, I liked GTk+ back when I was doing that kind of stuff.

~~~
tsarfox
I agree. Using GTK+ for a small personal project made me realize just how
unwieldy GObject is. Vala was a nice alternative, in my opinion, but it seems
that everyone is trying to kill it off nowadays.

~~~
VMG
> but it seems that everyone is trying to kill it off nowadays.

What do you mean?

~~~
tsarfox
At least in the GNOME ecosystem:
[https://mobile.twitter.com/ebassi/status/827482509982195712](https://mobile.twitter.com/ebassi/status/827482509982195712)

------
_RPM
GObject is the most interesting source code in C I've read.

~~~
vanderZwan
Could you explain? I'm probably not familiar with C to get why even if I tried
it myself.

------
pritambarhate
A little bit offtopic: I am somebody who has programmed in memory managed
programming languages for all of my career. (With exception of Obj-C for a
couple of years before ARC)

I recently wanted to try my hand at C. But was surprised that there isn't a
Boost like lib for C.

What is a good generics/data structures library for C? Glib is one option. But
it is supposed to be hard to use. Apache Portable Runtime seems to be another
option. I read somewhere that its memory pools were considered to be a bad
design and were supposed to be removed in the newer implementation. But the
current stable version seems to use them.

~~~
emmelaich
There's also NSPR (Netscape Portable Runtime). Still maintained after all
these years.

[https://developer.mozilla.org/en-
US/docs/Mozilla/Projects/NS...](https://developer.mozilla.org/en-
US/docs/Mozilla/Projects/NSPR)

