[Tutor] Python best practices

Wayne Werner waynejwerner at gmail.com
Mon Nov 30 13:29:14 CET 2009

On Mon, Nov 30, 2009 at 4:06 AM, ALAN GAULD <alan.gauld at btinternet.com>wrote:

> Thats what I think is meant by bad practice in returning
> multiple values. The function returns two completely different
> things depending on some input flag.

Now that's something I definitely agree with! I can't think of a single case
where that would make sense or be good practice. It would just create a ton
more work for the programmer/maintainer and obfuscate the code.

OTOH I can think of several reasons/times I've returned multiple related
values - for instance I was just writing a function for homework that found
the continuous subsequence with the greatest total that returned the start,
end, and total (more for my benefit than any other requirement... still, in
terms of time complexity and program complexity, it makes much more sense
than trying to break it up as "getMaxTotal" "getstart" and "getend"
functions - that would just be ridiculous!)


To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091130/30d610b6/attachment.htm>

More information about the Tutor mailing list