Posted by brian d foy on October 2, 2011
Programmers generally consider two types of error communication: the “modern” and shiny exception throwing, and the old and decrepit return values. When they consider these, they choose one and forsake the other. One is good, and the other is bad. Programmers won’t agree on which is which though. The return value technique comes from older [...]
Posted by brian d foy on September 18, 2011
When you’re using code references heavily, you’re going to have a problem figuring out which one of them is having a problem. You define them in possibly several and far-flung parts of your program, but when it comes to using them, you don’t know which one you are using. You can’t really print its value [...]
Posted by brian d foy on July 3, 2011
Perl 5.16 makes the Perl special variable, $$, writeable, but with some magic. That’s the variable that holds the process ID. Why would you ever want to do that? There’s not much to write about with this new feature, but there’s plenty to write against it since it introduces more magic (see commit 9cdac2 on [...]
Posted by brian d foy on May 22, 2011
Perl lets you override the effects of warn and die by redefining the signals that Perl sends when you call those functions. You probably don’t want to use the signal from die, though, since it might mean a couple of different things. You handle these special signals by setting values in the %SIG hash just [...]
Posted by brian d foy on May 8, 2011
Is your object-oriented module subclassable? Do you know that from testing or are you just guessing? Setting aside other Perl programmers reaching into your package and redefining your subroutines, there are some basic things you can do to ensure that you’ve made life unhard for the people you want to extend your classes. If you [...]
Posted by brian d foy on April 17, 2011
Perl 5.10 introduced a flexible method resolution order mechanism. Instead of Perl’s default order (see Understand Perl’s default inheritance model), you can try something less stupid by using the mro pragma to specify which order perl. So far, there are only two resolution orders: dfs, which is Perl’s default depth-first search, and c3, a new [...]
Posted by brian d foy on March 20, 2011
Perl’s default inheritance mechanism is a bit weird, and it’s not something that any language designer would want to repeat. However, it is what it is and by knowing its quirks you should have any easier time tracking down inheritance problems. Before you go further in this Item, though, you have to sit through this [...]
Posted by brian d foy on February 6, 2011
Data::Dumper, a module that comes in the Standard Library, is one of the great tools knows to Perlers. You give it a big data structure and it pretty prints it for you. If you are one of those people who still believe that the best debugger in the world is print and need to get [...]
Posted by brian d foy on December 5, 2010
How often have you wished that one of Perl’s modules did things slightly differently? That module mostly works for you except for some hard-coded decisions in string formats, pack specifications, or other minor point that you wish that you could configure. Or, maybe you’ve been the one to write that module. When you have to [...]