Open miili opened 6 years ago
I agree with you. I am not sure it is necessary to have such complex function. However, the name of the function scale_rectangle looses its meaning with your simplified version. I guess the idea was also to have a meaningful function (in terms of content). I labeled this issue as both enhancement and discussion to get more inputs from others.
Interesting suggestion! fixing the function is straightforward (given its description):
return (x1, y1, x1 + (x2-x1)*factor, y1 + (y2-y1)*factor)
Of course, that's assuming factor
is positive...
However, do we need to check that x1<x2
and y1<y2
? What if we use min(x1, x2)
or min( (x1, y1), (x2, y2) )
? Would that increase cognitive load?
related to #622
I believe that neither the summing numbers nor the rectangle example show good practice for a few reasons:
+
operator is defined.ValueError
should be raised.A good example would be:
IndexError
(a shorter list would cause the same error in the line x1, y1, x2, y2 = rect
). I actually find it quite hard to come up with a good example myself, because most errors are raised in the function anyways without manual checking before. From my experience the typical case is checking the number of arguments.
function
normalize_rectangle
is not easy to comprehend for a beginner. Why should a rectangle be normalized?http://swcarpentry.github.io/python-novice-inflammation/08-defensive/
I propose a more simple function
scale_rectangle
: