After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 771838 - bookmark-list: port to G_DECLARE* type declaration
bookmark-list: port to G_DECLARE* type declaration
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: general
3.21.x
Other All
: Normal minor
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks: 771777
 
 
Reported: 2016-09-22 14:57 UTC by Ernestas Kulik
Modified: 2016-09-29 07:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
bookmark-list: port to G_DECLARE* type declaration (3.68 KB, patch)
2016-09-27 10:52 UTC, Sirbu Lavinia Stefania
none Details | Review
bookmark-list: port to G_DECLARE* type declaration (3.72 KB, patch)
2016-09-27 18:25 UTC, Sirbu Lavinia Stefania
committed Details | Review

Description Ernestas Kulik 2016-09-22 14:57:46 UTC
See bug 771777.
Comment 1 Sirbu Lavinia Stefania 2016-09-27 10:52:29 UTC
Created attachment 336346 [details] [review]
bookmark-list: port to G_DECLARE* type declaration

The context of this change is the desire to make the code more easy
to read and understand for newcomers.

The problem is the boilerplate code that reduces the readability of the code.

To fix this use G_DECLARE* type.
Comment 2 Ernestas Kulik 2016-09-27 11:25:01 UTC
Review of attachment 336346 [details] [review]:

LGTM, awesome work :)
Comment 3 Carlos Soriano 2016-09-27 12:37:02 UTC
Review of attachment 336346 [details] [review]:

Nice work Lavinia! 

It needs some work, here's the review. Feel free to ask any questions you might have.

About the commit message:
"The problem is the boilerplate code that reduces the readability of the code." It's actually more about being able to use g_autoptr and the new smart pointers, which are not possible with old classes.
Also, the context part lacks what we are doing right now. So I would write something like: "Currently we are using the old GObject class declarations, which have two problems." Then in the problem paragraph "One is that we cannot use smart pointers like g_autoptr. The other problem is that has more boilerplate, which makes the code less readable."

::: src/nautilus-bookmark-list.c
@@ +194,3 @@
                       G_TYPE_FROM_CLASS (object_class),
                       G_SIGNAL_RUN_LAST,
+                      0,

Why this change? We need the offset to be able to override the signal handler in subclasses (although currently we are declaring this final type, which means not sub classing allowed, we still have the public signal handler in the header). Also, the docs say:
"The closure to invoke on signal emission; may be NULL.". Although NULL == 0, we shouldn't rely on that and use NULL if necessary.

@@ +197,2 @@
                       NULL, NULL,
+                      NULL,

Why NULL to the marshal? Using NULL will let glib try to guess the marshaller, which is worse than explicitly tell what marshaller is using.

::: src/nautilus-bookmark-list.h
@@ +30,3 @@
 #include <gio/gio.h>
 
+G_BEGIN_DECLS

Although this is fine, it's not necessary for this change. In the docs of G_BEGIN_DECLS says for what it is, in case you didn't check yet.
Leave it in the patch since is nice to have it.
Comment 4 Ernestas Kulik 2016-09-27 12:45:32 UTC
(In reply to Carlos Soriano from comment #3)
> Review of attachment 336346 [details] [review] [review]:
> 
> Nice work Lavinia! 
> 
> It needs some work, here's the review. Feel free to ask any questions you
> might have.
> 
> About the commit message:
> "The problem is the boilerplate code that reduces the readability of the
> code." It's actually more about being able to use g_autoptr and the new
> smart pointers, which are not possible with old classes.
> Also, the context part lacks what we are doing right now. So I would write
> something like: "Currently we are using the old GObject class declarations,
> which have two problems." Then in the problem paragraph "One is that we
> cannot use smart pointers like g_autoptr. The other problem is that has more
> boilerplate, which makes the code less readable."
> 
> ::: src/nautilus-bookmark-list.c
> @@ +194,3 @@
>                        G_TYPE_FROM_CLASS (object_class),
>                        G_SIGNAL_RUN_LAST,
> +                      0,
> 
> Why this change? We need the offset to be able to override the signal
> handler in subclasses (although currently we are declaring this final type,
> which means not sub classing allowed, we still have the public signal
> handler in the header).

With the class struct removed, the offset can be 0, as we are no longer associating any class method slot with the signal (from the docs, verbatim).

> Also, the docs say:
> "The closure to invoke on signal emission; may be NULL.". Although NULL ==
> 0, we shouldn't rely on that and use NULL if necessary.

What are you quoting, exactly? It is the offset, not the closure.

> @@ +197,2 @@
>                        NULL, NULL,
> +                      NULL,
> 
> Why NULL to the marshal? Using NULL will let glib try to guess the
> marshaller, which is worse than explicitly tell what marshaller is using.

GLib uses the generic marshaller in that case.
It is used in some places, but specified explicitly.

> ::: src/nautilus-bookmark-list.h
> @@ +30,3 @@
>  #include <gio/gio.h>
>  
> +G_BEGIN_DECLS
> 
> Although this is fine, it's not necessary for this change. In the docs of
> G_BEGIN_DECLS says for what it is, in case you didn't check yet.
> Leave it in the patch since is nice to have it.
Comment 5 Carlos Soriano 2016-09-27 12:56:18 UTC
Thanks Ernestas. Everything you said is right, sorry for the confusion. Except:

> 
> GLib uses the generic marshaller in that case.
> It is used in some places, but specified explicitly.
> 

As said I prefer a explicit marshal.

So Lavinia, just modify the marshal and the commit message and it looks good to me :)
Comment 6 Sirbu Lavinia Stefania 2016-09-27 18:25:23 UTC
Created attachment 336381 [details] [review]
bookmark-list: port to G_DECLARE* type declaration

Currently we are using the old GObject class declarations, which have two
problems.

One problem is that we cannot use smart pointers like g_autoptr. The other
problem is the boilerplate code generated that makes the code less readable,
so harder to understand.

To fix this use G_DECLARE* type.
Comment 7 Carlos Soriano 2016-09-28 09:12:31 UTC
Review of attachment 336381 [details] [review]:

Good job, thanks!
Comment 8 Carlos Soriano 2016-09-29 07:34:57 UTC
Pushed to master. Congrats on your first accepted contribution Lavinia!

Attachment 336381 [details] pushed as dcd4eb3 - bookmark-list: port to G_DECLARE* type declaration