Object Relational Mappers are evil (a meditation)

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Dec 21 18:42:49 EST 2009


On Mon, 21 Dec 2009 11:44:29 -0500, J Kenneth King wrote:

> A programmer that
> lacks critical thinking is a bad programmer.  The language they use has
> no bearing on such human facilities.

That's nonsense, and I can demonstrate it by reference to a single 
programming language, namely Python.

For many years, Python had no ternary if operator:

result = x if condition else y 

Instead the accepted, idiomatic Python way of writing this was to use 
short-circuit booleans:

result = condition and x or y

However this idiom is buggy! If x is a false-value (say, 0) then result 
gets set to y no matter what the value of condition.

This buggy idiom survived many years of Python development, missed by 
virtually everyone. Even coders of the calibre of Raymond Hettinger (who 
neither lacks critical thinking nor is a bad programmer) have been bitten 
by this:

"The construct can be error-prone.  When an error occurs it can be
invisible to the person who wrote it.  I got bitten in published code
that had survived testing and code review: ..."

http://mail.python.org/pipermail/python-dev/2005-September/056510.html


This is a clear and obvious case where a language feature (in this case, 
the lack of a feature) encouraged an otherwise excellent coder to make an 
error. It was a very subtle error, which was not picked up by the author, 
the tests, or the coder reviewer(s). Had Python been different (either by 
including a ternary if statement, or by forcing and/or to return bools 
only) then this bug never would have occurred.

Of course awful programmers will be awful programmers in any language, 
and excellent programmers will be excellent programmers in many languages.

(I say "many" rather than any deliberately. There's a reason why nobody 
uses languages like Brainf*ck, Whitespace, Ook or Intercal for real work.)

But most coders are neither awful nor excellent. The language DOES make a 
difference: the quality of a technician depends partly on the quality of 
his tools, and programmers are no different.

If you don't believe me, imagine writing code in a language without 
functions or loops, so you have to use GOTO for everything.



-- 
Steven



More information about the Python-list mailing list