Earlier quoted context omitted.
It is certainly okay for some functions to be complex. Some may rely on simpler functions, but the one you'd use can still do a complex task in general. A function that squares a number is simple, one that computes the standard deviation is definitely more complex.
> A function that squares a number is simple, one that computes the standard deviation is definitely more complex. I'm talking about the complexity difference between this: def stddev(pop): total = 0 count = 0 for x in pop: total += x count += 1 mean = total / float(count) variance = 0 for x in pop: variance += (x - mean)**2 return math.sqrt(variance) and this: def stddev(pop): return math.sqrt(variance(pop)) def var…
Well, that stddev function could be much less verbose:
def stddev(pop):
mean = sum(pop) / float(len(pop))
variance = sum( (x-mean)**2 for x in pop)
return math.sqrt(variance)
To me that's easier to read than jumping back and forth between multiple function definitions. Of course, if you need the mean or variance independently then your way is better.