views:

408

answers:

11

I've been working with a lot of FORTRAN 77 lately, and though I had reservations at first, I now see some great qualities of the language. It is:

  • Simple to learn (no object-oriented or functional-programming complications)
  • Easy to read
  • Blazing fast at number-crunching

Those qualities are naturally attractive to non-programmer engineers and scientists who just want a way to make a computer give answers quickly. But it has a lot of limitations based on its age and some of its basic assumptions. I'm skeptical about how easily non-programmers can understand some of the added capabilities of later versions of Fortran, as well.

Is there a modern language that is as straightforward as FORTRAN, just as fast for mathematical applications, and less limited? Or is the answer Fortran 90, 95, 2003 . . . ?

+2  A: 

You may be looking at MATLAB. Many engineer undergraduates learn that so I think it's easy for non-programmers to grok.

If you want to get hardcore, take a look at J.

kizzx2
J is a horrible suggestion. One of his criteria was "easy to read". I can't think of a language that is harder to read.
Turtle
@Turtle: You're right. I said that half-wittingly. I'm also surprised that got upvoted thrice :P
kizzx2
Matlab is indeed a nice choice for undergraduates and many more; it has a lot of nice features, and it's graphical capabilities, are, well, practical to say the least, in a number of situations. But, just like every "pro" has a "con", it suffers from some historical development issues. To me, when I was (still do for some things) using it was organization of larger programs, sometimes bad documentation (incorrect on some issues) and backward incompatibility (combined with the fact that it was a /one company language/ -> fear).
ldigas
Just so this is not misunderstood; I still think of it as excellent for some purposes, such as rapid prototyping in some fields.
ldigas
+1  A: 

If you're really excited about using Fortran, you might consider using Fortran for Microsoft.NET. The idea behind this project is that it allows you to use the Fortran language while taking advantage of a mangaged code environment via the Common Language Runtime (CLR).

Ben McCormack
Mybe mine is a stupid question, but how does CLR help non-programmers scientists?
klez
I'm guessing, but garbage collection would be quite helpful.
Turtle
@klez Well, If you have ever worked in a constrained library you would probably know this. The CLR and Java's runtime have support for thousands of operations that old Fortran compilers couldn't dream of. GUI creation when necessary, easy graphing, arbitrary precision math and real-world data collection capabilities would all greatly benefit a non-programmer tying to develop software to solve a real-world "science" problem.
Bill K
You don't have to be a CLR expert to *consume* the CLR and gain its benefits. F# has gained immense popularity in academic/research communities and it compiles down to the same IL code that runs on the CLR as C# and VB.NET. If the OP likes the benefits of Fortran but wants to be able to run it in a modern environment, Fortran for .NET seems like an excellent choice. Heck, if you wanted, you could write your own "number-crunching" libraries in Fortran and consume them in an easy GUI-based framework such as WinForms or even a console application. This idea is just one option among many.
Ben McCormack
A: 

@S.Lott: Cannot imagine Fortran users such as scientists, having to switch over and dump all their Fortran work..... :S The OP is looking for input on what's new...

To the OP: Have you read up on Wikipedia which details the changes made to Fortran, for 2003 version, allows interoperability with C, so maybe S.Lott does have a point, perhaps, bit by bit, gently port some stuff over or write a wrapper in C to call the Fortran modules? I'll quote from that Wikipedia page...

Interoperability with the C programming language.

