5
$\begingroup$

As you may know, Fortran is widely and longly (?) used in science. I've heard a lot of people saying that we natural scientists should all migrate to C++ or Java. I've seen people increasingly suggesting also Python, that I thought it was basically a script language like Bash, but which supports floating-point number operations (I have only used Python with that purpose).

However, other people I know have been saying that, since Fortran 2003, all the old advantages of languages such as C++ and Java are irrelevant, and that Fortran still has the advantage of being fast, robust and having a lot of code already written for all types of scientific calculations.

Another motivation I have to abandon Fortran is that, when I said I used Fortran to some non natural scientists that work with computer, they laughed and asked "Fortran yet?", but, beside that fact, are there still good reasons to abandon Fortran in science after Fortran 2003? What do C++ and Java have that Fortran don't?

$\endgroup$
  • 4
    $\begingroup$ "Python, that I thought it was basically a script language like Bash" Python is not at all similar to bash, and if you use it like that you'd be missing much of the point of using python, especially all its and its libraries' support for scientific computing. Have you tried looking at one of the major computational science projects that use python, and how they use it? How would you compare it with, e.g., matlab? Is there a reason you say this? Perhaps it would be better if your question described your programming goals more clearly. $\endgroup$ – Kirill Dec 22 '15 at 23:43
  • 5
    $\begingroup$ Despite the fact that this question is likely to attract many views and answers (many of us like to talk/argue about programming languages), I don't think it's a very good question for this site as currently posed. It seems you're basically asking for a list of features that Fortran 2003 doesn't have, but exist in other languages. This could be answerer by just comparing lists of the features of those languages. If you're asking "Should I switch?": well...it depends. $\endgroup$ – Doug Lipinski Dec 23 '15 at 0:46
  • 1
    $\begingroup$ "they laughed and asked Fortran yet?" : this statement should not influence your decisions. It's not because something is new that it's better! The OO paradigm is also very old and is "outdated" wrt the functional paradigm. Take the paradigm and the language that fits your problem. Fortran is good for doing linear algebra, bash is good for scripting, Python is good for fast development, OCaml is great for writing programs with very litte bugs, etc. It's not more complicated than that. $\endgroup$ – Anthony Scemama Dec 23 '15 at 9:53
  • 3
    $\begingroup$ No, you don't have to increment indentation every time you open a file in Python. You have to increment indentation every time you nest a conditional or loop operation inside the same function. Multiple nested loops/conditionals without refactoring into functions are considered bad coding style in every language, so you are probably already avoiding them. (And no, probably you shouldn't use Perl instead, at least for scientific computing.) $\endgroup$ – Federico Poloni Dec 23 '15 at 14:25
  • 1
    $\begingroup$ I never understood this whole "Java for scientific computing" trend. Beside the fact that I have never seen serious code in my area (mostly FEM), what exactly is the point? The language by itself improves on nothing that for instance C++ can already do and portability is also a non-issue for scientific libraries as long as you stick with what your standard library offers. Also you don't have as much rock-solid scientific code to build upon. I occasionally hear about 'adaptive runtime optimization' as an argument why Java does not suck so bad at HPC, but I still have to see it to believe it ;-) $\endgroup$ – Christian Waluga Dec 23 '15 at 19:36
4
$\begingroup$

One thing that C++ includes that Fortran doesn't have is extensive support for generic programming and compile-time code evaluation. Modern Fortran allows one to use object-oriented features like C++ (to a degree).

I would argue that these generic programming features, along with C++'s object-oriented model and standard library, allow for the construction of very neat abstract data-structures, algorithms and programming patterns, without any run-time overhead.

As such, if you find yourself using a lot of computer-science within your scientific programming (i.e binary search trees, hash tables, priority queues, etc, etc) then C++ might be a good choice. The more unstructured types of scientific computing (those based on unstructured meshes, graphs, networks, sparse matrices, etc, etc) often fall into this type of category. These CS-type language features are a bit of a double-edged sword though -- while some people love them, others hate them with a passion, and much prefer a language like Fortran.

While I personally prefer C++ for most projects, I think that Fortran is a fine language, and the fact that it's old is no reason to think about abandoning it. If you work predominantly with arrays and structured problems it's unlikely that there's a better language choice. At least there's very little incentive to change to a language like C++!

$\endgroup$
  • 1
    $\begingroup$ Good points that I forgot to consider about C++ for the comparison. I was thinking more about the computational performance with my response, but some of these features in C++ definitely help with reducing man hours. $\endgroup$ – spektr Dec 23 '15 at 2:38
  • $\begingroup$ @DarrenEngwirda "At least there's very little incentive to change to a language like C++!" An incentive I had to change to C++ was the OpenGL library that allowed me to draw good 2D and 3D output with the simulation data. Actually, I have a program written in Fortran that opens a file, writes a C++/OpenGL code in it and then compiles and executes it to generate periodic graphic output. I did so because I had the non graphic part already written and Fortran, so I ended up with a Fortran/C++/OpenGL frankenstein. $\endgroup$ – Leonardo Castro Dec 23 '15 at 21:05
  • $\begingroup$ @LeonardoCastro I don't have experience with OpenGL but for animation, I simply write some routines to export my simulation data in vtk format, and use Paraview to do the rest. $\endgroup$ – chuyenvien94 Feb 16 '18 at 16:37
2
$\begingroup$

I think this really comes down to what work you are doing with the language. If you are doing numerically computation heavy things, Fortran is a fine language for this and I don't know if C++ or Java would really be advantageous relative to Fortran 2003.

If you start diving into applications outside of purely number crunching, like building GUIs, apps, games, back-ends for websites, etc., I think C++ and Java would probably be much better for the job. Part of this is because of all the frameworks and libraries built in those languages to tackle those problems. Now obviously, you could do some number crunching code in Fortran and then build say GUI code in Python/C++/Java and just write a wrapper for the Fortran code to use it and then you could get the best of both worlds. But it just comes down to what's best for the task and constraints at hand.

Anyway, that's my 2 cents.

$\endgroup$
1
$\begingroup$

To expand on Darrens answer a little bit:

First of all, Java holds no advantage over Fortran 2003 for Scientific Programming. The syntax is more verbose (x.add(y) instead of x+y) and the performance is significantly worse. Some of the other JVM languages like Clojure or Scala will at least give you a reasonable syntax to work with.

When compared with C++, performance will be about same for numerical workloads. Indeed most Fortran compilers are part of a toolchain also supporting C++, and many (most?) of the optimizations will be the same. Like Darren said, C++ supports generic programming, which is implemented in a zero-overhead fashion, meaning you can do advanced abstractions without paying any extra cost. For instance, matrix libraries like Armadillo or Eigen give you a Matlab like syntax, without any performance penalty.

The main advantage of Fortran is for working with arrays. For pretty much anything else, C++ will be easier, more maintainable and faster.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.