Wolfram|Alpha: Systematic knowledge, immediately computable.

Wednesday, April 7, 2010

What programming languages should you learn?

I get asked periodically "What programming language should I learn to build my own games?".

Most games built today are done in C and/or C++. So I suppose, if you are looking to enter the game development field, learning one or both of those should be a priority. I like to think of the question in more general terms myself, more along the lines of "What programming language should I learn if I want to learn how to program?"

Having taught Lisp to engineers, I've seen the value of exposure to different paradigms in developing maturity in programmers. Were I to build the 'ideal' coursework to teach a 'How to Program, from Scratch' curriculum, I think I'd follow this course:

1) Assembler. Little practical use for building a new piece of software. Frankly, the speed of code produced by modern compilers of high-level languages is so good that in most cases only the most experienced human coders can better them. And yet, by learning this most basic lingua franca of the machine, the budding programmer will be exposed to thinking in the same way the machine 'thinks'. I for one believe this leads to more sane considerations as to the efficiency of their code. Of course, the ability to debug/disassemble/analyze applications where the source code is unavailable means knowledge of assembler is invaluable.

2) C. The mother tongue of many operating systems, still one of the most widely used application development languages. A good first step for the beginning programmer to get a foundational understanding of basic programming techniques and structure.

3) Java. Introduces, in a framework easily grasped by someone with C experience, the concepts of Object Oriented programming. One could argue there are other environments that do the job better (Ruby, Python, etc.), but the wealth of excellent teaching materials, and the availability of real jobs in the real world, makes this my choice to teach the OO concepts.

4) Erlang. Originally developed by Ericsson, this language introduces the learner to the world of distributed, fault-tolerant, concurrent programming. The conciseness of the language for its intended purpose allows for easy experimentation in these arenas.

5) Forth. Stack based, non-explicit grammar. I include this as an excellent environment for the learner to look at problems from a completely different angle.

6) Lisp. Functional programming at its best. Were I forced to pick one language for someone to learn if they are learning to program from ground zero, this would be it. Lisp has had features and functionality that are still unequalled overall by any other language. Even though every other language of import has evolved over time, adding features and capabilities (and becoming more lisp like), this still holds true. The mind expansion that results from really understanding and using the capabilities of the language will make one a better programmer in any language, even if they never use lisp again. The electric acid kool aid test for new (and experienced) programmers.

7) Mathematica. What? A mathematical computational software system? Yes! I use this product for various modeling and mathematical processing tasks. It utilizes an extremely sophisticated programming language that can be used in any of the traditional programming modes (imperative, OO, functional, rules-based, etc.), and can combine these methods in a single code chunk. The term rewriting reduction system that pervades Mathematica makes for one-liners that can require many lines of code, or even pages, in other languages. Memoization? In Mathematica, the one line:

Fib[0]=0; Fib[1]=1; Fib[n_] := Fib[n] = Fib[n-1] + Fib[n-2]

Gives us the Fibonacci function, fully memoized. Compare this to a Python (already a more concise language than most) implementation:

memo = {0:0, 1:1}
def fib(n):
      if not n in memo:
               memo[n] = fib(n-1) + fib(n-2)
       return memo[n]

Isn't the Mathematica solution so much more elegant and readable?

Not only does this allow for remarkably rapid 'proof of concept' experiments, but it also serves as an excellent environment to experiment with the many ways of solving the same problem. If I'm not using Lisp to prototype something, I'm probably using Mathematica. I used Mathematica to create the animated image of the Sun's analemma and the relation to the equation of time, by calculating the Earth's orbital elements and their effect on true and mean solar time. You can take a peek at it on the wikipedia entry Equation of Time, or the image itself at Analemma and EOT.

I'd probably throw in some SQL for good measure. This bag-oriented (that's right, not set-oriented, nor relational for that matter) language is the most widely used query language for large database systems. That the thought process needed to produce well-formed, optimal queries using this is different enough in concept from the paradigms of the previously mentioned languages, not to mention any large data based system is likely to have some form of DBMS under the covers that uses SQL, makes this a worthwhile addition.

Each of these I think forces the programmer to think differently enough in how to approach a problem they can't help but end up with an expanded 'thought portfolio' to use in attacking future problems.

Your thoughts?

2 comments:

  1. Just stopping by to say: great blog, and great post (I heard your website mentioned on BASH & SLASH and decided to check it out).

    There's one language I might suggest to beginners with a scientific background/application in mind: Fortran (95, not the older versions). While you might argue that most of the scientific computing is done in C (at least the stuff that's too involved to do in Mathematica/Matlab), Fortran beats C in terms of number crunching on any day. Thus, Fortran is the language of choice in high performance, scalable computing today (at least in my field).
    Plus, it is not as arcane as C and a little bit easier to read, as well as somewhat strikter in terms of syntax (the experienced programmer tends to frown upon those two points, but the novice will rejoice :) ).

    We tend to teach our undergrad students (aerospace engineering) Matlab to get them going, and switch to Fortran later.

    Anyhow, great post, I enjoy your blog!

    Andrea

    ReplyDelete
  2. I agree completely - Fortran is so widely used in the scientific community, it would be wise for the science student to learn it. Unfortunately, it's getting harder and harder to find decent Fortran programmers.

    That said, the features that made it particularly attractive for this kind of computing (Fortan being one of the first to offer robust parallel features) can be found now in most other advanced languages, and things like GPGPU (I was using this back in the Brook days of Ian Buck, before he moved to Nvidia) with Cuda & Tesla hardware dictate C as the language of choice - though there are good wrappers for Matlab and Fortran too :-)

    Thanks for the comment!

    PS - if I might ask, where do you teach?

    ReplyDelete