Optimization Hinders Evolution

Optimization hinders evolution. -- Alan J. Perlis, EpigramsOnProgramming?, SIGPLAN Notices Vol. 17, No. 9, September 1982, pages 7 - 13.

It has long been observed that PrematureOptimization can make difficult such things as reuse and later modification of code. Not only can it make code more difficult to understand for future programmers and maintainers, but optimization can also require unnecessary duplications (loop unrolling, code specialization), breaking encapsulation layers (black boxes have computational cost... see another epigram: "Wherever there is modularity there is the potential for misunderstanding: Hiding information implies a need to check communication." -- Alan J. Perlis), smashing programmatic abstractions (especially layers of abstraction), increasing unnecessary coupling, etc.

When performed by hand, optimizations can make code confusing to read and difficult to modify. The structure often becomes fast but brittle. However, even when the optimization isn't performed by hand, it can hinder evolution. Languages designed to allow for optimizations will have more stringent limitations on how the components are designed, and how components are plugged together; this is difficult to explain, but is easy to observe after playing with such things as Haskell and C++ vs. Python and Smalltalk. Among other things, optimization benefits greatly from static typing of code. Optimization thrives and survives on the ability to make correct assumptions, for it is assumptions that allow the elimination of actions and checks, and if code is structured to make assumptions easier to form, it can be felt by the programmer.

This isn't to say optimization is a bad thing. It is, rather, a trade. For greatest flexibility, future programming languages should allow programmers (or even the runtime environment) to make this trade at any time. Use of TypeInference and SoftTyping help. A language with different compilation modes can help (e.g. both REP interpreter and whole-program linker/optimizer).

See Also: PrematureOptimization, RulesOfOptimization, OptimizeLater


EditText of this page (last edited November 3, 2007) or FindPage with title or text search