3 ms·
And for people who took this to the "next level" just look at GTK.
by aninteger 3y ago
And for people who took this to the "next level" just look at GTK.
- gyrovorbis 3y agoExactly. Amen. GTk is the shining proudest most epic achievement of object-oriented C programming, and they still enjoy massive benefits in terms of being able to interop with every language ever because of this approach.
- pjmlp 3y agoThat would have been Motif and CDE, which Gtk is based on as idea.
- jandrese 3y agoNo seriously, the GTK C bindings are basically written in a half-formed version of the old C++ "C with preprocessor macros" syntax. It looks like this when you program it: GtkWidget* grid = gtk_grid_new(); GtkWidget* label = gtk_label_new("Hello World"); gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1); That GTK_GRID bit is a macro that evaluates at runtime and will chuck out runtime errors if the widget doesn't match. It supports inheritance. If you have for example a gtk_combo_box_text, you can use gtk_combo_box_set_active(GTK_COMBO_BOX(my_combo_box_text), 0) and it will select the first entry in the gtk_combo_box_text because gtk_combo_box_text inherits from gtk_combo_box like any good object oriented system.
- gyrovorbis 3y agoI'm a huge academic fan of what GTk has accomplished (thanks to their GObject type system), and as much as I know the C89 crowd who thinks macros are all evil probably abhor this kind of thing, I think GTk is one of the most epic, impressive, ambitious C codebases in existence. Witness as non-OO C matches, rivals, and quite often beats Qt on equivalent classes/features in plain C... It's even above "just C++ style C," as they have added features like a property and signal system... I'm such a fanboy it inspired my own type system and massive core library, libgimbal, which uses a type system similar to GObject and targets game consoles like the Sega Dreamcast: https://github.com/gyrovorbis/libgimbal https://github.com/gyrovorbis/libgimbal.
- dfox 3y agoMotif/libxm is very similar to that. With two important exceptions: the user code does not use type-checking macros and “stringly-typed” API for set a property to something is more or less a part of the overall ecosystem (well, Xm is just an layer built on top of Xt). Gtk+ was originally an implementation of whatever parts of Motif were used by Gimp, built on an underlying object model that has nothing to do with Xt (which has both good and bad implications).
- opan 3y ago>which has both good and bad implications Could you tell us what these implications are?
- reidacdc 3y agoI remember writing a GTK extension widget many years ago, and yes, it was very much like this. The macros end up making your very own hand-coded vtable-equivalent, so that function calls get dispatched to the appropriate point in the inheritance chain. It was pretty eye-opening!
- deleted 3y ago[deleted]