
FuckIt.py - The Python Error Steamroller - rbanffy
https://github.com/ajalt/fuckitpy
======
jxf
If anyone is curious (or lazy), FuckIt works by opening up the AST [0] and
wrapping almost every statement (except those that declare functions) in a
silent try-catch block [1].

[0]
[http://en.wikipedia.org/wiki/Abstract_syntax_tree](http://en.wikipedia.org/wiki/Abstract_syntax_tree)

[1]
[https://github.com/ajalt/fuckitpy/blob/master/fuckit.py#L70-...](https://github.com/ajalt/fuckitpy/blob/master/fuckit.py#L70-L77)

~~~
aaronem
I tried doing something similar with Perl, which as I understand matters does
not actually have an AST. It does have something called "source filters",
which I gather are almost entirely unlike Lisp macros; despite that seeming
like the best available option (the filter, in this case, being one which
wraps the whole script containing 'use fuckit' in a quoted eval whose $@ is
ignored), the closest I got with it was segfaulting the Perl interpreter,
which certainly counts as some sort of result.

------
dhammack
The test suite is amazing.

[https://github.com/ajalt/fuckitpy/blob/master/tests.py](https://github.com/ajalt/fuckitpy/blob/master/tests.py)

    
    
        def test_chaining():
            fuckit(fuckit('fuckit')) 
            
            assert 'false' # Good thing this isn't PHP

~~~
Goopplesoft
This guys got a good sense of humor.

------
null_ptr
There's something to be said about the quality of programming API-kids do
these days, if FuckIt.lang projects are so popular. Not to jab this project
itself by any means, but hiding defects _" on your way to doing that million
dollar demo to investors"_ makes my skin crawl. How many con men are in this
industry? This is damn sad. If you need a tool like this beyond your private
debugging needs, you don't understand what you're doing and should step back
and take the time to reason things out.

~~~
austinz
Assuming this project is satire (which I hope it is), it's amazing because it:

\- does something rather novel

\- does something that, to the sufficiently desperate or inept developer,
might seem like a half-decent idea or a cunning shortcut

\- does something that is just asking for trouble and that nobody in their
right mind should do without expecting terrible, terrible things to happen

~~~
code_duck

        - does something that is just asking for trouble and that nobody in their right mind should do without expecting terrible, terrible things to happen
    

It makes Python run about like JavaScript or PHP. I guess that's accurate.

~~~
mikle
Some people use Python as JS or PHP, why not also make it behave like that?

In reality, even if this is satire (which I believe it is) I'm sure if enough
people will know about it, at least one of them will use it seriously.

~~~
ot
> Some people use Python as JS or PHP, why not also make it behave like that?

If you want to go the other way, try

    
    
        window.onerror = window.close;

------
gkoberger
Based on fuckit.js, although fuckit.py seems to eat errors while fuckit.js
reruns code while removing the offending line until it runs:

[https://github.com/mattdiamond/fuckitjs](https://github.com/mattdiamond/fuckitjs)

~~~
alcari
That reminds me of Vigil[0], a Python-derived language that defends supreme
moral vigilance.

[0] [https://github.com/munificent/vigil](https://github.com/munificent/vigil)

------
PhasmaFelis
"Still getting errors? Chain fuckit calls. This module is like violence: if it
doesn't work, you just need more of it."

I feel like writing some Python now.

~~~
Wolfrum
I like this one: "Keep in mind that the decorator form of fuckit can't stop
syntax errors. For those, you have to use the import form."

------
md224
As the author of FuckItJS, I approve of this effort. And thanks for the
attribution!

------
calroc
"Don't silence KeyboardInterrupt or SystemExit. We aren't monsters." Hahahahha

------
sherjilozair
This module is not satire, and the existence of this module does not indicate
anything about the quality of programmers of this generation.

For those who think so, try doing some machine learning, data handling code,
or even web crawlers. Error tolerance is much needed.

For scientific experiments, sometimes the results of the experiment is still
valuable even if there's a trivial bug (malformed row). A partially-correct
execution is still more information than an unhandled exception causing an
early exit.

~~~
tel
Having worked on all of those, this module is satire and foolish to use in
normal code. The rule is protect your boundaries and whenever data comes in it
requires careful handling and thoughtful error policies. The entire notion of
taint from Perl comes to mind.

If anything, your error messages are more important then.

------
jpwagner
_" This module is like violence: if it doesn't work, you just need more of
it."_

if for nothing else, I am in love with this for its sense of humor

~~~
datashaman
From Nokogiri's homepage: XML is like violence - if it doesn’t solve your
problems, you are not using enough of it.

------
doki_pen
I just wrapped all my testcase's in fuckit and all my tests are now passing.
I'm ready to ship!

------
sheetjs
I like the opposite approach, where broken code is explicitly removed. vigil
([https://github.com/munificent/vigil](https://github.com/munificent/vigil))
attempted to do this

~~~
pyre
Well, when importing a module, it removes lines until it imports.

------
shabble

        On Error Resume Next

~~~
TheCraiggers
That makes me shudder.

At one point in a previous life, I was the administrator for HP Quality Center
at my company. On the good side, HP exposes the entire workflow in VBA (ok, I
guess that isn't that good actually, but still better than black box).

On the horrible side, EVERY SINGLE FUNCTION in that application began with the
line "On Error Resume Next". I quite nearly quit on the spot the first time I
looked at the code. A couple years later, I would regret that decision.

------
ak217
I wrote a library so you don't have to use this:

[https://github.com/kislyuk/ensure](https://github.com/kislyuk/ensure)

(Though I know how frustrating exception juggling can get... especially when
they get pickled and re-raised)

------
austinz
> "the test suite actually found a bug holy crap"

I'm sad to say I say this every time this happens to me as well.

------
nezo
A python version of PHP's '@' operator, nice!

------
phelmig
Loved reading tests.py:

def test_context_manager(): with fuckit: pass

    
    
        assert 'P' != 'NP' # proof is left as an excercise for the reader

------
Houshalter
This gave me an idea which is probably terrible. Instead of eating errors or
ignoring them, use genetic programming on the code until it passes all your
tests and doesn't give any errors. It would still be terrible to actually use,
but it might actually get the code to work.

~~~
hamiltonkibbe

      import fuckit
      from string import ascii_lowercase, digits
      from random import choice, randint
    
      def defuckify(test_fn, fn_name, n_arguments):
      ''' Randomly generate functions until the test passes
      '''
          defuckified_fn = ('def %s(' % fn_name)
          for i in range(n_arguments):
              arg_name = ('arg%d,' % i) if i != n_arguments else ('arg%d' % i)
              defuckified_fn += arg_name
          defuckified_fn += '):'
          exec('def '+ fn_name + '():\n    pass\n')
          while not test_fn():
              for i in range(randint(100,10000)):
                  defuckified_fn += choice(' \n,[](){}\'"=+-*/%:'+ ascii_lowercase + digits)
    
              with fuckit:
                  exec(defuckified_fn)
          print(defuckified_fn)
    
    

Edited to use fuckit instead of try/catch

Edited again to add that it has been over an hour and it hasn't been able to
make a function that returns 3

~~~
gknoy
It seems like `unfuck` might be a more pythonic name.

That is not a pair of words I ever thought I'd use in the same sentence. :)

~~~
Houshalter
How often do you say "unfuck"?

~~~
antsar
Do you know a better term for "debug others' code"?

------
rectangletangle
Is there an actual use case for something like this? I'm legitimately curious.

~~~
sytelus
On a semi-unrelated topic, can anyone imagine a use of write-only memory? I
swear I'd came up with one few years ago and unable to recall it anymore.

~~~
kunil
There was some april joke like that, they even created data sheets if I
remember it correctly

edit: found it [http://www.repeater-builder.com/humor/signetics-
wom.pdf](http://www.repeater-builder.com/humor/signetics-wom.pdf) I love 0V +-
%2

------
jeffheard
Because after 48 hours of working on the same bug, there's nothing quite so
satisfying as going completely John McClane on its ass.

\- Yippie kai yay, motherfucker.

------
cjbprime
Most appropriate choice of copyright license ever.

~~~
VladRussian2
seems pretty restrictive to me :

"...and changing it [license] is allowed as long as the name is changed."

edit: i was joking :)

~~~
lambda
That's the licence for the license, not the license for the code itself.

The licence for the code itself is "0\. You just DO WHAT THE FUCK YOU WANT
TO." The license for the license is similar, with the caveat that you're
required to change the name if you change the content. Which makes sense; we
wouldn't want confusion about what the WTFPL refers to.

------
NamTaf
This truly appeals to the difference between Engineer and Scientist in all of
us. I can see myself getting heavy use out of this.

------
ozh
I just can't believe how many commenters here don't get it's a joke or are
carefully unsure. A. Ma. Zing.

------
allochthon
It's like the exact opposite of Perl's "use strict" pragma. ;)

------
zackbloom
Reminds me of
[http://criso.github.io/ChuckNorrisException/](http://criso.github.io/ChuckNorrisException/)

~~~
lhgaghl
Is there a Python version? If so does it beat Fuckit.py?

------
druiid
I think my favorite part of it had to be the readme for using it with
decorators:

@fuckit def func(): problem_solved

That has to be the best piece of code I have ever seen.

------
doug1001
i've used this for a while now--really useful debugging tool in my workflow.
Does exactly what it says on the tin.

just wrap the offending module and get on with your life; and in those rare
(for me) instances where you still get errors, this module supports chaining
syntax--declarative syntax, to say the least:

fuckit(fuckit('imported_module'))

~~~
mkesper
How could this be helping in debugging? I'm curious!

~~~
guipsp
It's a joke

------
d_theorist
I'm assuming this is a joke. If so, it is funny.

------
yeukhon
Does this fix circular import for me...?

~~~
acosmism
yes

------
sfbsfbsfb
I'm so tired of the use of profanity in names. Why is this acceptable in this
industry?

~~~
aaronem
Because we're all adults with functioning senses of humor, where 'all' is
defined as a 'mostly' whose exceptions tend to be both immediately obvious and
unbearable in social settings.

~~~
sfbsfbsfb
OK. Adult. Got it.

------
pyrcules
this library should actually be called "phpify"

------
tbarbugli
made my day

------
shaneofalltrad
wtf!

