tags:

views:

931

answers:

8

Is there any good reason to develop a new software project with Fortran anymore?

+8  A: 

Scientific computing is often written in Fortran for a few reasons:

  • Scientists don't know other languages,
  • You can get better performance in Fortran than C for scientific code (lots of massive arrays), because of aliasing restrictions in Fortran, which allow the compiler to optimize better. This can make a 30% difference in speed,
  • There are a lot of scientific libraries in Fortran.

So, I would say the only good reason would be you're working with scientists (like computational chemists or physicists, say) who have a lot of entrenched fortran, dont want to learn new stuff, and the speed is super important.

Otherwise, there are probably better ways to achieve the same results (C++ libraries or Python libraries, say).

Paul Biggar
Many of your points are good, but I want to say that - even though I'm a big Python fan - I doubt that you will get the performance from Python that you get from FORTRAN for many of the applications FORTRAN is used for. Where I work there are people who routinely send their stuff off to the supercomputing centers, and they're almost always using FORTRAN, and I've never heard of any of them using Python. I've not worked with C++, so won't address that.
PTBNL
@PTBNL: My impression is that Python and C++ can be used to glue together libraries which perform the really hard work. I'm not advocating doing computation in Python.
Paul Biggar
Fortran is very easily connectable with py, and one of the newer standards also standardized a way of interfacing with C/++
ldigas
+28  A: 

Yes:

  • if you need to deal with vectors and matrixes a lot
  • if you do lots of heavy numerical work
  • if you want to make use of some of the most optimised numerical libraries in the world
  • if you are into supercomputing

But there is of course no need to limit yourself to one language. One project I worked on, for example, used C++ and a GUI library to draw models of oil-field pipe networks, and then used Fortran to optimise the flow of gas and liquids through the pipes.

anon
As Neil doesn't quite say but implies:If you need to do parallel computing (not distributed, not concurrent, but parallel) then Fortran is a good choice since both shared memory and distributed memory parallelisation is well supported for Fortran.
High Performance Mark
Just to add to Mark's comment: Drafts of fortran standards are available on the net for free download, and anyone wishing to see how parallel processing is implemened can easily do so.
ldigas
+4  A: 

...At a conference on computational physics in South Korea (CCP2006), most of the plenary speakers who talked about codes used Fortran. Perhaps scientists prefer Fortran because they're productive when using it.

from here

Ilya Kochetov
+4  A: 

There are many good reasons for using Fortran. How often do you hear of someone hacking a fortran app? It's not like the language is broken. Sure there are some nice features that wouldn't be readily available but you can still make it work.

Just think of it as retro programming or vintage development.

