Hacker News new | past | comments | ask | show | jobs | submit login

> Why is the implicit:

> if not users:

> an improvement in any of these cases?

Function iterates over the input. User provides a list,

     if users == ():
test fucks up because lists and tuples are never equal.

Literally no gain, only pain.




I don't quite understand. In the case where the function is expecting a list, why would you want to execute the logic for "empty list" on an empty tuple?

Wouldn't this just be the developer using the wrong comparison for the types the function is expecting(hence more reason to be explicit instead of using the implicit false)?


> I don't quite understand. In the case where the function is expecting a list, why would you want to execute the logic for "empty list" on an empty tuple?

Because for most functions that's not a relevant or useful distinction, in Python a tuple is an immutable list, both are sequences.

By mis-handling empty tuples you're just unnecessarily constraining the caller. Not only that, but you might also create an inconsistency which is hard for the caller to notice if your function only fucks up on empty collections.


Good point!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: