[PBP-pm] Named constants from modules?

Stuart Jefferys srj at email.unc.edu
Fri Nov 18 19:27:34 PST 2005


This is my first post here. Hope it works...

The Conway PBP book recommends using named constants in place of  
magic numbers. This is a standard practice across many languages. The  
"Readonly" module is suggested as way to make these constants really  
constant. However, the book also recommends against allowing export  
of any variables from modules. I agree in principle, but as named  
constants are implemented as variables the two practices are at odds.

If that was the limit of the problem, I would just skip the  
recommendations and export "named constant" variables when needed.  
However, there is a convenient package for exporting subroutines from  
a module (Perl6::Export::Attrs) that *explicitly* avoids allowing the  
export of variables. This seems very 'un-perlish', and actually  
prevents me from using the package to do something I believe to be  
unquestionably correct. I have added a "request for feature" to that  
module on CPAN to allow export of named constants if they are read only.

Anyone have any thoughts on this?

Also, I have never tried it, but it just occurred to me -- what  
happens upon export of "Readonly" tagged variables anyway?


      "Physics, mathematics, and chemistry - they are all just  
frameworks. Biology is different because it's the content that matters."

Stuart Jefferys - Graduate student
UNC - Curriculum in Genetics and Molecular Biology;
UNC - Bioinformatics and Computational Biology


More information about the PBP-pm mailing list