What programming language should I use?What are the differences between them? - Peter9192/MAQ_PhD GitHub Wiki
If you do not have much experience programming, you may soon feel flooded by the ocean of programming languages and come up with this question. And that is why in the folowing lines we will give you a brief explanation of strong and weak points os the languages we use most at the department: Python, Fortran, R and the basic bash scripting. If you just want a fast answer on which language to use for which purpose, go to the last 2 paragraphs. If you enjoy taking your time in life, you can read from the beginning.
Bash scripting is the most direct way to talk to a computer. Since this is a not very user-friendly language, I would rather leave it for handling files, renaming, moving and other easy tasks that you would do without too many calculations and, of course, do not even think of plotting.
As everything in life, you usually need different tools for different purposes. In the same way you would not use a chainsaw for cutting your nails (creepy idea, huh?), you will not use certain programming languages for unintended purposes. Thinking on Fortran vs Python vs R, there are few things to consider: Fortran is, as far as I know, one of the oldest (if not the oldest) programming language. However, it is also true that it has had several updates and releases of new versions (last one was in 2008 and there is one planned to be released in 2018, as far as I know). It is seen as an old-fashioned language by computer scientists and engineers, but is the most used language when it comes to physics and large models (lime climate models, for example) together with C or C++. Fortran is good for complex calculations, especially when they consume quite some computational time and effort. Fortran code can also be parallelized, meaning that it can split the internal processes of the program in different processors and thus speed up the calculations. This is of special importance for large models like GCM models or LES simulations. However, it usually takes long to write and run Fortran programmes. Fortran is slow when reading and writing files. It also requires any variable used to be defined at the beginning of the programme/function/subroutine. Additionally, if what you defined has more dimensions than 0 (so it is NOT a scalar), you will need to give the dimensions when defining the variable. One way to get around this definition of dimensions is to allocate and deallocate the variable, which is nice but also takes some time to program. Although it contains several built-in functions (like trigonometric functions, for example), the number of them is quite limited compared to other languages. Another drawback is the fact that Fortran, as one of the first programming languages, needs to be compiled ad run after the code is written. Going more into detail: when you write a Fortran code, you will have to save it. Then, you will compile, which is something like translating your human written script to a language understandable by the computer. After compiling you will get an executable, which is the file you actually need to execute, so that the computer does, through the compiled files, what you wrote in the script.
On the other hand, Python is a more user-friendly language. It is a more broadly used programming language, not just by physicists or meteorologists, but a wider scientific community as well as industry. Because of this, it is usually easier to find hints, answers or manuals on the internet about it than Fortran. There is no need to define variables, you can use them right away and Python will understand what kind of variable it is, depending on what you are linking the variable to. It is a more intuitive language and by loading different modules depending on your needs you can have a lot of built-in functions. A nice feature is that it is an interpreted code, meaning that there is no need to compile and run the code as in Fortran and other classical languages. In Python, you just execute the script and it will automatically run it. By loading certain modules (matplotlib for example), Python can provide you with very nice plotting and graphic tools.
Finally, the R language is not regularly used at our department, but can nevertheless come in handy in some cases. It can be downloaded freely (https://www.r-project.org/). R is especially useful for statistical computing, as it contains packages for very specific statistical tests and techniques. As such it is a good alternative for statistical packages as SPSS and SAS. R can also be used to create all sorts of graphics, such as polar plots and spatial maps. Like with the Python language, you can download and compile a wide variety of community-developed packages. Usually a manual is available online for each package. Also with R there is no need to compile the code. If you like a more user-friendly interface, the use of R Studio is recommended which is very easy to use (https://www.rstudio.com/).
Summarizing, Fortran, Python and R are three languages that do not necessarily compete with each other, since they have different strengths. Since Python and R are faster to write and more user-friendly, I would recommend using them for everything as long as you do not need too costly and long calculations. That is, usually what you do in post-processing (including the generation of plots) unless you need to calculate some crazy variables. Going back to the chainsaw, if we see Python (or R) as small scissors, I would rather use them for everything I can. I would use the chainsaw (with the effort it takes to hold it and use it) only when I see that the scissors (Python/R) are not enough for the big tree (complex calculations) I am facing. If you are making complex and large numerical calculations, then I would switch to Fortran. As an indication, Python can be 100 slower in heavy numerical computation than Fortran. Although writing the Fortran code and compiling it may take longer than with Python, this will be compensated by its fast calculations if your operations are long or complex enough.
Another unexplored (at least for me) option is to combine Python and Fortran by calling scripts written in different languages, keeping each language for its most efficient features. If you feel curious about this, internet seems to be full of ideas and examples about this. Just ask Google about “interfacing python fortran”.
Sources: http://scicomp.stackexchange.com/questions/11514/python-vs-fortran http://www.danielcelton.com/2015/07/16/why-physicsts-still-use-fortran/