for / while else doesn't make sense

alister alister.ware at ntlworld.com
Fri Jun 10 07:18:18 EDT 2016


On Thu, 09 Jun 2016 18:19:23 +1000, Steven D'Aprano wrote:

> On Thursday 09 June 2016 10:34, Lawrence D’Oliveiro wrote:
> 
>> In my undergraduate Comp Sci classes, we used to discuss arbitrary
>> rules like limiting functions to n lines. With real-world experience,
>> it soon became clear that such rules were a waste of time. A function
>> should be just as big as it needs to be, no more, no less. The same
>> with a class, or a module. Or whatever other constructs your language
>> may have.
> 
> The opposite of "arbitrary limits" is not "no limits".
> 
> An arbitrary limit like "500 lines is the maximum size a function may
> be" is clearly arbitrary and not very helpful. (Also too high.)
> 
> Better is to understand that there is no hard cut-off between
> "acceptable" and "too long", but we can still judge that all else being
> equal, long functions are worse than short functions.
> 
> The real problem is complexity of functions. The more complex they are,
> the harder they are to write correctly, and the harder to maintain, and
> the more likely that they have bugs.
> 
> The length of a function is a very crude measure of complexity, but it
> *is* a measure of complexity, and people are right to look at long
> functions as a code smell and a sign that the function probably does too
> much, or is badly written,
> or that it could do with some refactoring to simplify it. Not in *every*
> case, but I've never yet seen a long (> 200 lines) function that wasn't
> improved by refactoring or splitting.



Or more simply a hard fixed RULE (MUST be less than X lines) is Bad.

a flexible GUIDELINE on the other hand is reasonable.

after all an efficient function could be be X=1 lines, abriatrily spliting 
this could make the final function less readable & possibly even longer 
in total.
 


-- 
Puns are little "plays on words" that a certain breed of person loves to
spring on you and then look at you in a certain self-satisfied way to
indicate that he thinks that you must think that he is by far the 
cleverest
person on Earth now that Benjamin Franklin is dead, when in fact what you
are thinking is that if this person ever ends up in a lifeboat, the other
passengers will hurl him overboard by the end of the first day even if 
they
have plenty of food and water.
		-- Dave Barry, "Why Humor is Funny"


More information about the Python-list mailing list