views:

54

answers:

4

Question: Is there a repository, a wiki, of code samples?


I'm trying to learn a couple new languages, and I just wish that there was a library of code samples of the same code in different languages. I can't seem to find anything like this, and I was wondering if anyone knew of a site like that. Something that has code samples doing various different things across multiple languages. Kind of like Project Euler but with code samples I can see.

A: 

Well, Wikipedia often has code examples in multiple languages. For example

Wikipedia Singleton Pattern

The trouble is finding all the pages :)

Lawrence Tierney
A: 

Little bit of googling brings Wiki on Comparison of Programming Languages with external link to www.scriptol.com and other interesting references.

K. Claszen
+1  A: 

Rosetta Code is exactly what you described. For example, going to their quicksort page will get you code snippets in 56 different languages. Of course, different pages have varying levels of completeness - quicksort is definitely one of the better examples.
Wikipedia sometimes includes the same information, too, but just as often will leave such examples for the external links. (For comparison, their quicksort page - no code! They may also include a lot more things you don't care about.)

Larry Wang
+1  A: 

What you probably need is a book like Concepts of Programming Languages. Not only does it provide varied code examples but also goes over things like threads, recursion, binding, OO, functional, and all other sorts. There are also problem sets at the end of each chapter. After mastering this, you should be able to pick up any language within a couple weeks just using a reference book/documentation.

buckbova