tommieb75
Modern Fortran is much better than C. So the advice to port some code to C is bad to say the least.
kemiisto
Yes, I've read about the updates since 1990, and I'm skeptical about some of their suitability for non-programmers --- object orientation? recursion? pointers?
JasonFruit
"Cannot imagine Fortran users such as scientists, having to switch over and dump all their Fortran work". The question is a search for a programming language. So, what point are you making? That changing programming languages is bad? Impossible? Unimaginable by you?
S.Lott
@S.Lott: I'm talking about from a perspective of $$$$ Can the scientists afford to ditch *ALL* of their codebase and go through some intensive courses to learn another language.... not in your words *unimaginable by you* or *impossible*... wise up!
tommieb75
@tommieb75: "I'm talking about from a perspective of $$$$"?? Why? That's not part of this question? Why are you mentioning this?
S.Lott
$$$ are part of any reasonable question. It is one of the few objective criteria which can be applied to most of life's choices.
ldigas
@ldigas: First. That's not part of this question. Second. And far more important. You don't know how much of a Fortran code base they have. Nor do you know anything about the quality of the code base. Rewriting in C could be the best way to improve it. Since we haven't actually seen the code (nor do we even have metrics on the volume of code) these random considerations of cost seem way out of place. Perhaps you should open a new question on "cost of conversion of an unknown and unspecified code base from F77 to C"? Since we have no facts, why is this so important?
S.Lott
@S.Lott: Right, let's put this back on you - what makes you think that the existing code (regardless of lack of posting metrics etc) can be rewritten into C - HOW do you know that? The OP did not give any clear indication - but yes I can see your viewpoint as much as I hope YOU can see my viewpoint also! These needs to be considered firstly before 'diving in and you making that recommendation into rewriting the codebase into C...' Why is everyone so quick to jump in and say 'Rewriting in C could be the best way to improve it' without looking at other angles also!?
tommieb75
@tommieb75: Where in the question did it say "rewrite"?
S.Lott
@S.Lott... let me quote your comment you wrote above addressed to ldigas... **Rewriting in C could be the best way to improve it** ^^^^ so do not twist up my words...
tommieb75
@tommieb75: "having to switch over and dump all their Fortran work" Why did you say that? Rewrite is not in the question. Dump their Fortran work is not in the question. Why say that when it's not in question? I did not "twist up your words". I'm trying to understand why you keep mentioning cost and dumping Fortran. It's not in the question.
S.Lott
@S.Lott: All of this stemmed from your answer which you posted earlier on and was down-voted and ended up on the bottom of this page (I did not down-vote you btw in case you're wondering) as it was not the answer the OP was looking for as I was against that opinion you expressed.
tommieb75
@S.Lott - I see you are wise in the ways of the taking a discussion, while putting practical aspects aside (until it becomes purely theoretical and the only goal is to win the argument). Unfortunatelly, I've given up on that trolling game some decades ago.
ldigas
... and there it goes ... meaningless comments, catching other people's words, instead of understanding their meanings, in hope of winning for no purpose whatsoever. I can't want to see who'll mentionn Nazi's first :-))))
ldigas
@tommieb75: "having to switch over and dump all their Fortran work" Why did you say that? I'm just trying to understand the comment. Please explain the comment. That's all I'm asking. I don't care about downvotes. I'm trying to understand the comment. Please explain why "dump all their Fortran work" is so important when it's not in the question. Please explain.
S.Lott
@S.Lott: This is my last comment to this. Look at it another way, with 94.1K reps and 13347 views expressed, you *should* know! I spelled it out, justified it. You're missing what I've said as all of this was in *response* to your post! What I do find **remarkably odd** is this - you were quick to point out in your post *Sounds like C. Buy Numerical Recipes in C. etc*, but reading your comment underneath addressed to Bill.K **I agree that C is complex. Personally, I avoid it as much as possible** This begs the question why did you post it in the first place? You argued instead - go figure!
tommieb75
@tommieb75: Please explain why "dump all their Fortran work" is so important when it's not in the question. Please explain. I understand you're responding to a comment. I don't understand the response. Please explain it.
S.Lott
A: 

I assume you are considering small, dedicated programs written to solve specific problems. In that case, if the complexity of OO really bothered you I'd just write a C# or Java app and not use OO. Visual Basic should be pretty darn fast these days as well.

Nearly all compiled languages will be mathematically quick these days, all operations are done on the math co-processor--so unless you have found some language to be particularly lacking I wouldn't let any languages "math speed" bother me much.

