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

Re: [Omaha.pm] Evolution or devolution?



There is such a thing as maintainable code.  I guess a Schwartzian
Transform isn't all that bad.

http://en.wikipedia.org/wiki/Schwartzian_Transform

Sean Baker
Omni Hotels

-----Original Message-----
From: omaha-pm-bounces+pbaker=omnihotels.com@pm.org
[mailto:omaha-pm-bounces+pbaker=omnihotels.com@pm.org] On Behalf Of Jay
Hannah
Sent: Thursday, December 28, 2006 3:29 PM
To: omaha-pm@pm.org
Subject: [Omaha.pm] Evolution or devolution?

Here's three code snippets in 3 different chunks of code that do the
same thing... Is this progress?  :)

j



First example I found...

    my ($common_rate,$cnt);
    foreach my $rate (keys %common_rates) {
      if ($common_rates{$rate} >= $cnt) {
        next if ($rate < $common_rate);
        $common_rate = $rate;
        $cnt = $common_rates{$rate};
      }
    }


Second example I found...

   my ($highest_frequency) = reverse sort values %ratecount;
   @rates = grep { $ratecount{$_} == $highest_frequency } @rates;
   my @common = reverse sort @rates;
   return $common[0];


Code I just wrote:

   print [ sort { $common_rates{$b} <=> $common_rates{$a} } keys
%common_rates ]->[0];



http://cancerweb.ncl.ac.uk/cgi-bin/omd?query=devolution&action=Search+OM
D
_______________________________________________
Omaha-pm mailing list
Omaha-pm@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm