3 ms·
An extremely obscure and rare scenario that exposes a flaw with a convenient tool does not negate the value of the tool in all other cases. Are you also going
by deanCommie 7y ago
An extremely obscure and rare scenario that exposes a flaw with a convenient tool does not negate the value of the tool in all other cases.
Are you also going to throw out all use of automatic garbage collection in languages because of a bug caused by a GC pause.
Should we stop bothering with encryption because people discover weaknesses and attack vectors?
Come on, man.
> Also, KeyboardInterrupt should not be an exception. It's a signal, not an error or exceptional situation that code wants to report to the caller.
OP doesn't mention anything about KeyboardInterrupt, but I'll bite.
Some languages like C# make "Events" a 1st party citizen, making it really easy to write non-sequential code and handling such events.
Most don't, so when people want to GUARANTEE a caller handles a particular signal, they use the Exception tool because it posesses the necessary qualities.
"Using Exceptions as flow control" is a well-known anti-pattern but even anti-patterns have their use in exceptional circumstances.
> ("randomly" as in: why is "open file" throwing an exception when file doesn't exist but "find substring" returns -1 when substring doesn't exist?)
I'll concede this one point. In-memory utility methods shouldn't throw exceptions when a useful error code would be just as good - it keeps code cleaner without trycatch blocks. NumberFormatException is my bane in Java.
- CaptainMarvel 7y agoExceptions as flow-control is normal in Python. It’s used all over the place, e.g. generators with StopIteration.
- rumanator 7y ago> Exceptions as flow-control is normal in Python. Perhaps it's high time that problem was solved?
- maweki 7y agoEspecially 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.
- larkost 7y agoThis isn't a problem, it is a design decision that you evidently don't like. There is a difference.
- minitech 7y agoAs 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.
- rumanator 7y ago> 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.
- sicromoft 7y agoTerminology nit: Flow control is not the same as control flow (which is sometimes referred to as flow of control... yeah it's confusing). https://en.wikipedia.org/wiki/Flow_control_(data) https://en.wikipedia.org/wiki/Flow_control_(data) https://en.wikipedia.org/wiki/Control_flow https://en.wikipedia.org/wiki/Control_flow
- masklinn 7y ago> NumberFormatException is my bane in Java. Surely that’s because of java? conversions normally throw in python and that’s no issue. So does indexing. So does str.index.
- Dylan16807 7y ago> OP doesn't mention anything about KeyboardInterrupt Please go check on the original post.