[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] @_[1..$#_] is that evil? -laugh-



Jay wrote:
> Should I make these each 5 liners instead?

Whenever I ask myself that question I find that "yes" is the correct answer in the end. ;-)

As nice as the single line solution is, are you going to be the one that will be the sole caretaker of this section of code until the day it dies --  the day _YOU_ die is not an option! :-) If not, do the others on your team have a similar comfort level with this code?  In general, I ask myself this question: "At 3:30 AM, will we be able to look at this code and understand it with minimal thought?"

On the other hand, if this code is called a for each line in a million-row database lookup for each query, which one is faster?  That might be the key -- if so, you might want to put a comment in that readability was sacraficed for speed in this case.

Dan

On Wed, March 22, 2006 12:09, Jay Hannah wrote:
> Wow. Is this readable? I think this is the first time in my life I've
> intentionally used $#_ (or any $#x for that matter...)
>
> sub set_rate_single {
> $_[0]->SUPER::set_rate_single($_[0]->rate_split_shrinker( @_[1..$#_])) }
> sub set_rate_double {
> $_[0]->SUPER::set_rate_double($_[0]->rate_split_shrinker( @_[1..$#_])) }
> sub set_rate_xperson {
> $_[0]->SUPER::set_rate_xperson($_[0]->rate_split_shrinker(@_[1..$#_])) }
>
> Should I make these each 5 liners instead?
>
> j
>
>
> The long way would be:
>
> sub set_rate_single {
> my ($self, @rates) = @_;
> my $result = $self->rate_split_shrinker(@rates);
> return $self->SUPER::set_rate_single($result);
> }
> ...ditto double
> ...ditto xperson
>
>
> _______________________________________________
> Omaha-pm mailing list
> Omaha-pm@pm.org
> http://mail.pm.org/mailman/listinfo/omaha-pm
>


- - - -
"Wait for that wisest of all counselors, time." -- Pericles
"I do not fear computers, I fear the lack of them." -- Isaac Asimov
"Soon we will be able to harness the rotational energy from Orwell's grave to solve all world energy problems." -- /. user GigsVT (208848)
GPG fingerprint:6FFD DB94 7B96 0FD8 EADF 2EE0 B2B0 CC47 4FDE 9B68