Web Frameworks Excessive Complexity

Chris Angelico rosuav at gmail.com
Wed Nov 21 06:21:23 EST 2012


On Wed, Nov 21, 2012 at 10:09 PM, Andriy Kornatskyy
<andriy.kornatskyy at live.com> wrote:
> We choose Python for its readability. This is essential principal of language and thousands around reading the open source code. Things like PEP8, CC, LoC are all to serve you one purpose: bring your attention, teach you make your code better.

But too much focus on metrics results in those metrics improving
without any material benefit to the code. If there's a number that you
can watch going up or down, nobody's going to want to be the one that
pushes that number the wrong direction. So what happens when the right
thing to do happens to conflict with the given metric? And yes, it
WILL happen, guaranteed. No metric is perfect.

Counting lines of code teaches you to make dense code. That's not a
good thing nor a bad thing; you'll end up with list comprehensions
rather than short loops, regardless of which is easier to actually
read.

Counting complexity by giving a score to every statement encourages
code like this:

def bletch(x,y):
  return x + {"foo":y*2,"bar":x*3+y,"quux":math.sin(y)}.get(mode,0)

instead of:

def bletch(x,y):
  if mode=="foo": return x+y*2
  if mode=="bar": return x*4+y
  if mode=="quux": return x+math.sin(y)
  return x

Okay, this is a stupid contrived example, but tell me which of those
you'd rather work with, and then tell me a plausible metric that would
agree with you.

ChrisA



More information about the Python-list mailing list