Re: Why do you still use Fortran?
- From: Brooks Moses <bmoses-nospam@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 09 Dec 2005 16:06:29 -0800
AN O'Nymous wrote:
When I first graduated, I was quite unsettled to learn that C/C++ was the lingua franca in most of the engineering companies I applied to, and that Fortran tended to be used in niche applications.
My undergraduate education only encompassed Fortran and although I could have put effort into learning C/C++, I thought (and still think) that spending time learning another language would turn me into a jack of all trades, but master of none.
I think that's an unwise idea. Spending the time to learn another language (particularly one that's conceptually different from what you are used to, like C++) will introduce you to other ideas about how programs can be structured. This will give you a broader toolset that you can then use when designing programs to be written in Fortran.
Because of that sort of thing, I believe that learning C++ has improved my Fortran programming skills. A lot of the concepts around "object oriented" code are very useful in many programming applications -- and many of the concepts are quite usable in Fortran programming, but the language doesn't happen to guide the user in writing that way, so it's not something I would have been likely to learn without learning C++ or something similar.
The only thing that you might lose, in my experience, in learning other languages rather than spending that time on Fortran, is that you might not have the sort of understanding that allows you to tell me the difference between the MOD() and MODULO() intrinsic functions without looking it up. Except in rare conditions, I don't think that's a significant loss. The fundamental skill is not "Fortran programming", but "programming", and any time spent programming in any language improves that skill, particularly if you're doing something new.
So...why do you still use Fortran?
Because its language features match well to the set of things that I want to write, and thereby make it easier for me to write the programs that I'm writing.
Specifically, Fortran's core language is designed to make it very easy to deal with multidimensional arrays. They are easy to declare, easy to allocate without requiring one to worry about memory leaks, easy to pass around, and easy to select subsections of. It's also easy to do whole-array operations such as setting all the elements to a uniform value or to a function of another array.
To get anything approximating that in C++, I would need to use some sort of library file, and then I would need to worry about whether that library was present everywhere I wanted to use my code, and so forth; with Fortran, it's part of the language. More significantly, I probably would not use the same C++ array library that someone else uses, and that makes it harder for me to use their code in mine, or to contribute to their project.
Beyond that, Fortran has a number of other nice features that I find useful -- intent() declarations, for instance. The Fortran I/O system is very nice for writing purpose-specific data files; it doesn't require much work at all to get something working.
Why do these niche applications (such as the algorithms running on the Earth Simulator) use Fortran?
I don't know, but I suspect that it's a combination of the reasons that I cited, and the fact that they incorporate significant amounts of older Fortran code that predates the existence of C++ (and possibly even of C).
As an undergrad, we were told that Fortran was more efficient for math-intensive algorithms. Is this true? Why is this the case and what sources cite this to be so?
It is more efficient to write, in many cases, because of the array syntax.
For calculations, this is a definite function of the compilers. In some cases, Fortran syntax allows compilers to make more optimizations that C or C++ syntax, but I am uncertain how much this matters in practice.
Another reason this could be true is that Fortran 77 only had static array allocation, whereas C and C++ have the ability to do dynamic allocation. If one misuses the latter ability in a way that causes one to be continually allocating and deallocating arrays, that can cause a performance problem.
Do you suggest that I at least pick up some basic C/C++? If so, where should I start?
I suggest that you should pick up some basic C++; see above for why.
I will (somewhat flippantly) say that you should start by learning why "C/C++" is meaningless in this context, and what the differences are. Specifically, I think that what will be most useful for you to learn are the things that are in C++ but not in C.
How I learned was to read a bit about object-oriented design, and then pick a small project that I wanted to do that would work well with that. And then I tried writing a program to implement it -- I wrote out a rough design, and then for each piece I read through Bjarne Stroustrop's _The C++ Programming Language_ until I figured out how to write it. For some basic things involving pointers, that didn't really help much, and so I asked my friends who know C++ about how to do that. (One of them also loaned me a copy of Ellis and Stroustrop's _The Annotated C++ Reference Manual_, which was helpful for that sort of thing).
I do not know if I would recommend this method; it worked for me, but that's in part because I knew a little bit of C once, and also I tend to be rather different from a lot of people with regards to such things. Also, it does involve a lot of reading and re-reading of large books.
I will, incidentally, recommend my method for picking from the vast collection of C++ reference manuals at the local bookstore, once you have a very little bit of knowledge: Think of a typical thing about C++ programming that want to look up in your new reference manual. Pick up each book in turn, and try to find the answer to your question in the book.
Hope this helps! - Brooks
-- The "bmoses-nospam" address is valid; no unmunging needed. .
- Why do you still use Fortran?
- From: AN O'Nymous
- Why do you still use Fortran?
- Prev by Date: Re: ftnchek illegal character bug?
- Next by Date: Re: Why do you still use Fortran?
- Previous by thread: Re: Why do you still use Fortran?
- Next by thread: Re: Why do you still use Fortran?