86 points · by aburan28 · 11y ago · 46 comments
def test_context_manager(): with fuckit: pass
assert 'P' != 'NP' # proof is left as an excercise for the reader try:
[...]
except IOError:
# Worst-case scenario we can only catch errors at a granularity
# of the whole function.
[...]
else:
# If we have access to the source, we can silence errors on a
# per-expression basis, which is "better".
[...]
and then: def __exit__(self, exc_type, exc_value, traceback):
# Returning True prevents the error from propagating. Don't silence
# KeyboardInterrupt or SystemExit. We aren't monsters.
Brilliant.It was funny! There was a religious or medieval theme or something. I can never find it...
https://github.com/nvbn/thefuck
(Previous discussion: https://news.ycombinator.com/item?id=9396116 )
http://rubylearning.com/satishtalim/ruby_method_missing.html
Also, it's from Smalltalk, and found in some ways also in python, objective-c and many others.
https://github.com/mattdiamond/fuckitjs
So if you want the same thing but for JS give the above a shot.
http://bazaar.launchpad.net/~leonardr/beautifulsoup/bs4/view...
That said, I have met some developers who would find this as an advantage and might actually try to put it into use. Generally these are folks who prefer the default soldier-on-in-the-face-of-errors behavior from sh and perl.
Nobody in the Perl world prefers that, outside of people who are complete newbies. In fact, collectively Perl has been yelling at newbies for decades that anything not containing `use strict;` and `use warnings;` is almost without fail broken code, mainly because there are a lot of very old and outdated tutorials which introduce these modules as optional and/or way too late.
I think these are actually old-bies. They don't opt-in to `use strict;` because they like it that way. I suppose they just have an astonishingly high pain threshold.
DFSG compatible Yes
FSF approved Yes
OSI approved No
GPL compatible Yes
Copyleft No
Linking from code with a different license Yes