
StackOverflow Importer – Import code from Stack Overflow as Python modules - drathier
https://github.com/drathier/stack-overflow-import
======
selljamhere
Relevant xkcd: [https://xkcd.com/1185/](https://xkcd.com/1185/)

"StackSort connects to StackOverflow, searches for 'sort a list', and
downloads and runs code snippets until the list is sorted."

~~~
roryokane
And
[https://gkoberger.github.io/stacksort/](https://gkoberger.github.io/stacksort/)
is an actual implementation of that sort.

------
guelo
This might be a joke but everybody does it manually for real. Whenever I copy-
paste some tricky function from SO I like to add a code comment with the url
pointing to the stackoverflow.com answer. This allows future maintainers to
refer back to SO and see if a better answer has surfaced or read comments
about any issues.

~~~
Biganon
I never, ever copy paste code, unless it's really long. I always end up
rewriting everything myself, so I have the time to think about what's
happening.

~~~
andybak
Hmmmm. I'm the other way round. I copy and paste short snippets because I'm
lazy and I can see if they are ok at a glance. Longer code I'll go through
line by line and try and 'touch' each line to force me to think about it.

------
yefim
Reminds me of stacksort[1]

[1]
[https://gkoberger.github.io/stacksort/](https://gkoberger.github.io/stacksort/)

~~~
dabber
Very funny. I hadn't seen this before. I particularly like:

>>Is it safe?

>>Uh… it evals both user input and random code, unchecked, from an external
site. This is what security-minded folks would refer to as Very Bad™.

~~~
gkoberger
I do my best to make it safe(ish), though :) It only runs code samples that
were posted before I made StackSort.

~~~
relate
What if someone edits an answer posted before you made it?

------
orasis
Awesome. Now we just need to integrate upwork with our IDE so I can just write
the method signature and a bid price and my method will be magically
implemented.

------
Uptrenda
It's interesting to imagine adding something like this to an editors auto
complete or as some kind of search function to automate functions you've coded
a million times.

I.e. maybe you type: "repeat a function over a list python" in a special
format and your editor pastes in the accepted answer from stackoverflow for
you to choose whether that's acceptable / whether you want to use it as a
template. Then maybe you could get into a better flow without ever having to
stop what you're doing to Google something ... It would all just show up
magically in your editor.

You could even have libraries of common answers written in such a way that you
could write expected input and output formats and then get a code fragment
that would fit that description. Something like a more organized test driven
development. Though that would really only work for very specific things.
Improve these ideas enough and make them more general - and maybe you could
improve programmer productivity by quite a large margin.

Disclaimer: I know the OP was a joke but I see no problem with reusing code if
you understand what its doing and the costs / trade-offs for doing so.

~~~
lotkowskim
There is something like that for JavaScript
[https://emilschutte.com/stackoverflow-
autocomplete/](https://emilschutte.com/stackoverflow-autocomplete/)

------
rplst8
It brings new meaning to the term "full-stackoverflow developer."

~~~
0xmohit
Err.. did you mean "full-stack(overflow) developer"?

------
0xmohit
I like the description: "Import _arbitrary code_ from Stack Overflow as Python
modules."

(Emphasis mine.)

\--

Now Stack Overflow should be even more concerned about the availability of
their service.

------
xg15
Way ahead of you:
[https://twitter.com/ckolderup/status/789002880246177792](https://twitter.com/ckolderup/status/789002880246177792)

------
prodigal_erik
It's hard to imagine a better argument for vendoring your dependencies in case
they change.

------
89vision
because executing arbitrary unknown code is always a good idea

~~~
emmelaich
On the other hand, at least the code has gone through some review.

Compare that to NPM or PyPI, which is full of crap. Some of the modules in
PyPI were merely ads for putlocker, without even a single line of Python.

~~~
voltagex_
>Some of the modules in PyPI were merely ads for putlocker

Seriously? Are they still there?

------
sparky_
Based on some of the comments here, a sarcasm disclaimer might be necessary on
the repo!

~~~
pmarreck
(OT) HEY! I finally noticed your Desert Combat comment and responded to it. If
only HN had a better commenting/messaging system...

------
dustinmoris
I often find that the accepted answer with the most votes is the oldest and
often outdated and that there's a newer answer with also a lot of votes which
is more up to date and better many times.

------
denfromufa
Stackoverflow-driven development (SDD):

[https://goo.gl/images/xXCZrx](https://goo.gl/images/xXCZrx)

~~~
drathier
Did I just render that book obsolete?

~~~
denfromufa
Not sure what you mean..

------
lifeisstillgood
Can I be all code review mode, and ask you to lower case the first f. It's
sticking out like a sore thumb

------
shade23
And the relevant book for people who prefer reading material.
[https://tra38.gitbooks.io/essential-copying-and-pasting-
from...](https://tra38.gitbooks.io/essential-copying-and-pasting-from-stack-
overflow/content/)

------
libeclipse
I did something similar with a project that allowed you to import code from
anywhere[0]. StackOverflow would be a nice addition.

[0] [https://github.com/libeclipse/import-
from](https://github.com/libeclipse/import-from)

------
45h34jh53k4j
Cool joke. Post leftpad it needs a disclaimer lest someone actually do this
for real.

~~~
ramblenode
I'm kind of shocked how many people here are talking as though they would
actually include this in a codebase.

~~~
noescape
What if, somehow, there was a guarantee that the code can't harm your machine
-- would you use it then?

This isn't a joke.

~~~
Alupis
It's not just about harming your machine - it can harm your* data, or data
passing through your* system!

* Where "your" can mean you, your employer, your customer, another company, etc.

~~~
noescape
What if it can't harm _your data, or data passing through your system_?

What if it can't harm anything.

~~~
emodendroket
How could a system that executed arbitrary code ever make such guarantees? I
mean sure, if there were a magical thing that only ever produced correct code
for what you wanted to do I guess people would use it.

------
pryelluw
Its amazing how little code it takes to implement this (aside from
dependencies).

------
mobiuscog
And then:
[http://code.visualstudio.com/blogs/2016/11/3/rollback](http://code.visualstudio.com/blogs/2016/11/3/rollback)

------
hughes
If I have editing powers could I hijack the answer that gets its code
imported?

~~~
avg_dev
Edits get reviewed before being published.

~~~
stuartd
No they don't. From
[http://stackoverflow.com/help/privileges/edit](http://stackoverflow.com/help/privileges/edit)

> We believe in the power of community editing. That means once you've
> generated enough reputation, we trust you to edit anything in the system
> without it going through peer review. Not just your posts—anyone's posts!

~~~
0xmohit
If you've been on Stack Overflow enough, you might have noticed that crap is
sometimes approved even after peer-review. Many doing the review do it like
robots (to earn internet _reputation_ and _badges_ ).

------
marcoperaza
This is a really stupid idea, even as a joke to play with. Someone can just
edit the top answer to make it malicious and steal your personal or work data
from your workstation.

~~~
45h34jh53k4j
and then own your network, your DVR, your toaster, your cat.

~~~
StreamBright
Please leave the cat!

------
bthornbury
This is a pretty cool idea! Concerns for running unknown code aside, it seems
like the results of this type of thing would be prone to potentially frequent
change.

I wonder if there'd be a way to maintain consistency, something like a
requirements.txt file that got spit out to describe what the results of the
search terms mapped to when the code was run.

It could just contain the search term and link to the chosen question.
Although you'd still run the risk of the answer itself being edited. The code
itself would have to be cached in whatever this file was.

------
mooreds
What a fascinating concept! I think that with some kind of review built in,
this kind of dynamic loading would be really useful.

I think if you do this, you'd want external tests, or some way to pull the
code in and "freeze" it so that you wouldn't be at risk of external
compromises. (For example, a high ranked SO user might be able to change a
highly ranked answer . They might not do it, but someone suborning their
account might.)

But really, this is an optimization of a lot of code that is currently
written.

~~~
Ph0X
I don't see this being useful for real programs, but it could be amazing for
interactive use in a shell. I use iPython for all sorts of quick data
manipulation daily, and being able to just quickly type an idea and get it
would be amazing.

~~~
mooreds
You're right, maybe it is better for prototyping, but as I've experienced, for
better or worse what you prototype sometimes becomes production.

------
jbpetersen
Anyone else tinkering with / armchair philosophizing about ways of making
stuff like this practical for regular use?

------
ronreiter
This is a license hell, whatever you do, don't use it if you care about your
code not being owned by other people.

------
StreamBright
Importing and running code from an external site without verification or code
review. What could possibly go wrong?

------
qud
What a time to be alive. Edit: this is officially the best thing to happen to
me this week, heck, month.

------
gigatexal
This is so funny. Kudos to the author!

------
Alex3917
I look forward to using this in a future job interview and seeing what
happens.

------
nhatbui
This is awesome. But how is `time_delay` used?

~~~
drathier
The code snippet it finds imports sleep and calls it directly. Fire it up in a
repl and check __author__ or _code yourself :)

------
jstoiko
Makes me think of Kite[1]. Kite is a "real" thing that one can use though.

[1] [https://kite.com](https://kite.com)

------
hiou
Somewhat related
[https://github.com/gleitz/howdoi](https://github.com/gleitz/howdoi) with the
vim frontend [https://github.com/laurentgoudet/vim-
howdoi](https://github.com/laurentgoudet/vim-howdoi)

