views:

373

answers:

4

Background: 19th-century German archeologist Heinrich Schliemann was of course famous for his successful quest to find and excavate the city of Troy (an actual archeological site for the Troy of Homer's Iliad).

However, he is just as famous for being an astonishing learner of languages - within the space of two years, he taught himself fluent Dutch, English, French, Spanish, Italian and Portuguese, and later went on to learn seven more, including both modern and ancient Greek.

One of the methods he famously used was comparison of a known text, e.g. take a book in a language one is fluent in, take a good translation of a book in a language you wish to learn, and go over them in parallel. (various sources cited the book used by Schliemann to be the Bible, or, as the link above states, a novel).

Now, for the actual question.

Has anyone used (or heard of) an equivalent of Schliemann's method for learning a new programming language? E.g. instead of basing the leaning on references and tutorials, take a somewhat comprehensive set of programs known to have high-quality code in both languages implementing similar/identical algorithms and learn by comparing them?

I'm curious about either personal experiences of applying such an approach, or references to something published, or existance of codebases which could be used for such an approach?

What got me thinking about the idea was Project Euler and some code snippets I saw on SO, in C++, Perl and Lisp.

+3  A: 

It's unlikely that the best way of implementing something in one language follows the same pattern in another. It's therefore very difficult to find points of correspondence. Taking this approach is likely to teach you how to program badly in the language you are learning - look at all the bad, Java-like code written in C++ by people with Java as a first programming language.

Edit: Typical java in C++ code:

string * s = new string;

instead of the C++ way:

string s;
anon
Neil - I know conceptually what you're talking about (from seing C++ written in Perl), but I'd be curious what a typical "Java written in C++" looks like if you have an example handly
DVK
Java written in C++ - Catmother http://catmother.sourceforge.net/
fuzzy lollipop
nice Example... +1
DVK
that is actually some of the cleanest C++ I have ever seen.
fuzzy lollipop
+2  A: 

Programming languages are less about syntax and more about idioms. I really doubt you could do a side by side comparison of say Apache source in C and YAWS in Erlang and actually learn either one of the languages in either direction. Say you know C what do you do when the language you are learning has single assignment variables, or no ternary operator. There very few 1:1 mappings even among impendence matched languages like OO languages. I mean C++ doesn't map 1:1 to Java or Python and they are all OO in nature.

fuzzy lollipop
That is correct - but you can see, for a simple example, a loop-y and recursive implementations of a factorial, and then see a map/reduce approach to the same in perl - which will teach you nothing about factorioals but LOADS about how things should be done in Perl (e.g. map/reduce approach)
DVK
Basically, I was thinking slightly (or significantly) smaller elements being compared than a full web server
DVK
what Schliemann was doing was reverse engineering syntax and grammar. What is more important when learning a new programming language is the over arching idioms. Imagine trying to learn how to write Chinese poetry while only having the Chinese and English versions of the Tao te Ching [http://en.wikipedia.org/wiki/Tao_Te_Ching]. That is why it is important to compare larger corpus of code in total. You can't capture the personality or flavor of a language unless you look at a large piece of code, except Perl, even small pieces of Perl suck! :-)
fuzzy lollipop
And these days, Standard Libraries, "Batteries Included", etc. are more important than how to write a loop or a switch statement when there are things like list comprehensions built into languages and/or their standard libraries.
fuzzy lollipop
+6  A: 

I would expect Schliemann's method to work very poorly, because one of the points of creating a new programming language is to introduce new objects of discourse and new means of transferring control. In Schliemann's method of comparing two texts, the objects of discourse are always the same, only the language used to talk about them is different.

  • For example, method dispatch and inheritance are inherently new things. So maybe if you know Simula-67 you can learn Java, and maybe even you can stretch to learn Smalltalk or C++. But you can't possibly learn Tcl or Scheme or ML or Diesel because single inheritance and dynamic dispatch just aren't there.

  • Similarly, if you've only ever seen C or C++, or maybe even Pascal/Ada/Modula/Clu, nothing can really prepare you for the power and expressiveness of first-class functions.

  • As another example, how you can you compare solutions to string-processing problems if one language (Perl) has regular expressions, a second (SNOBOL) has pattern matching, and a third (Icon) has string scanning? Your poor head will explode!

Schliemann's method may have its uses if the languages in question are very similar. Say you know Java and you want to learn C#, or vice versa. Or change between languages in the OCaml/F#/SML family. But in most cases I suspect Schliemann's method will do you more harm than good.

Norman Ramsey
+8  A: 

Rosetta Code may be useful. To quote the site:-

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. Rosetta Code currently has 372 tasks, and covers 197 languages, though we do not (and cannot) have solutions to every task in every language.

Strawberry