Python & Poetry <was Dr. Dobb's Python-URL! ...(Mar 26)>

Lemniscate d_blade8 at hotmail.com
Wed Mar 27 18:54:58 EST 2002


FYI, this is a very interesting topic to me, so this post is a bit on
the long side with little-to-no technical aspect.

Geoff Gerrietts <geoff at gerrietts.net> wrote in message news:<mailman.1017255224.10677.python-list at python.org>...
> Quoting Gon?lo Rodrigues (op73418 at mail.telepac.pt):
> > On Tue, 26 Mar 2002 20:04:50 -0800, Geoff Gerrietts
> > <geoff at gerrietts.net> wrote:
> > 
> > >Quoting Courageous (jkraska at san.rr.com):
> > >> 
> > >> >I'd say the skills required to write clear, readable
> > >> >software and clear, readable novels are not entirely
> > >> >disjoint!

I agree, but with a slightly different twist.  There is a skill in
writing prose, just as there is a skill in writing poetry and they do
not always seem to go hand in hand (many great poets could not be even
lackluster prose writers and this_statement.reverse() ).  However,
there is basic skill that both emcompass and that is the skill of
conveying an idea.  A truly obscure and obfuscated story or poem isn't
really interesting unless the reader can identify with the idea in
some way.  Incidently, this is related to why, historically, some
poets looked down at prose as a mode of expression (poets, they
argued, convey ideas, thought, emotion while prose writers had to be
concerned with conveying the plot).  It's all about what ideas we are
trying to convey...
 
> > Poetry and coding are similar in that they are both creative activities
> > needing inteligence, imagination, etc. But there is also a world of
> > difference between the two. A simple way to see this is how they relate
> > to their heritage, their common dead.

In our case, coding is conveying an idea of a behavior to the
computer.  Once again, the conveyance of an idea is the main
objective.  Now, just as any writer will tell you, you convey your
point best when you use the least amount of information required.  I
agree very much with this point; it is very much like the performance
art of magic, my other paid 'hobby' (I've previously seen a thread on
"Is magic poetry?" so I don't want to rehash it here, but I do have a
point).  The method of conveying an idea is at least as important as
the idea itself; any decent magician will tell you that poor
showmanship by the magician can kill the best trick in the world even
if the trick itself was performed flawlessly.  The same can be said of
coding.

There are various old thereoms and ideas about short code using less
memory and being faster and the like (I'm just using this an example,
I am not making the argument one way or the other).  But the fact
remains that the quicker and cleaner that one can communicate the idea
they want to the computer, the quicker the computer may respond
(please note:  the response phase is omitted in this statement, I am
merely referring to the time until the computer can begin its
response)

> Writing code is a lot like writing a poem, with a vocabulary that is
> extremely restricted and formal requirements that are invariably
> rigid. The sense of meaning one derives from a program is generally
> more pragmatic than what one gets from a poem. But both are
> appreciated as much for what they say as for how they say it. 

Excellent point.  If we all remember back to learning about poetry and
the Bard's use if iambic pentameter (let us assume, for now, that WS
did all his own writing), we will recall how strict poetry can be.  A
haiku is another great example.  One must be both a linguist and a
puzzle-teer (what do you call somebody who does a lot of puzzles?). 
Writing code is the same way.

There is a python book, I seem to think it is "Python Annotated Code"
(or something like that), that has the code for determining if a
number is a prime.  Let us say the number is x.  It takes the approach
of dividing the number by every number x/2 and below (except for 1)
and checking for a remainder (no remainder means the number is evenly
divisible, thus not prime).  This code works, but could be made to run
much faster by using math.sqrt(x) instead of x/2 as the first number
(this is a mathematical property of numbers, a number that has
multiple larger than its square root has one that is smaller [e.g. 100
has 50 and 2, 25 and 4, 20 and 5].  Additionally, one could start at 2
and increment up to the square root (another property of numbers, more
numbers are divisible by 2 than by 3 in a sequential series of at
least four numbers; this will reduce the amount of time needed to find
more numbers).
When I saw the alternative way to compute primes (I saw the x/2 method
first, somewhere else long ago), I thought that here was a perfect
example of how code could be poetic.  It made me understand what was
meant by the term 'elegant' code.

> One notable difference between programming and poetry is that a
> programming cliche is acceptable, a rote that people are encouraged to
> re-use, whereas dropping someone else's clever turn of phrase into
> your poem is likely to backfire.

As mentioned before, this can be the same argument used for why code
is not the same as prose (you aren't supposed to plagarize).  However,
coding styles can be likened to poetic styles (the aforementioned
haiku or iambic pentameter).  One could also make the argument (and I
am NOT) that the use of symbols in poetry is equivalent to the reuse
of code in coding.  One takes advantage of something that is already
there and draws further information to or from it (see how this works
whether one is talking about modules or an albatross necklace?).

> 
> I'm still a long way from a thesis, but I think the similarities are
> pretty astounding.
> 
> Maybe that thesis isn't so many years off, after all....
> 
> --G.



Very nice and thought-provoking
D



More information about the Python-list mailing list