Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Miscellanea > Encapsulated Cleverness - Pg. 454

While that's certainly an improvement in both readability and efficiency, it still requires some careful thought to verify that it's doing the right (i.e., minimizing) thing. And everyone who maintains this code will still have to decode that expres- sion--possibly every time they come across it. However, it's also possible to write that same expression in a way that's so obvious, straightforward, and plain-spoken that it requires no effort at all to verify that it implements the desired behaviour: use List::Util qw( min ); $optimal_result = min($result1, $result2); It's not "clever" and it's even marginally slower, but it is clean, clear, efficient, scal- able, and easy to maintain. And that's always a much better choice. Encapsulated Cleverness If you must rely on cleverness, encapsulate it. Very occasionally a genuine need for efficiency may (appear to) make it essential to use non-obvious Perl idioms such as: # Make sure the requests are unique...