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

> Exceptions as flow-control is normal in Python.

Perhaps it's high time that problem was solved?




This isn't a problem, it is a design decision that you evidently don't like. There is a difference.


> This isn't a problem

It actually is. Abusing exceptions as the normal control flow is a crude anti-pattern. Obviously the normal flow of control is not exceptional behavior. Therefore, abusing exceptions and exception-handling mechanisms to implement the happy path is simply wrong at many levels, from conceptual to practical, and in the end actually cause problems and hard to find buga such as the problems described in this bug report.


As a fan of Python, I agree that it’s a problem, and probably one of Python’s worst design decisions. It doesn’t achieve anything over sentinels, and results in lots of potential for hidden bugs (especially in the case of __getattr__, and before PEP 479). Comparison overloading even does use NotImplemented instead of an exception.


Especially on StopIteration this is a good way to keep the interface small when lacking static typing.

A generator in Java has the has_next() and next() method and this can be statically checked and you're basically only allowed to call next is hasnext is true.

In python the generator only has to provide the next-method and raises an exception when it's exhausted. I don't find this particularly unclean.




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

Search: