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

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.

StackOverflow.com. No, I'm not joking.
At its best, people come here saying "hasn't some library done X already", and very often the Collective Wisdom answers "yes". But the biggest obstacle is lack of a description language: even here, a big problem for many posters is describing the problem clearly enough for others to recognize it as something they've seen before.
And if people can't understand what you're trying to do, no search engine will.

Firstly, two caveats:
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.
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:
Perl (which probably started this trend) has CPAN
Python has PyPI and Python Cookbook
PHP has PEAR
C++ has boost
Ruby has gems
R has CRAN.
Haskell has Hoogle and Hackage
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:
Java has its API documentation
C# and VB.NET have the massive MSDN
Non-openly developed languages often have non-official community archives. For example:
C# tends to have a lot of code at CodePlex and CodeProject
MATLAB has the Matlab Central File Exchange
A third category of sites are language agnostic. They are often best search through POG (plain old-fashioned Google). For example:
Stack Overflow
SourceForge
The confusingly language agnostic Java2s
Planet source code
Github
Finally, a fourth category of sites that I find increasingly useful are source-code search engines:
Google Codesearch
Koders
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.

There is a wiki that contains free code that anybody can edit and improve:
Rosetta Code.
As a means of an overview there is the "Solutions by Programming Task" page.
From the former page:
"Rosetta Code is a programming chrestomathy site. The
idea is to present solutions to the same task in as
many different languages as possible, to demonstrate
how languages are similar and different, and to aid a
person with a grounding in one approach to a problem
in learning another."

Cutting and pasting code you find on the Internet into production code would be like chewing gum found in the street. - Mike Johnson
With that in mind, try sites that host opensource projects like GitHub, CodePlex, code.google.com, etc.

I'm not sure this question is language agnostic, but I use GitHub this way ;) Other languages may have places where this is possible.

Safari Bookshelf from O'Reilly has many, many books that contain many implementations from which to choose.
http://my.safaribooksonline.com/
I was a subscriber for a few years before coming to my current job, where we have a corporate account! It's one of the best perks, and one of the best resources I have available. I haven't bought a computer book in years.

Aside from sites like this (Stack Overflow) I don't think there's many, maybe CodePlex, but I almost marked you -1 for assuming that code found on the Internet is yours to copy.
I'd suggest reading about software licencing, I hope you'd at least comment where you got it from.

Related

Are there any way or place to know how to build WDM in VS 2013?

I have learned about the rootkit
Then, I tried to practice example codes,
but, I can't build a wdm driver(only can KMDF)
So, I've searched so many websites but that documents was out-dated
Can you tell me the way or some good place to learn with VS 2013??
(Or, good examples of rootkit tutorial with KMDF)
I'm not sure as to exactly what you're asking for, but try Microsoft Virtual Academy, as they have hundreds of online (free and downloadable) courses on programming or their technology in general.
And to be specific, there are at least 10-12 courses on different frameworks including WDM. I strongly suggest you begin there.
Only problem is knowing how to find the course specifically, as their names can sometimes be misleading, so just read the introduction and the name of each module to see if that's the course for you. Good luck!
MVA: http://www.microsoftvirtualacademy.com/

Resources containing cross-language benchmarks?

