Glib constants as barewords

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Glib constants as barewords

oldtechaa
Hello everyone,

I had a quick question about the reason for using Glib constants vs declaring your own. I could do this:

use Glib qw/TRUE FALSE/;

or I could do this:

my ($TRUE, $FALSE) = (1, 0);

The second way would have the advantage of not being a bareword and being clearly defined in the code. What reasons are there to use the Glib way, especially if I'm not directly using anything from Glib?

oldtechaa
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Glib constants as barewords

Brian Manning-2
On Wed, Jun 28, 2017 at 9:23 AM, oldtechaa <[hidden email]> wrote:
> Hello everyone,
>
> I had a quick question about the reason for using Glib constants vs
> declaring your own.

If you're not using any other features from Glib besides the boolean
constants, it's probably not worth importing the module; you can use
something like the `constant` pragma in core Perl [1] to do the same
thing.

Thanks,

Brian

[1] http://perldoc.perl.org/constant.html
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Glib constants as barewords

oldtechaa
Thanks Bryan. I just wondered since two of the GTK3 tutorials on gtk2-perl doc page recommended loading Glib, even only for the booleans. I personally am fine with the constant method in perlstyle with all-caps as constants, simple and no-fuss.

oldtechaa
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Glib constants as barewords

Jeff
On 29/06/17 05:36, oldtechaa wrote:
> Thanks Bryan. I just wondered since two of the GTK3 tutorials on
> gtk2-perl doc page recommended loading Glib, even only for the booleans.
> I personally am fine with the constant method in perlstyle with all-caps
> as constants, simple and no-fuss.

Surely, for a Gtk3 project, Glib is being loaded anyway (at least by
Gtk3), and is therefore no extra overhead. Whilst in the past, at least,
the overhead for the constant module was significant.

Regards

Jeff



_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Glib constants as barewords

oldtechaa
Thanks Jeff. That's probably true about the Glib module and constant. I figure why not skip both and just use variables with all-caps as constants. (Horrible, I know. But hey, it's what perlstyle recommends!) Clean, no barewords (which I think are far worse and especially more confusing than my method), and pretty much no overhead!

To each his own. For someone else, The Right Way may be different. TIMTOWTDI.

oldtechaa

On June 29, 2017 11:37:59 AM EDT, Jeff <[hidden email]> wrote:
On 29/06/17 05:36, oldtechaa wrote:
Thanks Bryan. I just wondered since two of the GTK3 tutorials on
gtk2-perl doc page recommended loading Glib, even only for the booleans.
I personally am fine with the constant method in perlstyle with all-caps
as constants, simple and no-fuss.

Surely, for a Gtk3 project, Glib is being loaded anyway (at least by
Gtk3), and is therefore no extra overhead. Whilst in the past, at least,
the overhead for the constant module was significant.

Regards

Jeff



_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Glib constants as barewords

oldtechaa
In reply to this post by oldtechaa
That's true, Shawn, but in this/my particular case, these variables are unlikely to be overwritten (who would redefine $TRUE and $FALSE?) and since this is an OSS project, I don't want more dependencies (use constant isn't really recommended, apparently) and I can define a standard coding style, so anytime anyone sees all-caps they should not be overwriting. Again, that's this particular case. In other cases it may not be desirable.

By the way, great link. I think I saw it once a while back and only looked at the most recommended modules like Readonly, constant, and Const::Fast.

Thanks,
oldtechaa
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Loading...