[BangPypers] Return values
vivek.ramakrishna at globalsoft.com
Sat Sep 20 11:15:17 CEST 2014
Why not create two methods, get_stats() and get_stats_list(). Both can
share logic in a common function which takes the consolidate flag - meaning
your logic is localised to one point only. It makes for more readable code
when called as well.
On Sat, Sep 20, 2014 at 2:34 PM, Noufal Ibrahim KV <noufal at nibrahim.net.in>
> I've recently come across something that I'd like some comments on. It's
> a stylistic issue so not something that there's an objective answer
> for. Nevertheless.
> I have a function that gets some statistics from some source and returns
> it to the user as a Stats object. Let's call it get_stats. This has a
> parameter `consolidate`. If consolidate is True, it will combine all the
> statistics and return just one Stats object. If not, it will return a
> list of Stats objects.
> The problem now is that this function sometimes returns a single thing
> and some times a list. I don't like this since I have to alter my
> calling code to handle this.
> I'm surprised that I've never hit this before and I'm not really sure
> how to handle it.
> BangPypers mailing list
> BangPypers at python.org
*Vivek Ramakrishna* | Director | GSoft Services Pvt Ltd |
www.globalsoft.com | +91 702 202 5880
More information about the BangPypers