If you're only going to learn one programming language, you should learn...
Posted: 21 Jun 2016 | 07:59
Choice, choice, choice
I'm often asked "What programming language should I learn for scientific computing?". Or I get involved in religious-like discussions about the best programming language for a particular task, or of all time (think Python vs Fortran, Go vs C, etc...). What's my answer?
Just recently I realised that, to me, programming languages are like musical instruments.
Our daughter is learning to play a couple of musical instruments. She started off with the bagpipes. Actually, you don't start learning the bagpipes, you learn the chanter, which is what you use to play the tune with the bagpipes but you don't need to learn all the technically-challenging aspects of inflating the bag etc (it's a bit like programming without having to learn types, or memory addressing).
She's also had to learn to read and understand music, a whole new language in itself.
More recently, she's also taken up the fiddle (violin). On the face of it, there are very few similarities between the two instruments, and having started learning the chanter does not seem like it will be a benefit for playing the violin, except that both require the understanding of a common language: music.
Having already learned to read music is a benefit when starting any new instrument. The core language is the same and so it's a transferable skill.
The interesting thing is that learning the violin has significantly improved her chanter playing, and in a very short space of time. Because of the difference in playing method, it's very easy to understand and focus on timing and rhythm. Playing with a bow means that there is little extra effort in holding a note, or in playing notes quickly. The same isn't true of the chanter. Holding a note for longer requires blowing for longer, which requires co-ordinating breathing and playing. This means that it's hard to get the rhythm of a tune correct.
Therefore, learning the chanter helped with the fiddle, it provided the basic music skills required for any instrument, and learning the violin has helped progress skills on the chanter. Learning two different instruments seems to improve the playing skill more than simply spending twice as much time on a single instrument, because each instrument has different strengths and weaknesses, different aspects that are hard or easy to master.
Variety in programming
Of course, the point of my ramble is to try to highlight something that I think is relevant to programming. Different programming languages have different strengths and weakness, different aspects they can make easy when writing a program and aspects they will complicate. Some languages are very focussed around testing and validation, but this can complicate performance or reduce access to some functionality. Other programming languages are designed to give low level access to hardware, but can be easy to write complex, hard to understand programs in.
We always try to teach choose the language that is best for the job, not just the language you know. In practice this can be hard to do, and there are often many languages that could be appropriate for a given task, so using a language you already know and are confident with often isn't a bad choice. However, if you've only ever learned and used one programming language, or one style of programming language (ie functional vs procedural, interpreted vs compiled, high-level vs low-level) it's likely that your thinking around programming is very structured around that language.
Learning, and using, at least two programming languages, preferably different styles of language, can significantly help your understanding of the fundamental concepts of programming and using computers, and therefore let you better design and create sensible, well structured, tested and functional codes. If you're primarily writing programs for computational simulation then Fortran or C are still excellent choices as your first programming language.
Multiple is good
But don't stop there, learn Python or Java or C++. Any of these will nicely compliment C or Fortran, provide access to data processing and GUI facilities you generally can't easily implement in C or Fortran, and give you a different perspective on programming in general. Playing with experimental or new programming languages as well (Go, Erlang, Clojure, Haskall, Chapel, etc) can all bring different perspectives to your coding, widening your programming horizons, and highlighting areas you might want to focus on when writing your codes.
Finally, don't get too entrenched in any one programming language, we all have favourites, but there is no right choice for most programs, only choices that will make the programming easier or harder, safer or more risky, easier to maintain or harder for others to understand. And not all of this is down to the language, it's easy to write poor programs in most programming languages, so always program assuming you're going to need to understand the code you've written in a hurry in 20 years' time. That way you'll document and structure it in such a way as to easily enable others to understand and maintain your code.