How complex is complex?
rhodri at wildebst.demon.co.uk
Thu Mar 19 00:34:01 CET 2009
On Wed, 18 Mar 2009 17:30:45 -0000, Kottiyath <n.kottiyath at gmail.com>
> When we say readability counts over complexity, how do we define what
> level of complexity is ok?
We don't. There is no One True Way that defines for us what complexity
is, never mind how much of it is too much. It's a judgement call that
is very personal, and as with all these things involves trade-offs.
Some potentially helpful rules of thumb:
* Am I going to understand this code when I come back to it in half
an hour? If not, I'm probably better off with a more readable version
or (if I really must) a page and a half of comments explaning the
* Am I going to understand this code when I come back to it in six
months? Similar reasoning applies, though I'm more likely to comment
than replace in this case.
* Is someone else going to understand this code in six months time
when I won't be around to help them. A rather higher bar than the
previous one, which pushes back towards readability again.
* Does it look incredibly ugly? If so, it's probably a bad idea no
* (with respect to your example) Does it do the same thing as the more
readable version, and do it at least as efficiently? If not, there's
no point in being clever, do it the readable way.
Rhodri James *-* Wildebeeste Herder to the Masses
More information about the Python-list