Badfish
Security through obscurity is a bad idea.
Wahnfrieden
last time I checked the code still worked and is being used. Just because you don't use it does not mean it's obscure (see markj's answer)
Badfish
@Wahnfrieden - I wouldn't say "obscurity" is the term that fits - fortran programs 50 years old still compile without change, and you don't see any "fortran obfuscation contents" out there, do you ? Sadly almost all other languages offer them.
ldigas
+6  A: 

Scientific numerical software is often still written in Fortran, for the reasons given in other answers. I'd just add that in 2008 I heard an Intel employee say that their high-performance Fortran compiler outsells their equivalent C compiler. The Fortran compiler sales were also growing faster.

MarkJ
+6  A: 

No (with clauses):

Fortran is a language with a very low expressivity (see footnote), unexistent libraries for common non-numeric tasks, an awful handling of strings, no exception handling, a dangerous system of variable declaration (unless overridden), no decent IDE, an obnoxious standardization, no decent and fully compliant free compiler (g95/gfortran do not support the full language specs, and I heard they have troubles), incredibly limited namespacing capabilities, among many others.

It makes absolutely no sense today to start developing a large project in Fortran, It would be like ploughing a vast terrain with a hand plough. Doable, but a waste of time. Many laboratories directed by the new generation of professors are ditching Fortran and moving either to C++ or to python. Young computer-savy students don't want to touch Fortran code with a 3 foot pole, because they know that better alternatives exist, so only the unsavy will accept it, and generally produce low quality code as a consequence of their low interest in programming as such. You are therefore screening out people interested in programming. Moreover, if the code for whatever reason happen to go commercial (for example, a spin-off), then you will have to rewrite it: hiring will be a nightmare otherwise.

You should use a highly expressive language as much as you can, reducing lines of code and bugs, improving development speed, code clarity and testability. Then, profile your code, and optimize the really time-critical parts in Fortran. On this, I am all for it (but consider C first).

More on the point http://forthescience.org/blog/2009/02/22/why-is-most-science-programming-done-in-fortran/

Footnote: See this page on the pedia

Language    Statements ratio[25]      Lines ratio[26]
C           1                         1
C++         2.5                       1
Fortran     2.5                       0.8
Java        2.5                       1.5
Perl        6                         6
Smalltalk   6                         6.25
Python      6                         6.5

According to the pedia, the data come from Code Complete. You are also welcome to play with this page for a comparison of different languages for a set of benchmark codes. Comparing a language with itself brings the absolute values.

Stefano Borini
Ome of wikipedias less accurate tables, one feels.
anon
probably, but I wouldn't challenge the expressivity of fortran against the python's one no matter how inaccurate is this table.
Stefano Borini
Compouter-savy ? Or computer sciences ones ? There is a difference.
ldigas
As far as your comments goes, it is not only not a language with low expressivility, but also a language with high readability, has decent string handling (when will people start seeing that fortran77 is not the latest ?), several compilers use IDE of VS, some have their own, it has one of the clearest standards and clearly defined what is part of the standard and what not. ... I won't even bother with the rest.
ldigas
I wouldn't define a language that does not allow you to allocate a string of arbitrary length as decent. And let's not go into the detail of passing the string to C: two parameters, one parameter?
Stefano Borini
I could make the same analogy about some fortran features and half of the mainstream languages today. C was made for string processing, fortran for number crunching. Which it does well. As far as string processing goes, I've yet to find a task which I cannot do in fortran but can in C/python/your language of choice.
ldigas
As far as the table goes, it is 'not little' biased. I could easily produce several snippets showing otherwise.
ldigas
@Idigas: regexps ? XML parsing ? FoX?... at last! I had to write my own wrapper library to parse XML (look for F90xml).
Stefano Borini
@Idigas, @Neil: about the table, added more info to the answer.
Stefano Borini
@Stefano - That, what you are saying now, is one of the "standard arguments" against fortran. "It can't do this and it can't do that. It sucks." No, it can't (or maybe it can but with significant difficulties - I never tried.) be used for regex (I don't know what the "ps" at the end is), XML parsing or FoX (???). It also can't, to add to your arguments, interface with hardware at a low level. And I personally find that a good thing. For it is a language that was designed for numerical processing. Which it does very well. It was not designed to be a general-purpose language.
ldigas
Neither was C for that matter (to which we're now comparing it), but just like in real life, there are more people who know the alphabet then people who know how to read mathematical expressions.
ldigas
Also, I do not understand what you mean by "Comparing a language with itself brings the absolute values." - explain, please. May be just my misunderstanding of the phrase, but still.
ldigas
http://uszla.me.uk/space/software/FoX/
Stefano Borini
If you visit the page you will understand it.
Stefano Borini
Ok, Fortran is not a general purpose language. It works only to do calculations. Then what I said stands: use it to do raw number crunching, and let another language take care of everything else.
Stefano Borini
@Stefano - I haven't quite said that. Please, do not take my words out of their existing context, and use them in a completely different one. Journalists do that. Judging from your previous posts, I consider you to be smarter than that.
ldigas
As far as FoX goes - looks like an interesting project. Will definitely look at in in more detail. I'm still however a little puzzled about this whole new XML thing - for I can't see how it's better *that much* than just plain old text files.
ldigas
New ? it's 15 years in the wild... plain old text files work well if you have simple, unstructured data and you don't have further manipulation. More complex stuff require more complex formats. I daily use CSV, much easier to handle with the python csv module. XML is good if you work with grid computing and the like. The alternative is to convert XML into namelists or whatever, and then parse your text output to create a XML output. To do this, either you use a general language (e.g. python) or you pretend to use Fortran so you need FoX,regexps and company. And a debugger for the segfaults.
Stefano Borini
Or to be more precise, it appeared 15 years ago, but until 5 it was practically unknown. For someone who enjoys rewriting his whole work every 5 years, 15 years is old. For me, however, text files have worked for every application I've put them through. I've even been known to read .csv every now and then, but had no problems parsing them in fortran (much easier than some of my own, for that matter). XML - I'll wait some 5 years to see if it'll still here, and then think about reorgani
ldigas
zing the whole package. Segfaults - not so common in fortran. I can't remember when was the last time I used to produce one.
ldigas
+8  A: 

This question is so old.

There are many reasons for using Fortran, many of them have already been stated so I won't repeat those.

A small digression, if I may - although unrelated to your question by title, the post at the link may also clear away some doubts.

But, allow me to add just one more reason, which as far as one can see, nobody thought to mention still. That is, and this of course depends on the type and projected life length of your project, is that fortran today has extremelly good backing. Technical and financial wise - I would dare to say even, that maybe only a handful of languages have available the number of compilers Fortran has (we're talking still actively developed ones here), and with the names like Intel, Lahey, and NAG it is not going anywhere in the not so near future. With its principle of strong backward compatibility it is a language that fits very good for long term projects.

This being a forum oriented mostly at professional programmers, not engineers and alike, one of course can expect what is usually the common answer to this kind of question - but remember, they said in the 80ties that "Fortran was dead", they repeated it in the 90ties, and they're still (I see) saying it today.

Check out the first link, it may clear away some doubts on the Fortran-python-matlab trilemma :); if you still feel uncertain, refine your question a little.

ldigas
good point - I was going to mention "portability" as one of the advantages in my answer
anon
They also said that Cobol is dead, but it's not, and still I would not start a project in Cobol today. Would you ?
Stefano Borini
@Stefano: Personally, I don't much like COBOL, and don't want to work with it. However, if by some strange twist of fate I've got a project where COBOL would be appropriate and a staff that's well-versed in it, I don't see why not.
PTBNL
@PTBNL: then you have to consider a couple of things: 1) how good is for your career ? Cobol is used by banks, Fortran is used by academia. The chance of having a permanent position in the academia are close to zero, so any experience in Fortran is totally wasted time when you have to recycle in any other employment involving programming.
Stefano Borini
2) Fortran well-versed staff is becoming more and more difficult to find. Physicists, chemists, bioinformaticians, either they are for the crude science, so they don't want to code unless forced to (with all the consequences) or they like to code, but then they go for other languagees because they like programming, and programming in Fortran is not what someone enjoying programming wants to do. Finding someone willing to put his nose into Fortran programming is becoming more and more difficult.
Stefano Borini
@Stefano - "fortran is used by academia" ? You mean "and ..." or "only by". Because, if you mean the latter, then I will just assume you're trolling, and stop wasting my time explaining. If you mean the first, then I will assume you're ill informed. As far as second comment goes, on my university it is taught on mec.eng. and nav.arch. college, arch. college, geo. college, and natural sciences.
ldigas
@Idigas: I am not trolling. I am expressing my experience and my experience is different from yours. I am reporting what I see and hear from many colleagues and research groups. If your experience is different, so be it, but considering me ill informed just because my hands-on experience saw different things than you did is totally subjective. I could claim exactly the same.
Stefano Borini
@Stefano: If Idigas has spoken to people who actually use Fortran in industry, his evidence is objective. You will find that if Unis teach Fortran, it is BECAUSE industry demands it. Depts that teach stuff that nobody wants/needs to learn any more lose enrolment numbers.
Stephen C
@Stephen: I still have to find an industry requiring Fortran in the job announcement. Give me examples and I'd love to add them to my knowledge. By the way, here at ETH they teach C++.
Stefano Borini
@Stephen C - Yes :) I have spoken with people who use it in industry, but that is beside the point now. For just after reading that last comment I think I finally understood was @Stefano was trying to say.Let me start with an example; I'm not a programmer, but a nav. arch. by profession. In my job description fortran was not mentioned, and (although I can't be certain) I don't think I mentioned it in my c.v. either. But my employer was still pleasantly suprised when he learned about it. What I am trying to say ? For computer science students
ldigas
programming languages is all; to them code produced is the purpose of their efforts. On the other hand, to pretty much all other engineering orientations it is just a step in the way. You see, I don't sell my code, I often don't even show it to anyone, even the results that come out of it are nothing final. Maybe the ones that come from those. My employer doesn't care what I use to get those results - he just cares that I get them. And after spending 6 years (btw, longer than cs in here) learning the ins and outs of their profession most of my coleagues don't wan't to spend another, learning
ldigas
the computer sciences to be able to do their job. And that was one of the main considerations when fortran was being designed - it was not designed for cs, but for engineers who wanted a tool to do their work. Which enables them to live. "Beautiful code" <- give me a break - what can you do with that ? A nice house to live in <- that could be useful ... |||| This being said, I'm not saying there aren't professional fortran programmers that live of that. I know a few even. It's just that they are in the minority. ||| @Stefano - ETH ? (I haven't been able to google it.)
ldigas
I'm not saying it is an ideal prog. language, as far as programming languages go. No. Nothing is ideal. It is just better than the available alternatives for its purpose and its users. I'm familiar with several other languages and use them daily. Python, for instance - nice, but who can guarantee me what will happen to it if van Rossum gets hit by a bus ? Or will it still be here in 10 years ? Hell, I can't recompile 5 year old python code now, less alone anything older than that. Not to mention that numpy/scipy look nothing like "regular" python. Matlab then ? Nice, no doubt about
ldigas
it. But to depend on one company, and one company alone, when something goes whong ? The only worse thing than that is to let them know it.
ldigas
%s/recompile/interpret/
ldigas
http://en.wikipedia.org/wiki/ETH
Stefano Borini
Python is free software and with a huge community around it. Your claim "who can guarantee me what will happen to it if van Rossum gets hit by a bus" is exactly the same as "who can guarantee me what will happen to Linux if Torvalds gets hit by a bus" or "who can guarantee me what will happen to Apple if Steve Jobs gets hit by cancer". As for being dependent on one company, What about fortran compilers? the free ones have a bunch of issues. Intel? The Math kernel library was free, and then suddenly it was not anymore.
Stefano Borini
In any case, since today is all "publish or perish" I would kindly let my competitors doodle with Fortran while I code in python and publish before them. In 10 years the code and technique will be obsolete in any case.
Stefano Borini
@Stefano - What do Torvalds and Jobs have with this at all ? You didn't understand the analogy. ||| Actually, no. Even the free ones are pretty good, g77 used to have some issues, but gfortran was always good. But you missed the point again - it is not the matter of cost, but the matter of development. ||| Intel is not the only one who develops them (check out the link)
ldigas
@Stefano - 2nd comment - Hardly. That may be your case, but it is not a "luxury" everyone has. Some things are built for a longer lifetime than 5 years (OS switch), you know?
ldigas
A: 

let's write a high level interface to fortran, like fython or fruby :)

joe
I think PYTRAN (especially all caps) gives it that legacy language feel.
Steven