Schliemann's method of programming language learning
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 Bibl开发者_高级运维e, 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.
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.
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.
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;
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.
精彩评论