[BangPypers] Return values
senthil at uthcode.com
Sat Sep 20 11:20:44 CEST 2014
On Sat, Sep 20, 2014 at 5:04 PM, Noufal Ibrahim KV <noufal at nibrahim.net.in>
> 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.
One option to me looks like, don't have consolidate as parameter for this
function, but do the operation outside.
Like providing a function called get_consolidated_stats, which will call
get_stats and provide the consolidated result.
The reason I am suggesting is, consolidation is one of the operation that
be performed on the the collection and it seems that injecting that
operation on the collection is 'limiting' the API.
The other obvious options are.
1) Return a list, but when consolidate is sent, it is a single element
list. # This hurts semantics and human understanding
2) Return a higher level object, (Stats object) which has a property called
consolidate, which can be set, when it is invoked. # This makes it a bit
More information about the BangPypers