Thursday, October 27, 2011

Teaching a second programming language

If a Chinese person who has been learning French for a year now wants to learn Italian, how do you go about teaching them Italian? You don't start from scratch and painfully relate Italian to Chinese: instead, you leverage their knowledge of French and teach Italian as, roughly, a variant of French: you highlight the delta between those two relatively close languages.

Similarly, after 6 weeks of teaching Racket I have now switched to OCAML: last year the way in which I did it was to teach OCAML from scratch, only going much more quickly than when I started Racket 6 weeks before. As I was doing it, I realized that it was largely redundant and boring. So this year, I simply show OCAML and corresponding Racket code side by side, so that the students see that many of the differences are simply syntactic details that can be translated automatically. That gives me more time to focus on the differences and try to figure out the reasons for those differences.

In hindsight, it is obvious.

I wonder if there are any web resources to serve that kind of requests: "I want to learn computer language X; I already know computer language Y".

14 comments:

  1. American universities explicitly teach programming languages?! Over here in Europe, you take more general classes on algorithms, design patterns, or functional programming and are supposed to pick up the particular language used in the exercises by yourself... I mean, getting started in another programming language with operational semantics, once you know one, is really no big deal. (mastering the idiomatics or libraries coming with one particular language is of course another topic). Teaching one particular language, which might be en vogue this decade and obsolete next decade, is probably not a great investment. Getting used to generic concepts and getting familiar with switching languages (rather than staying stuck) is what I would expect a university to prepare students for. For example, my evolution was from Basic -> Pascal-> Pascal+x86 ASM-> C -> C++ -> Java -> Python with no big issues. It's all operational semantics, with a little bit more language-level support added for this and that design philosophies. For the first step "Pascal -> C" I used a book teaching C for people with Pascal background, back in the 90ies. Switching to declarative and/or functional programming is another matter. There I took a "functional programming" class which had Haskell as example language. But I also did give Common Lisp a try.

    ReplyDelete
  2. maybe there's something like the following for programs other than "Hello world" as well
    http://en.wikibooks.org/wiki/Computer_Programming/Hello_world

    another cool web resource would be:
    I already know paper X (or papers {X_i}) and I'd like to understand paper Y

    ReplyDelete
  3. This is a slightly off-topic question: I would like to know how you prepare your programming classes.
    One issue is that you do not have extensive programming experience from your research work (this is what I gather from some of your previous posts).

    So how do you learn the material: do you try to learn it in the same way as a mathematical topic (by reading a book on, say, OCAML) ? Do you try to get some "hands on" experience and how ?

    Just a question from a curious theorist...

    ReplyDelete
  4. Anonymous: actually in algorithms I like to teach from examples, starting from something concrete and then going from there to an abstraction. I think that the same goes for "generic concepts" in programming. I couldn't possibly teach them without the support of a particular language. Also observe that many students arrive with zero knowledge of programming.

    I think that teaching a second programming language is great as a concrete way to get students familiar to switching. (And as you point out, it's not such a big deal: in terms of lecture time, it took just one week of the semester.)

    Christian: I think I've seen that before. I must say that I don't find it very illuminating, but it's fun anyway.

    Pascal: the truly wonderful resource I have are my TAs. I could never do it without them. There are lecture notes, I can focus primarily on the high level, and they deal with all the difficulties that go with getting things to actually work. My only "hands on" experience is when I test some of my code before lectures or jot down the occasional draft for some exercises.

    To be fair, this is not a project-oriented course. The programs tend to be short pieces of code that are just a few lines long, so the course design is appropriate for theorists.

    ReplyDelete
  5. Claire, this is a stylistic note regarding your post that I think is important to make. In the phrase "If a chinese who...", the use of "chinese" as a noun to refer to a single individual carries connotations of racism/discrimination, and is therefore considered derogatory. The same is true of "black", "italian", or any other nationality or ethnicity if used as a singular noun. The uncontroversial variant of this sentence would be "If a chinese person who...". Obviously, it was not your intention for this post to be deragotary, but rather this might be a function of English not being your first language. I just thought that you should be aware of this.

    ReplyDelete
  6. Thanks for pointing that out. I had no idea that there was any kind of connotation. And, indeed, the turn of phrase is a literal translation of the French "un chinois".

    It is now fixed.

    ReplyDelete
  7. I agree that "a Chinese" sounds strange (although not necessarily derogatory) but I don't agree that there's anything wrong with "an Italian" (which is a direct translation of "un/una italiano/a"). In some cases --- e.g., I'm a Canadian --- including "person" after the nationality sounds pedantic. I don't know how we decide to call someone from France a French person (or perhaps Frenchman/woman when the sex is known?), someone from Italy an Italian, someone from Finland a Finn, someone from Uzbekistan an Uzbek, etc, but that's usage (n.b., with capitalization).

    ReplyDelete
  8. "chinese" is not a noun but an adjective, as is "french" or "british". Therefore you need to say "a chinese person". On the other hand, "italian" is both an adjective and a noun and therefore can be used for both.

    ReplyDelete
  9. Re: Anonymous 4
    "chinese" can be used as an adjective or as a noun (See OED.) When used as a noun it is always capitalized.
    As a noun it has two meanings: it can denote a person, or people from China (the plural form is also "Chinese") or it may refer to the language.

    The usage is exactly parallel to "American". You could say "He is an American person" but it is pedantic and somewhat superfluous, unless in a context like "He is an American person, not an American werewolf."

    English is not logical, like French. You would not say "a French", but "a Frenchman", although you do say "a Brit", "an Italian", and "an Estonian." I guess the ambiguity about "a Chinese" comes from the fact that there are many contexts in which "chinese" acts as an adjective,
    even in composite words (Chinese lantern, chinese pear, etc.)

    ReplyDelete
  10. Pointing out similarities and differences is a rich learning method. I do something very similar when transitioning from a familiar programming language to an unfamiliar programming language as well. I find it also works really well when comparing algorithms, especially when analyzing run-times.

    ReplyDelete
  11. Even if "Chinese" can be used as a singular noun, that sounds wrong/derogatory to me as a native speaker of American English.

    While one would not say "a French" (I don't know what OED says but that sounds wrong!), you can always say "the French", "the British" or "the Chinese" to denote the plural, i.e. the people from that country, and that does not sound bad at all.

    So, while I was incorrect saying that "Chinese" is not a noun, it sounds offensive to me in the singular form. But then to me, "a Jew" or "a Black" sounds more offensive than "a Jewish person" or "a Black person", although I do not know why this is. I think that this may be that when there were historical cases of discrimination in the US against a class of people, then using the classification of that person as a singular noun sounds discriminatory. There was widespread exploitation of Chinese people and widespread discrimination against Jewish people in this country, so maybe that is where that comes from.

    ReplyDelete
  12. Apparently resources/books on C++ -> Java, C -> C++, JS -> Python, Ruby -> Perl and even .NET -> COBOL programmers do exist. http://www.google.co.uk/search?q=%22*+for+*+programmers%22 . For comparing algorithms in languages, Wikibooks is a great resource http://en.wikibooks.org/wiki/Algorithm_Implementation

    ReplyDelete
  13. Awais, the wikibooks resource is great. Very incomplete, but once people have added to it, it'll be a wonderful resource. (I just looked up Fibonacci numbers in scheme ~= racket and in OCAML). Thanks!

    ReplyDelete
  14. I learned Java from chapter 2 of "Java in a Nutshell," entitled "How Java Differs from C". It was absolutely superior to learning Java ab initio, and shorter too.

    ReplyDelete