Bill K
" Nearly all compiled languages will be mathematically quick these days, ... " - hardly. Even simple programs (models) can become very slow very quickly when it comes to commercial applications (where the grids have to be refined in a way not such to show only trends, but to give practical results).
ldigas
Bill K
"Programming language shootout" - which has been discussed numerous times before (just google it, you're bound to stumble onto one of them discus.) is not an objective criteria for speed, since it obviously fits some more than others. Want an opposite example; write a sparce system solver in most of those (or pretty much anything similar).
ldigas
@Idigas Actually, it's a pretty good criteria since it has a variety of different problems it solves and each problem can be tailored to be faster by people who are the best programmers in a given language. If you think your language isn't adequately represented, submit a better test or solution. It is biased that it runs on Linux so it can't represent languages that only reside on a single platform.
Bill K
@Bill K - (btw, my name is Ldigas, but I agree, in this font the error is easily made) - No, no. Quite the opposite. I'll go from the last, if you don't mind. Platforms aside; 'tis not that relevant, so we can skip that for now. As far as "each problem can be tailored to be faster by people who are the best programmers in a given language" - it's simply not correct. Instead of putting it in my own words, I'll link to http://stackoverflow.com/questions/1196814/fortrans-performance/1236830#1236830 who's already put it nicely (particularly first paragraph). Second, to submit my own problm;
ldigas
why would I want to do that? Like the above said, I've nor the motivation, nor the time, nor the will. But a good counter example of "variety of different problems" as you say, is a fact, that I cannot recognize not one problem which would befit traditional engineering disciplines, in two or three fields (depending how you look at it), which I'm to some moderate extend familiar of.
ldigas
@ldigas That answer had no example of performance--just more theories. It's just not possible that Fortran (or any other language) is SIGNIFICANTLY faster (say within 3x) to EXECUTE than C, C++ or Java and is likely a bit slower but still darn fast--but they all run at very close to machine speed. Some languages may be easier to code and some are easer to code efficiently. Fortran may have libraries that already do some things very efficiently whereas on other languages those libraries don't exist and people create sloppy replacements, but that has nothing to do with the language itself.
Bill K
@Bill K - Uhm, yes/no ... you're losing me here now. On what comment is this a reply? No, the answer has no example of performance - it just gives an opinion very similar to mine on those benchmarks (see also my upper comment). I linked to it as not to repeat the same thing here. Why the "yelling" ?
ldigas
@Idigas Sorry about the emphasis, I forgot caps tend to mean yelling--just couldn't figure out how to do italics in comments. I wonder if many math fortran libraries are hand-coded in assembly or something, otherwise there is just no way it's as fast as C and is going to be much difficult to code large solutions in than any modern language as far as having a usable IDE, decent error handling, coding-time error correction and all the other things that make programming scalable these days.
Bill K
@Bill K (from LDIGAS <- please :) - No, from my understanding they are not in most cases hand coded in assembly. Exceptionally some small parts. But, let me try to put it from another perspective - from the beginning. Assume equal speed of C and Fort. (just so we put a stop to that part of this discussion, which is leading us nowhere. I'm sure you'll agree.). I'm sure you'll also agree that for many types of libraries which deal with stuff fortran is used for, effort/cost for implementing a function (not a programming function, but as a feature function) is greatly on the side of fortran - it
ldigas
is purely simpler and much more quicker to write it. Combine that with rather rigorous optimizations from the compiler side, which are very strong in that respect (speed was always more important in fortran then C, simply by nature, since in fortran that was the only measure in a lot of cases) and maybe some low level optimizations, and you'll quickly come to the conclusion that for many purposes, it is, even for things which require performance, unplausible financially to try to write it in for example, C. This is an argument which still stands today. Hopefully, that answers the first part of
ldigas
your question. As far as the second part goes, no, it is not overly difficult to code large projects in fortran (functions, subroutines, modules, private/public, interfaces ... >=F90 versions have extremelly nice organization features), although I agree, it is missing a little on the side in regards to tools which support it (IDE's for example). You mentioned error handling - many errors which you commonly encounter in C are however very hard (sometimes
ldigas
impossible) to produce in Fortran programs (segfaults for example). It's rules/design regarding pointers, aliasing, passing array infomation, restrict quite a few of those errors, to a point where they become quite rare in practice. One can of course, always produce an exception, but those are, as their name says, exceptions.
ldigas
*italic with stars* <-- yup, just checked it myself. For italics use stars (as in multiplication). **bold with two stars** For bold two stars (as in fortran exponential operator).
ldigas
@Ldigas I agree wrt C, wouldn't use it. I'm writing mathematical libraries in Java right now. The infinite precision, speed, strict typing, strict error checking, etc are really helpful. I'm not crazy about the syntax for this particular problem set. Generally it's great, but Java is better for making solutions than for making libraries. Perhaps we should come up with a fairly simple benchmark, each implement it and see where we end up? I think the ideal might be to make a new language that allows nicer mathematical syntax but compiles to a known fast language like Java, C#, ???
Bill K
@Bill K - It is not a problem to write/to make something, but to make it in a way so that people will want to use it, yet still for it to be "good" (in numerous criteria). After all, these last 5 decades, one can find a number of "great languages which are the future" (or so it seemed) which practically you can't even hear of today. Here, an article which deals with the idea that we should write a new language for hpc to replace fortran. http://cacm.acm.org/magazines/2010/7/95060-the-ideal-hpc-programming-language/fulltext
ldigas
A: 

Simple to learn (no object-oriented or functional-programming complications)

Easy to read

Blazing fast at number-crunching

Sounds like C.

Buy Numerical Recipes in C. That pretty much covers all the bases in a clear, readable style.

http://www.amazon.com/Numerical-Recipes-Art-Scientific-Computing/dp/0521431085

S.Lott
C is not neither easy to learn nor easy to read. And it's not for number crunching. http://latticeqcd.blogspot.com/2006/11/why-we-use-fortran-and-python.html
kemiisto
@kemiisto: Take it up with the Numerical Recipes authors and readers. Not me. They seem happy, even if you Georg von Hippel aren't happy.
S.Lott
When I compare the ease with which I picked up FORTRAN 77 with the difficulties I've had with C, I have a hard time recommending C for the non-programmer. Still, +1, since this seems to be what a lot of people are doing, rightly or wrongly.
JasonFruit
Can anyone name a worse choice as far as easy to use? Readability you MIGHT have competition with WORN (write once read never) languages like APL. I'm serious--please attempt to name one.
Bill K
@Bill K: Perl is a WORN language. Far more so than C. Again, you may have personal problems with C. But you'll have to take it up with the Numerical Recipes in C folks. They're happy and successful using C for scientific computing, not matter how many problems you see with what they're doing.
S.Lott
@S.Lott - what is the point of your above comment ? You state something and then reffer to "folks at NR"? Argument it if you wish it to stand.
ldigas
@ldigas: My argument remains the same. Other folks are happy and successful using C for scientific computing. I personally would never use it. But my preferred scientific programming language has "functional-programming complications". My point is simple. Other people use C. Simply discarding C as "not for number crunching" or the worst "choice as far as easy to use" seems to fail to recognize that it's already being done by people who are already successful. Their success is my argument.
S.Lott
@S.Lott I admitted other languages might be less readable, but I can't imagine one less easy to use--where you have to keep track of memory allocation, deal with pointers vs references and can't even use "abc" + "def". Ease of use. I'm coding in C right now, by the way.
Bill K
@Bill K: Please look at the book. They provide macros, hints, techniques, suggestions, libraries, all kinds of support for make C not so complex for numerical calculations. I agree that C is complex. Personally, I avoid it as much as possible. But the question -- as asked -- sure seems to point toward C as a candidate answer. "no object-oriented or functional-programming complications" and "Blazing fast at number-crunching". Nothing can touch C for these two features. It's uncluttered buy OO or FP. And it's fast.
S.Lott
@S.Lott - Where did I disgard it in that manner (catching words here; really annoying habit I learned off some in here :) But to say "Their success is my argument." is an an oxymoron by itself. What is better - a 747 or a Concorde for fast flying? Obviously, a 747, since so many happy and successful air companies use it - their success is MY argument.
ldigas
@S.Lott 2nd comment (please keep it clear when answering this one; this is gonna turn confusing anytime now) - actually, Fortran can quite catch it in that field - C is fast when used properly, no one is arguing that. But it is a language designed originally for text processing, and it takes a significant effort to optimize it in a way that match optimization of Fortran's compilers in combination with a properly written program. For, in contrast to C, Fortran was written primarily for nc. (num. calc.), and its compiler's writers have for a long time now, been working on methods for improving
ldigas
primarily that. I've seen many "optimizations" in many cases, in several languages, only for them to turn out several orders of magnitude slower than the basic algorithm with some compiler options turned on/off.
ldigas
@ldigas: C simple. C is fast. And -- most importantly -- C is already used for this. I hoped that "it's already used for this" would be enough. I hoped that providing factual evidence for "it's already used for scientific computing" would be enough. It's hard to provide more factual evidence than books, authors, readers and users. We can debate many features of the language. But we can't debate people already using it. My point is to avoid the debate and present the only fact I have. It's my only fact. I have no others.
S.Lott
@S.Lott - Apart from repeating that your argument isn't really an argument, and from a plea that you try to read my last/semilast comment with understanding, I've really nothing to add to this. 'cept that it's now closing to 01 a.m. in my part of the world, and that I'm going to sleep. So, do not take my not answering your comments the wrong way - although I will probably not be answering them anymore anyhow.
ldigas
@ldigas: I'm not sure what your point is. I presented my facts. What more do you want?
S.Lott
@S.Lott --- My preferred scientific programming language also has functional-programming complications --- and I love that. But for a scientist who is not primarily a programmer, I think it's more complication than they need. Would you disagree with that?
JasonFruit
M. S. B.
@M S. B: That F77-to-C is the same evolution I'm suggesting here.
S.Lott
@JasonFruit: "I think it's more complication than they need" No. Functional Programming is not a "complication". It's a simplification. I find it to be a considerable simplification. And quite easy to learn. But you removed it from the answer *a priori*.
S.Lott
+10  A: 

Or is the answer Fortran 90, 95, 2003 . . . ?

Yes. Fortran 95 supported by most compilers is the language you are looking for. However Fortran 2003 has some major enhancements (besides unnecessary from your point of view support of OOP) which might be useful. Compiler Support for the Fortran 2003 Standard.

kemiisto
I believe gfortran and Intel "rectified" some things off that list in their newer versions.
ldigas
+8  A: 
ldigas
Good point; when I said "mathematical applications", I should have written "computationally intensive applications".
JasonFruit
Isn't that the nice thing about Fotran? You don't have to spend your entire time on comp.lang.xx studying the latest detail of partial template specialization through not virtual lamba functors - in order to do the work you are actually being paid for!
Martin Beckett
+4  A: 

For the most direct answer to your question, I think that kemiisto's answer is correct, with the caveats identified by Idigas.

That said, I've found more of my numerical code coming into contact with things like FTP, web, and closer to graphics. I've seen MATLAB suggested in another answer, but I've been writing more and more Python (with NumPy) and calling out to Fortran when I need the speed. I'd almost certainly not write a whole system (e.g. an entire numerical weather prediction model) this way, but it does allow me to have the best of both worlds in many respects.

Tim Whitcomb
+2  A: 

Or is the answer Fortran 90, 95, 2003 . . . ? Yes. For scientific computing, Fortran >=90 removes the limitations of FORTRAN 77. Learn how to use allocatable arrays to have dynamically sizable arrays. Learn how to use modules to organize your procedures and variables -- and easily provide automatic consistency checking between actual and dummy arguments. Starting from FORTRAN 77, you can gradually learn Fortran 90/95/2003, using whichever features seem useful to you. You don't have to learn the OO features and can ignore that portion of the language, until perhaps someday it offers utility to you.

I recommend the Metcalf, Reid and Cohen book.

M. S. B.
+1  A: 

I think Fortran 95 should be your choice it looks more modern and extends Fortran 77 quite significantly. The Fortran 2003 standard is not completely supported by most compilers. The great advantage of Fortran is that there is an optimized subroutine for every mathematical problem (such as root finding, matrix multiplication, eigenvalue problems, etc.). Other people mentioned legacy libraries and lapack is just one very powerful example. A major disadvantage of Fortran is that nobody is using it in the real world.

The best book around is is my opinion "Fortran 90/95 for Scientists and Engineers".

Of course all other suggestions are valid, but matlab is not free while Fortran is.

Python is free and has support for a lot of scientific applications through extra packages such as Numpy and Scipy. Python is however rather slow when it comes to numerical performance. It's probably a good option for small projects that don't require a lot of computational power. The syntax is very easy to understand.

C is of course also a free option and has a lot of (constantly updated) scientific libraries available. However, when it comes to readability it cannot beat Fortran. Fortran is well set-up to work with vectors and arrays.

C++ is a superset of C so it's definitely also a possible choice. However, it is a language that might be to complex for the problems that you're looking at. The number of scientific C++ libraries is rather limited. There are some around but they cannot beat the Fortran versions (or are just wrappers of those). It's probably a very good option for very big projects but some very big programs that run on the world's fastest computers are written in Fortran. C++ is definitely worth learning since it is used for a broad number of real world applications.

There are of course other languages or tools but I think these are the most commonly used across scientific disciplines.

Lucas
+1  A: 

I'm surprised that the consensus here is for modern Fortran, and I grudgingly agree.

Whatever its failings, Fortran is the only language out there being designed explicitly for scientific programming. Scientific programming is both more subtle (per line) and less complicated (in structure) than, say, a web server, and it just needs different tools. Garbage collection, for instance, is almost never useful for solving large 2d/3d PDEs where your primary data structures are fixed.

Any programming language that doesn't even have multi-d arrays as first-class objects can be dismissed immediately for scientific programming. and that's all of the C-based languages. Any programing language which is inherently god-awful slow -- Java, I'm looking at you -- can be dismissed immediately. Any programming language which is proprietary and requires thousands of dollars of licensing fees -- Matlab -- can be dismissed immediately.

Python and related languages are good for prototyping, and plotting is easy, and once you've got things working can write the numerical kernels in compiled lanaguages for speed; but it again suffers from the lack of real arrays (Numpy is good, but not great) and it is s..l..o..w.

By the way -- don't ever by the Numerical Recipies books. They're crap, the algorithms they pitch are of date, and the code ranges from poor to wrong. Take a real numerical algorithms course - there's good ones on line - or buy a real numerical algorithms book -- and for the love of God, don't type in code from a book to do linear algebra or whatever; use the zillions of real, proffessional quality libraries out there.

Jonathan Dursi