Sign up

Sanity check on idioms

With gtkmm and C++, the trend is away from dynamically created widgets to statically allocated widgets (except when using Glade). GtkD though seems to require use of dynamically allocated widgets since there appears to be no equivalent of statically allocated widget initialization that exists in C++. OK so the GC helps tidy things up instead of relying on RAII or smart pointers, but this is a very different idiom.

Re: Sanity check on idioms

On Thu, 10 Mar 2016 08:23:11 GMT, Russel Winder wrote:

With gtkmm and C++, the trend is away from dynamically created widgets to statically allocated widgets (except when using Glade). GtkD though seems to require use of dynamically allocated widgets since there appears to be no equivalent of statically allocated widget initialization that exists in C++. OK so the GC helps tidy things up instead of relying on RAII or smart pointers, but this is a very different idiom.

Just curious, not being familiar with gtkmm, or C++ for that matter, what does statically allocated mean exactly in this context?

If I had one quibble about GtkD, it would be that it doesn't offer much syntactic sugar on top of the GTK API to integrate and leverage better D idioms like ranges and templates. I assume though that to some extent this is the price you pay for a largely auto-generated API and if so that's a price I'm certainly willing to pay considering it's generally easy enough to provide that sugar yourself when needed.

Re: Sanity check on idioms

On 03/10/2016 09:23 AM, Russel Winder wrote:

With gtkmm and C++, the trend is away from dynamically created widgets to statically allocated widgets (except when using Glade). GtkD though seems to require use of dynamically allocated widgets since there appears to be no equivalent of statically allocated widget initialization that exists in C++. OK so the GC helps tidy things up instead of relying on RAII or smart pointers, but this is a very different idiom.

I'm not familiar with "statically allocated widget initialization",
doesn't gtkmm use smartpointers for classes derived from GObject?

Re: Sanity check on idioms

On Thu, 10 Mar 2016 19:54:30 +0100, Mike Wey wrote:
[…]

I'm not familiar with "statically allocated widget initialization",
doesn't gtkmm use smartpointers for classes derived from GObject?

For widgets constructed via Gtk::Builder all widgets are on the heap with Glib::RefPtr pointers controlling them, as ever. For all manually constructed widgets the idiom is to ensure they are all stack allocated unless there is no option. I.e. use RAII rather than smart pointers unless it is not possible. This saves all the hassle of using std::unique_ptr for ownership – except where you have to do it.

As far as I can tell there is no stack located widget possibility with GtkD.

Of course this is far less important for D than C++ because of garbage collection.