is there any principle when writing python function

Chris Angelico rosuav at gmail.com
Sat Aug 27 16:38:31 EDT 2011


On Sun, Aug 28, 2011 at 6:27 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> You've never noticed the masses of code written in text books, blogs, web
> pages, discussion forums like this one, etc.?
>
> Real world code for production is usually messy and complicated and filled
> with data validation and error checking code. There's a lot of code without
> that, because it was written explicitly to be read by humans, and the fact
> that it may be executed as well is incidental. Some code is even written in
> pseudo-code that *cannot* be executed. It's clear to me that a non-trivial
> amount of code is specifically written to be consumed by other humans, not
> by machines.

Yes, I'm aware of the quantities of code that are primarily for human
consumption. But in the original context, which was of editing code
six months down the track, I still believe that such code is primarily
for the machine. In that situation, there are times when it's not
worth the hassle of writing beautiful code; you'd do better to just
get that code generated and in operation.

Same goes for lint tools and debuggers - sometimes, it's easier to
just put the code into a live situation (or a perfect copy of) and see
where it breaks, than to use a simulation/test harness.

ChrisA



More information about the Python-list mailing list