[Tutor] Readabilty vs 80 characters
Russel Winder
russel at winder.org.uk
Thu Apr 19 17:04:43 CEST 2012
On Thu, 2012-04-19 at 16:00 +0200, Peter Otten wrote:
[...]
> Seriously, learn that you don't need backslashes if you put the expression
> into parens, precalculate parts of the expression and put them into
> temporary variables -- and if that doesn't suffice to keep the code readable
> and below the 80 char threshold reread the part of the PEP with the Emerson
> quote ("A foolish consistency...").
I agree that where there is a backslash in a Python program, there is a
better layout that doesn't have it. I wouldn't agree though that,
necessarily, decomposing long expression using temporary variables
improves anything. A good fluent API leads to function call chaining,
far fewer variables, and far more readable code. Much of the time, not
always, of course.
There is currently a definite trend (*) away from 1960s FORTRAN style
code structuring, to a 1980s Miranda (think Haskell and Scala) type
thinking about how to structure code. There is experimental evidence in
psychology of programming that declarative expression leads to more
easily comprehensible code. This isn't advocacy research as much of
programming research has been. Even C++ is going to a more declarative
mode of expression, along with Java. Python's list comprehensions fit
into this trend.
(*) Which may turn out just to be just the latest fashion ready to be
replaced in 2013.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/tutor/attachments/20120419/1c6da357/attachment.pgp>
More information about the Tutor
mailing list