Hi Noufal, Looks like we already have different style preferences here. So let me throw some more to the mix :)
Wearing a functional programmers cap, I would suggest creating one get_stats() function that always returns the stat values as a list. Then, there could be potentially several Higher Order Functions like stats_avg() or stats_median() which work on a list of Stats objects and returns a single Stats object or even a literal value. Thinking in a slightly different object oriented style, the return value could be a Stats object. It could have a raw_values() and consolidate() methods. Derived classes can override the consolidate() method to support various consolidation algorithms. Depends on the style you follow in the rest of the API as well :) Cheers, Arun On Sat, Sep 20, 2014 at 2:34 PM, Noufal Ibrahim KV <nou...@nibrahim.net.in> wrote: > > 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. > > Comments? > > > > -- > Cordially, > Noufal > http://nibrahim.net.in > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > https://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers