Should Undergraduates Be Taught Fortran? 794
Mike Croucher writes "Despite the fact that it is over 40 years old, Fortran is still taught at many Universities to students of Physics, Chemistry, Engineering and more as their first ever formal introduction to programming. According to this article that shouldn't be happening anymore, since there are much better alternatives, such as Python, that would serve a physical science undergraduate much better. There may come a time in some researchers' lives where they need Fortran, but this time isn't in 'programming for chemists 101.' What do people in the Slashdot community think?"
How about Cobol? (Score:3, Informative)
Some of those older languages have a surprising amount of life left in them, out in the real world.
libraries. gigabytes of libraries (Score:5, Informative)
i spoke to someone studying engineering in 1990 who was being taught fortran. they were using a mathematical library that would solve partial differential equations, by presenting the user with the actual mathematical formulae to them.
these kinds of libraries are staggeringly complex to write, and they have been empirically proven over decades of use to actually work.
to start again from scratch with such libraries would require man-centuries or possibly man-millenia of development effort to reproduce and debug, regardless of the programming language.
so it doesn't matter what people in the slashdot community think: for engineers to use anything but these tried-and-tested engineering libraries, that happen to be written in fortran, would just be genuinely stupid of them.
I still use Fortran for sciantific calculations (Score:5, Informative)
If all you need is to crunch numbers, Fortran is a good choice even today.
It might not be the best language to introduce someone to computer science, but it is very powerful for anything that has to do with matrix operations.
A few years ago in a physics graduate course we had a simulation project which left the choice of language to the student.
We compared performance between implementations in C C++ and Fortran.
Fortran was consistently faster by a big margin.
It's also very easy to learn.
That said, I do most of my coding in C.
Re:How would you learn? (Score:5, Informative)
How new does the book need to be for the language standard when it hasn't changed much in 2 decades? It's a simple, easy to use tool for serious engineering.
Python is not programming. (Score:2, Informative)
Python is scripting. FORTRAN is programming. MPI is vastly more supported by FORTRAN than any other language - grow MPI support for C++ or Object C, and then FORTRAN can go away.
Re:Not so easy (Score:2, Informative)
They ditched those line length limitations, special columns etc. twenty years ago. I suppose that is the burden of being the oldest computer language in use today: lots of people evaluate it on the basis of what the language was way back when they learned it.
Re:While there may be "newer" languages (Score:5, Informative)
Re:Agreed, but engineers still use Fortran (Score:4, Informative)
Re:While there may be "newer" languages (Score:5, Informative)
Fortran is still one of the best, fastest, most optimized tools for number crunching.
Agreed.
It's also very easy to write simple programs in it.
This is a strength of Python too.
No way I'd use Python for serious large data set numerical calculations.
It's not either/or, with F2Py you can put your inner loops in Fortran, and deal with the higher level abstractions with Python. So you get fast number crunching and all the 'batteries included' too.
Re:While there may be "newer" languages (Score:5, Informative)
0) A lot of legacy code people still have to work with is written in FORTRAN. Sad but true.
1) Many very optimized libraries available. Check if your language du jour has an implementation of a routine for solving a linear system using BLAS [wikipedia.org]. That provides a huge improvement.
2) Many libraries are in fact only available for FORTRAN. For calculating the eigenvalues of a sparse matrix, there is only ARPACK (for Fortran), Arpack++ (a kludgy C++ interface to the very same FORTRAN library), and Matlab's "eigs" (a Visual Basic-style interface to the very same FORTRAN library).
3) Very expressive. For instance, you can reverse the entries of a vector of complex numbers in a single compiler instruction. This is a toy example, but for more complicate stuff this expressiveness pays: the compiler has an easier job in understanding what code can be safely optimized and what cannot. More complicate stuff involving e.g. C++ method calls suffers in terms of pointer aliasing problems and similar stuff. Of course you may write the very same thing in C or machine code, but for 99% of the computations you would use the "standard" interface to vectors/arrays of your languages and forget about this sort of micro-optimizations. A good commercial FORTRAN compiler (forget about gfortran, sorry GNU but sadly it's true) does this automatically.
4) FORTRAN 95 is not a punch-card language anymore, it has most of the fancy modern stuff if you wish to use it. While "bad programmers can write FORTRAN in every language", good programmers can write well-factored and perfectly readable FORTRAN code.
Nevertheless, I do matrix computations, and still I try to avoid it as much as I can. Most people in our field use MATLAB (which is essentially a Visual Basic-style interface to most of the awesome number-crunching FORTRAN libraries) even though for tight "for" loops its performance sucks. If performance is mission-critical, you may write FORTRAN subroutines and call them from MATLAB, and that's very convenient. Python still lacks many of Matlab's features, its only advantage is being Free Software.
BTW, a very ill-advised design choice of Python: http://www.python.org/dev/peps/pep-0211/ [python.org] Ask any numerical analyst to know why it is a terrible idea to solve a linear system with inv(A)*b. But make sure you have at least half an hour free.
Re:Not punched cards (Score:2, Informative)
Re:libraries. gigabytes of libraries (Score:3, Informative)
Freefem++ (GPL code) however is C++ and solves PDE's by writing the weak formulation. I never saw fortran recently.
Even the famous VODE fortran code to solve ODE's has been rewritten to C++. It's now called sundials (BSD code), and guess what, there is a python implementation, pysundials.
From an engineer's viewpoint (Score:4, Informative)
Re:libraries. gigabytes of libraries (Score:3, Informative)
Except I'm pretty sure that there are modern languages and libraries that can handle this without Fortran. I don't have much experience with it myself, but I'm pretty sure that's exactly what MATLAB [mathworks.com] is for, for one.
Dude, what do you think the libraries Matlab uses are written in? Check out netlib to get an idea, ATLAS, BLAS, LAPACK, LINPACK, etc. Matlab stands on the shoulders of the giants of scientific computing (implemented for the most part in Fortran).
Re:Python is hard too (Score:4, Informative)
The point everyone misses with Python is that Python was designed to play very nicely with external libraries. Python isn't as fast as C at some things, and isn't as fast as Fortran at some things, but is much easier to develop in than either, and can incorporate libraries in both of those languages.
You can eat your cake and have it to.
Re:Agreed, but engineers still use Fortran (Score:4, Informative)
Matlab stops being a 'slow' language once you learn how to use it.
Matlab stands for MATtrix LABoratory. It loves to do matrix algebra more than any other kind. The worst offenders I see are people that try to use for loops for everything.
for i=1:10
y(i)=sin(i);
end
is much slower than:
y=sin(1:10).
And it just scales up from there. There were only a very few times I've ever had to use for loops and that's because of memory issues (on Win32).
Unless your current state depends on the previous one, there is no reason to use a for loop.
-
I never learned FORTRAN, but I make my living on Matlab. Matlab is good for quick turn around. If I need to make a script NOW that does X for me, I can turn it around in a few minutes. No compiling, etc. If I really want speed, I can write MEX (compiled) code.
Re:Oh come on. (Score:2, Informative)
Real men know that the name of the programming language 'Ada' is not an acronym.
Re:Oh come on. (Score:3, Informative)
Why are other programming languages so hard? And is the difficulty justified by the additional power?
Well, that all depends on what you mean by "power". In one sense, all Turing-complete languages are equally powerful, since the set of solvable problems for all is the same.
In the sense of being "easy to use" or "easy to learn", however, I would say that it is necessary for some languages to be "hard", in the sense of having fewer layers of abstraction between the programmer and the hardware-level instruction set. These languages allow those that need finer grained control to have it. In more concrete terms, I'm glad Assembler exists (for the sake of those making device drivers), even if I'll never personally use it.
Is it *necessary* that a language (cough, cough, C++) be an ergonomic disaster to be powerful?
Again, it all depends on how you define "ergonomic disaster". There are those who feel that C++ is a useful addition to C that makes object orientation easier while still not obscuring the central structure of C. C++ is no more powerful (in absolute terms) than any other Turing complete language - it just makes some problems easy while making others hard.
Trying to say that one programming language is more "powerful" than another is like trying to say that a hammer is "more powerful" than a screwdriver.
Re:While there may be "newer" languages (Score:5, Informative)
To make a long story short; solving Ax=b by calculating x=inv(A)*b is a terrible idea because calculating inv(A) is an inherently difficult thing. While it would be extremely useful to have inv(A), it's not strictly neccessary to obtain in in order to solve Ax=b.
At the most basic level, the technique which most would be aware of to solve Ax=b is basic Gauss Elimination, with an augmented matrix and back substitution. In fact, this is often the very first thing people learn how to do in a linear algebra course. It isn't much better than finding the inverse, but it saves a lot of computation in the long run.
Of course there are many other techniques. Happily however, most packages can now automatically make the best choice on which technique to use, depending on the properties of A. In Matlab and Octave, it all boils down to using the left division operator like so
x=A\b
instead of the inverse calculating
x=inv(A)*b
Using the first command, Matlab and Octave will choose a technique that best suits the matrix A. This page [mathworks.com] has a list of all the techniques that Matlab can use to solve the linear system. To my knowledge, Octave has a number of techniques as well, but I'm not sure if it's as comprehensive as Matlab. Also, Octave's left division operator has been known to have bugs.
And to return to the main topic, Octave and Matlab both use LAPACK [netlib.org] extensively, which is written completely in Fortran(and based on BLAS). There's really no other language for linear algebra.
Re:Python? (Score:4, Informative)
Not all scientific programming is heavy duty number crunching -- I'd suggest that only a minority is. My postgrad research proposal (involving Monte-Carlo simulation) said that I'd use Python for the framework and would swictch to C/C++ where Python got too slow. Python never did get too slow, and I never needed a single line of a C-derivative language. I also used Python for some continuation of Robert Axelrod's classic work on game theory (is that science, math, or psychology?).
Anyway, you're making the classic assumption that undergrads are taught the language for the sake of the language; that it will be the language they will use in the real world. Rather (even in the sciences, not just in computing) it's programming that's being taught, and the language is simply a means to an end. It's futile to try to double-guess what they will be using when they get out into the real world; even if you look at what's in demand now, no language has a monopoly and the language-of-the-moment will change anyway during their career. The person who can program Python will pick up any other procedural language quickly enough, because Python has pretty much all of the relevant constructs, and Python has the advantage of being easy to learn. FORTRAN certainly isn't easy to learn (I did my undergraduate project in FORTRAN), and even the newer versions of FORTRAN that have things like Object Orientation don't present the constructs as clearly as modern languages such as Python. I agree that Python is unlikely to be the only language they'll ever need (don't try saying that on the Python mailing list, though!) but it's at least a contender for the best first language.
Re:Sillyness (Score:5, Informative)
I'll add a "+2" to this. My background is in Astrophysics, and the coding there is largely done in Fortran. The friends and people I know spread between 4-5 different universities all program in Fortran. I'm moving into Geophysics/Atmospheric/Oceanic sciences, and all that work is done in Fortran. From fluid dynamics to stress fault calculations, Fortran is the de facto language.
To be clear, we're not talking about programming here. We're talking about math. Pure, hardcore, overwhelming math. The crunching of terabytes of data. Matrices with millions upon millions of cells, being combined with more of the same.
If we were talking about pure programming, Fortran is a terrible language. What we're talking about here is automating massively complex mathematical calculations on enormous amounts of data.
Re:Oh come on. (Score:3, Informative)
What makes C++ difficult is C. That is
1) Deallocation of memory, bounds checking in arrays... is done manually
2) Lots of direct pointer manipulation. You can't abstract away the "how the computer is going to do this"
3) Multiple inheritance
Getting rid of those things gives you Java which is much easier to learn but doesn't have the performance. The question is why did you choose C++ in the first place if you don't want the excellent performance?
Re:Python? (Score:3, Informative)
Say what? I've never seen anyone do any sort of scientific research programming with Python
My research lab (satellite data processing) is all python and the psychology department in my school is thinking of switching over to python. There are tons of great scientific computing libraries either written or wrapped in python. It's a great language for social science research because it's so simple and clean, and the libraries make it easily extensible to the hard science crowd. I'm working with pretty big data sets at the moment and don't find python that slow in comparison, plus it simplifies so much of the data organization/sorting/filtering tasks.
Re:Python? (Score:2, Informative)
I guess it depends on the type of scientific computing you are doing. If you need a cluster to crunch numbers, don't use python. However, there are huge areas in scientific computing where: 1) speed isn't the primary concern or 2) languages like python are fast enough. Also, python has some pretty significant scientific computing tools like scipy (see http://www.scipy.org/ [scipy.org]), visualization using matplotlib (see http://matplotlib.sourceforge.net/ [sourceforge.net] ), etc. I personally know a lot of people doing scientific computing and general research who use python.
If speed was the only concern, people wouldn't be using tools like Matlab, IDL, python, and the like. Obviously, a significant number of people doing scientific computing find these tools fast enough.
LHC languages. (Score:3, Informative)
My friend at cern working on programs for the LHC has to do everything in c++ or python. So python might be a good one to learn. I love fortran 90/95 its a good language that only has a hint of the unpleasantness that was fortran 66. As, I'm sure others have posted there are some very high performance libraries/compilers for fortran number crunching. But, its not that hard to pick up if you know c/python.
But it was pretty funny taking that FORTRAN class with some cs students who only knew ADA. They were sort of freaked out by its "modern" features and "easy" string handling. It was right then and there that I realized I had dodged a major bullet by not becoming a cs major at the school.
Re:It's okay to teach them FORTRAN (Score:3, Informative)
WD40 is a drying agent, not a lubricant.
Uh... isn't it both? The manufacturers of WD40 [wd40.com] certainly seem to think so:
WD-40 protects metal from rust and corrosion, penetrates stuck parts, displaces moisture, and lubricates just about anything
Re:While there may be "newer" languages (Score:3, Informative)
Python includes a great deal of MatLab functionality if you go look for it, and has lots of other advantages over MatLab. It's a modern, general purpose, object oriented language that scales well. You can write multi-thousand line apps in Python that are elegant and easy to maintain and understand. MatLab is designed to write very short programs in, but people are always trying to write big, full fledged apps anyway.
Plus Python is free and MatLab costs thousands.
Re:Python? (Score:5, Informative)
I think you are mistaken regarding what most undergraduate science students actually do (they are not maintaining/upgrading old fortran libraries). Most of the high performance capability that undergrads need involves matrix computations, FFTs, convolution, etc., all of which are included in the python numpy/Numeric module (which is a wrapper around fortran libraries, so they're just as efficient). And since they'll likely spend as much time analyzing data as producing it, python + numpy + matplotlib is a perfectly suitable solution.
I'm not suggesting that fortran isn't of value to some scientists in some situations but many science students will never have to touch fortran code unless they're forced to take a class that teaches it. As you said: "They're being taught to program as a mere tool for the important stuff being taught." Which is why it makes sense that their intro language is one that is easy to learn, supports multiple programming paradigms, has efficient numerical libraries, has easy-to-use visualization tools, an interactive interpreter, and can be used as a general purpose programming language. And while I personally prefer python for a high level language, there are others that could serve the same purpose.