I love
Scalar::Util and
List::Util. They allow me to do stuff in a cleaner, clearer, and more abstract fashion, which is what good code is all about.
Until I tried to convert the following code:
use UNIVERSAL qw( isa );
....
my $is_blah = isa( $thing, 'Some::Class' ) && $x == 3;
...
if ( isa($value, 'HASH') || isa($value, 'ARRAY') ) {
# Do something here
}
I tried to convert that code to the following:
use Scalar::Util qw( blessed reftype );
...
my $is_blah = blessed( $thing ) eq 'Some::Class' && $x == 3;
...
my $r = reftype( $value );
if ( $r eq 'HASH' || $r eq 'ARRAY' ) {
# Do something here
}
Except, that code isn't equivalent. Both reftype() and blessed() return undef, not the empty string. So, the most obvious use for reftype() and the second most obvious use for blessed() don't DWIM. Plus, ref() returns the empty string, which means they don't behave as the internal they're supposed to replace.
So, now I have to do (blessed($thing)||'') and my $r = reftype($value)||'; How annoying!
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.