Search code examples
algorithmlanguage-agnosticcode-reuse

Is there a website to look up common, already written functions?


I'm sitting here writing a function that I'm positive has been written before, somewhere on earth. It's just too common to have not been attempted, and I'm wondering why I can't just go to a website and search for a function that I can then copy and paste into my project in 2 seconds, instead of wasting my day reinventing the wheel.

Sure there are certain libraries you can use, but where do you find these libraries and when they are absent, is there a site like I'm describing?

Possibly a wiki of some type that contains free code that anybody can edit and improve?

Edit: I can code things fine, I just don't know HOW to do them. So for example, right now, I'm trying to localize a robot/car/point in space. I KNOW there is a way to do it, just based off of range and distance. Triangulation and Trilateration. How to code that is a different story. A site that could have psuedo code, step by step how to do that would be ridiculously helpful. It would also ensure the optimal solution since everybody can edit it. I'm also writing in Matlab, which I hate because it's quirky, adding to my desire for creating a website like I describe.


Solution

  • Firstly, two caveats:

    1. Copy and pasting code you don't understand is a bad idea. Make sure you understand exactly what the code does before you use it.
    2. Make sure you respect the license of the code you are copying. This is important!

    Those caveats aside, it's often language dependent. Languages with an open development ethos (not just an open source implementation, think Python as compared to Java) tend to have official archives of open source libraries. For example:

    Furthermore, don't forget to look in your languages standard library. Some modern languages have massive standard libraries, which have often contained the functionality I am looking for:

    Non-openly developed languages often have non-official community archives. For example:

    A third category of sites are language agnostic. They are often best search through POG (plain old-fashioned Google). For example:

    Finally, a fourth category of sites that I find increasingly useful are source-code search engines:

    You may also be able to find useful source code, or at least get help writing something, through various pastebins.

    • Pastebin is language-agnostic
    • HPaste is mostly Haskell, but has a little in other languages.

    Often, at the end of the day it is easiest just to google it, though.