This article is out-of-date. See [expressivity].
The elegance of a program is a factor of bytes of code (shorter the
better), completeness (does it handle corner cases?), and respect for
the underlying hardware (shouldn't be thrashing the hardware). "Readability"
is another, arguable, component, yet most elite programmers will probably
agree, that if you can't understand it, yet it succeeds all of the
aforementioned tests, the problem of readability is yours.
Since the number of bytes of code is dependent on the language constructs that
your programming environment provides, it is dependent upon and related to
your language's [expressivity].
Elegance can be calculated thusly: 2/#_of_equivalent_programs. Since most
systems are CPU-deficient and memory-rich, we can further refine this as the
most CPU efficient...
The closer this is to 1.0, the closer code is to its maximum elegance.
One should also discuss what is meant by "equal programs". I mean, the number
of programs fluent programmers of the language agree that are the good and
equivalent solutions to the problem. Whether the output should be the same for
every input is untested (there may be good solutions that don't include every
extreme case). Languages which have a large number of equal programs say
something interesting about either the programming language or the types of
programmers the language attracts.
Side-talk for the newbies...
There is always at least two equivalent programs to a given programming task:
one that optimizes space and one that optimizes time. Hence, the numerator is
2.
See also:
Wiki: Algorithmic Information Theory
Wiki: engineering
Wiki: expressivity
Wiki: kolmogorov quotient