We have a object method that returns a city/state tuple, i.e. ('Boston', 'MA'). Under some valid circumstances, there is no valid city/state to return. Stylistically, does it make more sense to return None, or a two element tuple containing (None, None) in that case?
We have a object method that returns a city/state tuple, i.e. (‘Boston’, ‘MA’) .
Share
I would return
None. If there is no result, why return something that looks like a result?It is also easier to test:
I would only return
(None, None)if it were possible that only one of the two values isNone(i.e.('Boston', None)). It would be more consistent in this case.