Python exceptions considered an anti-pattern
31–40 of 69 posts
Re: Python exceptions considered an anti-pattern
#32It amazes me how enduring formulaic it is to single out some particular design tradeoff of a language, draw up some examples of expressing something where that tradeoff creates worse code, and then act like it's some mortal flaw in the language. Python chose untyped exceptions, period. How is this surprising, given that its basis is untyped parameters? If you don't like that, use Java with its checked exceptions. Or…
The mistake I see people make is to use built-in exceptions without subclassing, making it impossible to explicitly catch specific errors. Or the opposite, catching Exception, which will catch everything indiscriminately.
Re: Python exceptions considered an anti-pattern
#33It re-implements a 4 line function as a 13 line class, but the logic at the caller doesn't get any simpler:
try:
result = get_user_profile(id)
except:
# handle any exceptions...
vs. with the library: result = FetchUserProfile(id)
if (result is a Failure):
# handle the failure
# do something with the resultRe: Python exceptions considered an anti-pattern
#34The interesting bit starts at https://sobolevn.me/2019/02/python-exceptions-considered-an-... , where it introduces a library for wrapping errors in return types, even if it got little to do with the headline. IMHO the article would be stronger with a title about what it presents and without the first half.
Thanks, my idea was to state the problem and propose a solution. Hope, that you will find `returns` helpful.
And for one specific reasons: Exceptions are not important per se, but also for the stacktrace they take with them, and that is given to you when you need to handle it.
I lost too much time in this last month trying to decipher where the hell stuff happened looking at the stacktraces in the logs.
Coming back to the python approach: I like python :) and it's philosophy it's to have unchecked exception, with all what it concerns. The idea is that if you don't know an exception, you really don't know what to do. So let the code blows up - ideally in tests :) - and understand what realistically can happen and how to deal with it.
Re: Python exceptions considered an anti-pattern
#35It amazes me how enduring formulaic it is to single out some particular design tradeoff of a language, draw up some examples of expressing something where that tradeoff creates worse code, and then act like it's some mortal flaw in the language. Python chose untyped exceptions, period. How is this surprising, given that its basis is untyped parameters? If you don't like that, use Java with its checked exceptions. Or…
> So, the sad conclusion is: all problems must be resolved individually depending on a specific usage context.
Why is that sad/revelatory? If the wrapper simply reproduces the behavior of a single infix operator for floating point numbers, then almost by definition one would need to reimplement NaN in order to get a general purpose exception handler.
Re: Python exceptions considered an anti-pattern
#36"X considered an anti-pattern" article titles considered an anti-pattern
Re: Python exceptions considered an anti-pattern
#37 try as method1:
method1()
except@method1 try as method2:
method2()
except@method2 try as method3:
method3()
except@method3:
raise NoMethodWorked()Re: Python exceptions considered an anti-pattern
#38Re: Python exceptions considered an anti-pattern
#39"X" implies "X considered harmful"
Thus
"X considered harmful" considered harmful
"'X considered harmful' considered harmful" considered harmful
...
QED
Re: Python exceptions considered an anti-pattern
#40Counterargument: Exceptions are Pythonic https://jeffknupp.com/blog/2013/02/06/write-cleaner-python-u...