What resources are available that use benchmarks for comparing programming languages?
I am interested in both
How quickly a program in a given language can execute a given benchmark?
How many lines of code are required in a given language to implement a given benchmark?
There is a long-standing web site called the Computer Language Benchmarks Game, originally created by Doug Bagley as the "Great Computer Language Shootout". (You can view a little history at Portland Patterns Repository.)
Is anyone aware of other resources that enable programmers to compare performance and size of programs written in different languages?
Alternatives
After a quick google search, I found a couple other sites where benchmarks for various languages have been done. Some other sites mention the programming language shootout site that is currently down.
There is a CPAN module for Perl that uses the same code found on that site.
Google has a directory where pages on this topic can be found. I have not found any yet that are as comprehensive as the page you speak of, but there are certainly other resources out there for comparisons.
Archived / Cached Page
If you're only seeking some information there, you can view archived pages of the site using the Wayback Machine or Google's cached version. Try searching Google with "site: shootout.alioth.debian.org" and click on the "Cached" links for the pages you find.
Find the Author?
Perhaps the best option is to try to contact the owner of the old site and find out what happened. The author mentioned in the BSD licence on this page is "Brent Fulgham". He may or may not be the one to contact.
Wait until Alioth is Fixed
As #ioguy found out, Debian's Alioth server that hosts the site in question is currently under maintenance. I would suggest subscribing to the debian-devel-announce mailing list for updates, and an idea of when it may be fully functional again.
If you find problems in the future, you can probably post to the debian-user list.
Each year there are two or three
isolated blog posts that claim to
compare performance and size of one
or two programs written in different
languages.
As a resource the blog posts fail for obvious
reasons, most obviously:
not updated with newer versions of the language implementation
not updated with better programs
Every couple of years someone
dissatisfied with something about
the benchmarks game (often some
detail about the code repository or
website technology) starts a project that will
fix everything they dislike about the benchmarks game.
As a resource the most obvious problem with those
projects is that they never seem to get
close to publishing performance
data.
Every year some group of programmers
campaigns to have language X
included in the benchmarks game,
while some other group demands that
some program is included (or
excluded).
Sadly, they rarely accept that among
the resources provided by the
benchmarks game are
scripts they can use to make and publish language performance
measurements
examples of which basic information (language version, build
commands, run commands, measurement
techniques, ...) is required to provide context for the measurements.
They rarely accept that they are
empowered to create what they wish
to see.
The benchmarks game website is now back to normal!
From Friday 20 May 2011 through Monday 23 May 2011, ALL alioth.debian.org subdomains were down - because the alioth admins were upgrading "in every way we can find: kernel, Debian release, FusionForge software, hardware, and so on."
In addition, making the benchmarks game website work again required:
installation of the GD library on the new server, for chart generation
basic information about changes to ssh use on the new servers
basic information about the project cvs repository on the new servers
basic information about the project /htdocs location on the new servers
replacement of the long deprecated
$HTTP_GET_VARS by $_GET in a couple
of dozen PHP scripts
Since the performance benchmark site
for Programming Languages (aka
Programming Language "Shootout" &
shootout.alioth.debian.org) is
permanently down ...
The original question was predicated on a false premise.

