Code formatting question: conditional expression

Ben Finney ben+python at benfinney.id.au
Tue Aug 18 17:39:13 EDT 2009


John Posner <jjposner at optimum.net> writes:

> > excessblk = None
> > if total > P.BASE:
> >     excessblk = ...
> >
[…]

> But doesn't it violate the DRY principle? The token "excessblk"
> appears twice instead of once.

No, the DRY principle <URL:http://c2.com/cgi/wiki?DontRepeatYourself>
doesn't speak against assigning two *different* values in two
*different* circumstances. That's not duplication, and doesn't risk
contradiction. DRY speaks against repeating the same *meaning* in two
different places.

Because this concept is expressed in natural language and not a
programming language, and because we don't speak in a language under the
same principles we espouse for programming, there are multiple terms
used for this concept :-)

Another term which makes the point slightly more sharply is SPOT: there
should be a Single Point Of Truth for each fact in the overall system.

-- 
 \          “What I have to do is see, at any rate, that I do not lend |
  `\      myself to the wrong which I condemn.” —Henry Thoreau, _Civil |
_o__)                                                    Disobedience_ |
Ben Finney



More information about the Python-list mailing list