in reply to Re^2: Clever vs. Readable
in thread Clever vs. Readable
You are of course free to code as you choose, but don't invoke the justifiction of reliability.
The day I cannot correctly code my $min = $a < $b ? $a : $b; is the day I'll go looking for a CPAN module to do it.
At the same time I'll go looking for something to help me with:
if( $a < $b ) { ## Do what is required when $a is the lessor } else { ## Do what is required when $b is the lessor }
Any thoughts? Maybe you'd code that as if( min( $a, $b ) == $a ) ...?
But when I've a nut to crack, it stays in the toolkit.
#! perl -slw use strict; use X; use List::Util qw[ min ]; my $a = X->new( .5, .5, .5, 1 ); my $b = X->new( .7, .9, .4, 1 ); print $a < $b ? 'a is the lessor' : 'b is the lessor'; print "\n-------\n"; print min( $b, $a ); __END__ [ 0:38:13.97] c:\test>junk3 a is the lessor ------- Argument "X=ARRAY(0x1824550)" isn't numeric in subroutine entry at c:\ +test\junk3.pl line 10. Argument "X=ARRAY(0x2251a4)" isn't numeric in subroutine entry at c:\t +est\junk3.pl line 10. X=ARRAY(0x1824550)
Even ignoring the warnings, did min() get the answer right? And if it did, was it for the right reasons or just some fortuitous accident that'll come back and bite once it goes into production?
|
---|