http://www.perlmonks.org?node_id=162869


in reply to Idiomatic optimizations

Beyond performance improvement, some of these transformations usually render your code "more correct" (for some suitable definition of correct). Your first point, for example, about unnecessarily quoting variables: in my experience, it's a left-over bad habit of shell programmers. It can lead to errors in strange circumstances, particularly if $foo is an object, and the stringify operator does something you didn't expect, or you didn't realize the stringified version is not the same as the object itself.

More than optimizations, I would categorize these as "Refactoring". Generally speaking, it means changing code without adding functionality, but improving it in some fashion, such as making it easier to maintain. Fowler has an entire book on the subject. Although it uses Java, some of the principles apply to other languages as well.

I recall brother chromatic was working on a refactoring editor for Perl, based on using the B back-end compilers to generate a uniform code tree, then applying these types of changes. He referred to it in his journal on use perl, but I don't know its current state (though I'm sure it'll be thoroughly tested when it's released ;-).