Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

chromatic
  (email not shown publicly)
http://wgz.org/chromatic/

Blog Information [technorati.com] Profile for chr0matic [technorati.com]

Journal of chromatic (983)

Thursday March 15, 2007
02:24 PM

Perl OO Tip of the Day

[ #32699 ]

Methods are not functions. If you call a method as a function, you might get the right results and you might get the wrong results. If the documentation shows you how to call a method as a method and you call it as a function and get the wrong results, that's your fault and you should stop doing it if you care about getting the right results consistently and reliably.

You should especially not file bug reports about getting the wrong results if you use the code incorrectly.

That is all.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • This post sends visions of CGI.pm whistling through my head :-)
    • At least the documentation supports that operation... but a cleaner way to perform the same behavior is to export functions that operate on an automatically-generated singleton, not to try to detect a valid invocant.

      It's funny how you mention that though, as I've written patches for CGI.pm to prevent it from breaking Liskov's substitutability principle.

  • This is not a bug. The documentation clearly indicates that calling $obj->routine() will return a scalar. However, calling Package::routine() is intended to throw a fatal error. This is exactly the results you are getting, and so it is not a bug.

    :)

    It's where you look over the three items of the bug report formula [perl.org] and verify that when the action described in point 1 is taken, the results described in point 3 are correct, and that the expectation described in point 2 is wrong.

    --
    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • One of the biggest mistakes I've made in my stuff on the CPAN is that in Number::Phone and Number::Phone::UK everything can be called as either an object method, a class method, or as a function. Yuck. Add to that that most of the functions (being almost identical, just lookups in a database or calls through to another module) are auto-generated at run-time, and it's a screaming nightmare.

    They really need a re-write.