What do you do when you're suddenly thrown onto a large project? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I recently started a career in software development after graduating a couple of years ago in CS. The current project I'm on is a large ongoing project that has it's origins in the 90s with a mix of C, C++, and Java. There are multiple platforms (UNIX, WIN, etc) being supported, older technologies in use like CVS, and some dated documentation in some areas.
The extent of my software development skills stem from going to university as I've had little real world experience. I felt like I had a decent foundation in CS but I cannot but help feel slightly overwhelmed by it all. I'm excited to be part of something so huge but at the same time I feel like it's a lot of information to absorb.
My coworkers have been great people and answer a lot of questions I. My employer hired me knowing that I am entry level.
I've tried poking around the source code and examining how everything gets built but it's on a scale I've never seen before.
How do more experienced people situate themselves when joining a large ongoing project? What are some common tasks you do when getting yourself up to speed?
Good question. I haven't had your exact experience, but in cases like this I like to think, "how do you eat a whale?" The answer is (predictably) "one bite at a time." Reasonable people won't expect you to grasp the whole thing immediately, but they will want to see progress. Perhaps there are some small areas of the larger project that are not too complex, without too many dependencies. Work toward understanding one of those and you're one 'bite' (and/or 'byte') closer to expertise on the whole project.
Being familiar with all existing documentation I would try to get the big picture. Literally.
generate a TreeMap of the source code
I would use GrandPerspective on Mac or WinDirStat on Windows. It will give you some insights about the structure of the project's files (sometimes it gives some hints about the code structure). Having this, you can ask your colleagues for some of the clusters, what they do, how they relate to each other.
learn how to build the project
This is important to have it compiling all the time if you are about to do any changes. Having tests executed at the build time is always a good thing, so ask for it also. Even better if there is some kind of continuous integration server in place. If there is, look at its configuration - figure out how the build is done. If there was no CI server, but you already got the knowledge how to build the project, create such a server on your local machine, and show it to your fellows - they should fell in love with it.
browse the source code with Structure101 or similar tool
This is useful especially for Java projects. This tool does great job. That will give you more details about the code structure, and sometimes about the system architecture. This experience may be sometimes hard, you may learn from this tool that a code is basically a Big Ball of Mud ;)
look for tests, and explore them
If you will be lucky there may be some JUnit, or CPPUnit tests. This is always good to try to understand what those tests are doing. It may be a good starting point to explore the code further.
My coworkers have been great people
and answer a lot of questions I. My
employer hired me knowing that I am
entry level.
You have little to worry about, you're employer knows what you are capable of and your co-workers seem eager to help you out - to be honest most developers love explaining things to others...
From what I've seen, it take truly 6+ years to become fully knowledgeable in a language, so don't expect to become a guru within a year... and even these so called gurus end up learning something new about their language everyday.
Learning a new system (large) will always take time.... the systems were usually not built in 2 weeks but over many years, so don't expect to understand it fully yet. You'll eventually discover what each part does piece by piece.
I know how you feel, because I felt like that once...
"I took a speed reading course and read 'War and Peace' in twenty minutes. It involves Russia." (Woody Allen)
I agree on what the others said before me. You need some tools that give you an overview on the code. I personally used inFusion (http://www.intooitus.com/inFusion) because it gives also other interesting data beside structure.
The method that has worked best for me is to grab a copy from source control, with the intention of throwing this version away...
Then try and refactor the code. It is even better if you can refactor the code that you know you will be working on at a later stage.
The reason this is effective is because:
refactoring gives you a goal for you to aim towards. Whereas "playing" an "breaking" the code is great - it is unfocused.
To refactor code you really have to understand the code.
Refactored code leaves code that has less concepts to retain in memory. If you don't understand a large codebase its not because you are a graduate - its because nobody can retain more than 7 (give or take a few) concepts at a time.
If you follow correct refactoring guidelines it means you will be writing tests. Although, make sure that you will be working on the modules that you are testing as writing tests can be very time consumning (although very rewarding)
Do invest in buying this book at some point:
http://www.amazon.co.uk/Refactoring-Improving-Design-Existing-Technology/dp/0201485672
But these links should get you started:
Signs that your code needs refactoring and what refacoring to use (From Refactoring - Martin Fowler)
http://industriallogic.com/papers/smellstorefactorings.pdf
A taxonomy of code smells:
http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm
Good luck!!!
I agree to the first comment but I also Think that you have to learn and see the big picture in some way. You have to trace the main flow from code at least.
I was in the exact same situation several years ago when I joined a software project with 50+ ClearCase version control vobs, 5 million lines of code, and some of it dating back to the 1980's.
The first thing I did was look through every source controlled directory and made a quick summary of my best guess about what the software in that folder did and what language the code was. You can make a pretty good guess by looking at filenames and any comments or documents in those folders.
I then looked at the build scripts to see if they were readable enough to get an idea of dependencies between different parts of the code.
Finally - and I believe this was the most valuable - throw an IDE like Eclipse or NetBeans on top of the code and start reading through pieces of it. Having the ability to jump to the definition of any functions or classes using the IDE allows you to move around a massive software baseline with relative ease.
Overall, have some confidence - it is unlikely that anyone else on the project knows all of the code, so you don't need to either. Use what other people said to get a good idea of the overall project and interfaces and requirements (if they exist) and poke through the code to get an idea of the most commonly used classes and methods.

Why does Ruby seem to have fewer projects than other programming languages?

I've found Ruby to be very attractive; I like the fact that everything is an object and its syntax is very appealing.
I was hoping that it would gain a lot of popularity this year, but I don't see lot of activity in Ruby.
For instance if we take the number of tags added in SO there are only about 700 questions tagged as "ruby." This may be because:
Ruby is so easy, noone has any questions.
This site attracts more from the.Net community and Ruby developers ignore its existence.
There are not as many Ruby projects as there projects in other programming languages.
Other resources show Ruby is not as popular as other programming languages.
What reasons do you think are behind this?
Links:
TIOBE Programming Community Index for October 2008
StackOverflow tags
Ohloh
You're mistakenly attributing something to Ruby. RubyForge alone reports over 1,000 open-source projects, let alone all Ruby on Rails apps that exist, and the projects hosted on Github, Sourceforge, and elsewhere.
Unless you spend a lot of time on other sites (Reddit is a good example) you will be unaware of just how .NET/Oracle/SQL Server/etc.-centric Stack Overflow is. (I use a Greasemonkey plugin to hide a broad swathe of these Windows- and "Enterprise"-centric technologies, because they don't interest me.)
I actually had the complementary experience to you: I started spending time on Stack Overflow, and had something of a "woah" moment when I realized just how many people spend their days futzing with ASP.NET. That's not a world in which I'd spent any time, so I had underestimated its size.
Some parts of the internet (e.g., Reddit) are primarily concerned with free software and its associated languages: Perl, Python, Ruby, PHP.
Some parts (e.g., Lambda the Ultimate) are concerned with more esoteric languages: Haskell, Lisp, Joy, Coq.
Other parts (e.g., Stack Overflow) are more mainstream: Java, .NET.
You cannot draw any conclusions about the popularity of a language by sampling just one of these 'pools'.
Ruby had its moment in the sun in 2005 - 2006 when Rails was making its way through the community and Apple decided that it would package it with OS X. So to pick 2008 as the year for Ruby to gain a lot of popularity seems amiss to me.
The Ruby language itself is, as you stated, very attractive. Its syntax and OOP model are what make it a hit with developers. You get equivocally the same product as you would with another language, but with what feels like less time wasted on internals.
Rails is really what I think is holding Ruby in the mainstream right now, more or less because of its ease-of-use and database handling. Web developers love it for that.
If you really want to see sites that have a lot of Ruby(on Rails) chatter on them, you could check out http://refactormycode.com or http://pastie.org. Those websites are built on RoR and are used very frequently by Ruby(on Rails) users.
Regardless of any real numbers, one thing I do know: When I go to look for a Ruby library for something I'm working on, I find something satisfactory over 90% of the time. And for some of the remaining 10%, it isn't that hard to write something myself. I do believe that 90% figure will rise over the next few years, too.
If I get what I need, I don't really care whether PHP or Python or C# has sixty bajillion applications and libraries written for them. :)
I find Ruby very attractive in several ways, but it has some issues holding it back.
The biggest I think is that Python already covers much of the same ground, has a larger library of projects, and thusfar better performance.
The other main problem I've had is also the thing that keeps it so popular: Rails. I think there are a lot of people that don't even think of Ruby as a standalone language. While I appreciate that Rails is supposed to be pretty great, it is not anything I deal with, and thus I get annoyed at having to wade through so much discussion of Rails to find an answer to a question in Ruby as a standalone language.
One last thing that has made me skittish about it is the 'more than one way to do it' philosophy it shares with Perl. I was not a fan of that.
It is really a matter of their already being a few hammers around, and Ruby's main distinguishing feature that most people tout currently is Rails.
There's a lot of activity with Ruby in web-based development. You just have to join the right communities and lists.
I don't think it will ever be as popular as C/C++ (because of the existence of already deployed code and a developer base) or Java (because I imagine it isn't quite as easy to understand at first).
2 - Not many rubyist come here. I you look there is a TONNE of Ruby projects. Just not here so much.
Check out what is happening on Github, rubyforge etc. I mean, Rails for starters is massive.
Here's my theory:
Industry Adoption - Although ruby is used in the real world, other languages (e.g. Java, C++, C#, etc.) have been accepted as "safe languages". No one ever got fired for picking Java, or C#, but CIOs' eyebrows have been known to raise when ruby is mentioned.
Talent Pool - When selecting a language, you want to know that you can find a good pool of talent. The more popular the language, the larger the pool, and the greater number of experts (statistically) (statistics do lie 50% of the time ;) ).
My hopes:
I believe the ruby talent pool will grow over time and the productivity offered by ruby will present a huge incentive for its adoption.
More and more colleges will teach it.
Please don't take TIOBE too seriously. Checking search engines for instances of "language-name programming" as some sort of indicator of popularity isn't very meaningful.
More than likely because it is younger than a lot of other languages and, on the web side of things, isn't as easy to implement as PHP and Python. Ruby has also gained notoriety as a web scripting language due to Rails which may be turning off some developers who are looking for client-based languages to work with.
Is Ruby not popular? I think it is but it hasn't really reached a critical mass yet to be widely accepted.

What real-world projects would you suggest as code examples to study?

What real-world projects would you suggest looking through the sources?
As I'm learning Java Swing, mucommander seems to be a decent example. The code is excessively commented though.
EDIT: No shameless plugs plz :).
I learned a lot from looking at the source code to GoGrinder. It's well thought out, uses MVC correctly, and the comments are helpful (and no, I didn't write it). It's also a fun program to use if you want to learn how to play Go.
For Gui design, Patterns and general good advice I highly reccomend Jeremey Miller's series of articles on building a better CAB. For C#, but equally applicable to Java. Also using
the MVC style which Stackoverflow follows, and Apple uses for Interface Builder.
Build your own CAB
Jeremy's articles/ideas are followed in his own project, which you can download and inspect at http://storyteller.tigris.org/
Take a look at the Windows version of truecrypt. It is one of the best organized open source projects I've ever seen. You can almost tell how the whole thing works just from the directory and file layout.
What I've done to learn some new technologies over the years is to look to open source projects that both match the criteria you're looking for and also interest you.
I'm not a Swing guy, but I'd suggest finding a project that uses Java Swing, does not appear too complicated, and then start digging through the source. The nice thing is you can then see the app before you start poking through it, and then you can see what happens as you change stuff.
The idea behind picking something that interests you is that it will keep you engaged. I am intrigued by content management systems, so I might download a CMS that I can then see how stuff works, and I'm engaged because the problem domain of the project fits in with an interest.
I've done this once or twice when I had to get up to speed on C# and I think it works will. YMMV....
Some of the most well thought out source code ( c++ ) I have seen in an open source project is the Ogre3D graphics engine, I've learned a lot about OOA&D just by looking at the structure and reading the comments. It is also well maintained and the community is very active.. http://ogre3d.org

Resources