The Zen of D.E.K.

avi.e.gross at gmail.com avi.e.gross at gmail.com
Sat Jan 14 12:16:57 EST 2023


I can appreciate a beautiful piece of code but I can also appreciate another
piece of code that does things in another pleasing way so there is quite a
bit of subjectivity here.

And, in yet another computer language, the implementation of what seems to
be the same algorithm is somewhat jarring as it does not quite fit the
environment.

Some people consider the symmetry of a language that ends an IF statement
with FI to be sort of pleasing. Others feel that way about matched opposing
braces and yet others like having things the same symbol such as an
unadorned double quote or slash to be both the beginning and end.

It goes way deeper than that but I think there is plenty of subjectivity in
what people find pleasing. Some adore it if an algorithm is a very curt and
mysterious one-liner while others like when code is lined up just so on
multiple lines, perhaps using a nice color scheme in their editor. Some
adore copious detailed comments while others find they get in the way.

Efficiency is another matter but again has some subjectivity and variations.
The same algorithm can be much more efficient in one language/implementation
than another but also in other ways can be less. If an algorithm must sort a
billion items, the algorithm may dominate the resources used. But to sort a
small number of items, the overhead of invoking and loading an external
module that has a faster method than the built-in way, may be much slower if
used only once.

In the real world, there are other candidates for what is in some sense
better to do. One example is how fast it can be designed and implemented and
another might be if it tends to generate fewer bugs and glitches. A big one
is if it saves the company money in creating and maintaining it or at
runtime. And, of course, a good algorithm implementation is one that others,
perhaps less extremely educated than you, can later read your code and
understand it well enough to modify it, or perhaps port it to another
language with different ways than the one you wrote it in.

Efficiency keeps being relative as languages evolve. A change in the
interpreter may add features that end up making the feature you chose to
slow a bit. Replacing some functionality with a version written in a
language like C that is compiled, can often speed it up. Changing an
algorithm from using a list to a numpy array can have dramatic differences
even as the skeleton of the algorithm remains the same in terms of
aesthetics.

Amusingly, I have been reading about ideas of Aesthetics and sort of beauty
by Mathematicians and Physicists in how it guides them in their work. Knuth
and others in C.S. are arguably doing similar things.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org> On
Behalf Of Ethan Furman
Sent: Friday, January 13, 2023 1:00 PM
To: python-list at python.org
Subject: Re: The Zen of D.E.K.

On 1/13/23 09:06, Stefan Ram wrote:

 >    "Beautiful is better than ugly." - The Zen of Python
 >
 >    This says nothing. You have to sacrifice something that
 >    really has /value/!
 >
 >    "[A]esthetics are more important than efficiency." - Donald E. Knuth

[okay, falling for the troll bait]

Those two things do not say the same thing; further, in Python at least, and
depending on the situation, aesthetics may /not/ be more important than
efficiency.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list