-
Drinkers of the World.. uh.. Mix Drinks!
2005-03-18 11:32 in /random
I’ve been saying someone should build this for years. Too bad they’re probably going to get cease-and-desisted out of existence.
(More generally, I really want cookbooks to stop being distributed (solely) in hardcopy. I’d much prefer to buy a datafile, in a standard format, that I can load into a “What can I make tonight?” program.)
-
use vars
, dammit!2005-03-18 11:00 in /tech/perl/HallOfShame
Or
our
if you prefer. Whatever you do, don’t refer to variables in the current package using the full, explicit package name. Concretely, don’t say,@My::Package::ISA = qw( My::SuperClass );
Instead, write
our @ISA = qw( My::SuperClass );
or
use vars qw( @ISA ); @ISA = qw( My::SuperClass );
The problem with the first is that it is typo-prone. If you typo the package name,
perl -cw
won’t complain (in fact, perl will happily do exactly what you said), but you’ll get errors like ‘Can’t locate object method “foo” via package “My::Package”’. This is particularly likely to happen when you create a new subclass and copy the old subclass to use as a template. The alternatives are typo-proof, and easier to read to boot.(BTW, this is a specific case of the general principle Don’t Repeat Yourself. In this case, you already typed the package name once in the
package
directive. Doing it again anywhere else in the file is just asking for trouble sometime later.)
Leave a comment
Please use plain text only. No HTML tags are allowed.