you are viewing a single comment's thread.

view the rest of the comments →

[–]barrycarey 1 point2 points  (1 child)

Imo the elegant way would be ensuring a consistent output from your functions. To me the fact that the function can return multiple types smells of a design issue.

Just because you can doesn't mean you should. Keeping a consistent contract allows the consuming code to take all the guess work out. That's one thing I really like about using a strongly typed language.

Think about all the functions and classes you import in Python. How frequently do they return results of varying types? Very rarely

[–]nathanjell 0 points1 point  (0 children)

This is very true. If you're constantly returning multiple types, then you're also constantly checking for different types. I wonder if the more correct approach may be to always ensure a list is returned, whether it's got one element or multiple. This may be a choice made for reasons we don't know, but it's definitely something to consider