Re: Accessors vs Properties

2017-01-05 Thread Tobias Knopp
Hi,

so you mean that the getter/setter usually internally calls the dynamic 
„property“ version where the property is passed as a string?
Thus it would make sense that language bindings are fine using the 
get/set_property methods since there is no overhead.

Best regards,

Tobias


> Am 05.01.2017 um 08:27 schrieb Gergely Polonkai :
> 
> Hello,
> 
> I don't know about others, but in my own code, my_obj_set_property() does 
> nothing else just calls the setter functions (and the same for getters). It 
> makes much more sense, and I saw it in a lot of Gtk and Gnome code, too.
> 
> Best,
> Gergely
> 
> 
> On Wed, Jan 4, 2017, 19:27 Tobias Knopp  > wrote:
> Hi,
> 
> I am working on Gtk language bindings for the Julia programming language 
> (https://github.com/JuliaGraphics/Gtk.jl 
>  
>  >) and have a question regarding the 
> accessor methods (methods with „get“ and „set“ in them) and the property 
> system.
> 
> - Is any accessor backuped with a property and vice versa?
> - Which one is to prefer?
> 
> I tried to find documentation on this but have not found anything.
> 
> Thanks,
> 
> Tobias
> 
> 
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org 
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list 
> 
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Accessors vs Properties

2017-01-05 Thread Tobias Knopp
Thanks, do you know what the Python gtk bindings (3.x) are using?

Tobias

> Am 05.01.2017 um 11:05 schrieb Debarshi Ray :
> 
> On Tue, Jan 03, 2017 at 10:46:13PM +0100, Tobias Knopp wrote:
>> - Is any accessor backuped with a property and vice versa?
> 
> Nicola already answered this.
> 
>> - Which one is to prefer?
> 
> It depends.
> 
> For simple setting and getting of values from C, I prefer the
> accessors because (a) it lets the compiler do some minimal type
> checking (b) accessors are more efficient at returning a C string than
> g_object_get. However, you need properties if you want to have a
> 'parametrized constructor'. ie. pass arguments to a *_new function.
> 
> Properties are more convenient from higher-level languages. eg., in
> JavaScript, you can use my_obj.prop to access a property.
> 
> They also offer extra features:
> 
> (a) You can bind a property on one object to another property
> elsewhere (see g_object_bind_property*).
> 
> (b) Every property comes with its own 'notify' signal that you can use
> to listen for changes.
> 
> (c) They can be introspected at run-time, which is very useful if you
> are writing a tool like the gtk+ inspector, glade or d-feet.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessors vs Properties

2017-01-05 Thread Debarshi Ray
On Tue, Jan 03, 2017 at 10:46:13PM +0100, Tobias Knopp wrote:
> - Is any accessor backuped with a property and vice versa?

Nicola already answered this.

> - Which one is to prefer?

It depends.

For simple setting and getting of values from C, I prefer the
accessors because (a) it lets the compiler do some minimal type
checking (b) accessors are more efficient at returning a C string than
g_object_get. However, you need properties if you want to have a
'parametrized constructor'. ie. pass arguments to a *_new function.

Properties are more convenient from higher-level languages. eg., in
JavaScript, you can use my_obj.prop to access a property.

They also offer extra features:

(a) You can bind a property on one object to another property
elsewhere (see g_object_bind_property*).

(b) Every property comes with its own 'notify' signal that you can use
to listen for changes.

(c) They can be introspected at run-time, which is very useful if you
are writing a tool like the gtk+ inspector, glade or d-feet.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessors vs Properties

2017-01-05 Thread Nicola Fontana
Hi,

Il Tue, 3 Jan 2017 22:46:13 +0100 Tobias Knopp  scrisse:

> ...
> - Is any accessor backuped with a property and vice versa?

Only the second part stands, i.e. any property should have its
own accessors. There is some exception though, e.g.
GtkContainer:child, but that is a special property anyway (it is
write-only).

> - Which one is to prefer?

They are equivalent. Sometime you can encounter missing accessors,
so I'd use g_object_{set,get}_property(), more so if you plan
to do some automatic processing (e.g. writing binding code).

Ciao.
-- 
Nicola
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessors vs Properties

2017-01-05 Thread Nicola Fontana
Il Thu, 05 Jan 2017 07:27:10 + Gergely Polonkai  
scrisse:

> Hello,
> 
> I don't know about others, but in my own code, my_obj_set_property() does
> nothing else just calls the setter functions (and the same for getters). It
> makes much more sense, and I saw it in a lot of Gtk and Gnome code, too.

Hi,

at least in GTK+ it is the other way, i.e. the setters call
gtk_*_set_*():

https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.6#n3684

Ciao.
-- 
Nicola
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessors vs Properties

2017-01-04 Thread Gergely Polonkai
Hello,

I don't know about others, but in my own code, my_obj_set_property() does
nothing else just calls the setter functions (and the same for getters). It
makes much more sense, and I saw it in a lot of Gtk and Gnome code, too.

Best,
Gergely

On Wed, Jan 4, 2017, 19:27 Tobias Knopp  wrote:

> Hi,
>
> I am working on Gtk language bindings for the Julia programming language (
> https://github.com/JuliaGraphics/Gtk.jl <
> https://github.com/JuliaGraphics/Gtk.jl>) and have a question regarding
> the accessor methods (methods with „get“ and „set“ in them) and the
> property system.
>
> - Is any accessor backuped with a property and vice versa?
> - Which one is to prefer?
>
> I tried to find documentation on this but have not found anything.
>
> Thanks,
>
> Tobias
>
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list