Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran90 vs C vs C++: not a troll

  1. Oct 3, 2008 #1
    Fortran90 vs C vs C++: not a troll!!!

    Ahhh, yes, the perennial debate that leads inevitably to broken bottles and fisticuffs. I'm being quite sincere here, though, although I'm sure the end of the thread may be ignoble.

    What I'm wondering is this:

    --->> What are the ADVANTAGES of Fortran90/95 over C/C++ as far as codability is concerned, NOT raw power? Are there any? <<----

    By far the most intriguing part of F90 is the module, which grew out of common blocks. It's a neat idea and I really like it, but on the other hand, Fortran seems to suffer from the fact that importing a module means the module's namespace walks all over your local namespace, in contrast with Python, say, where you can do "import foo" to make a qualified namespace instead of "from foo import *", to avoid namespace collisions.

    And then, in C++, you can really avoid namespace problems by making your procedures methods instead, so that there's no confusion between fooobj.sort() and barobj.sort(), for example, if fooobj is an instantiation of class foo, likewise for bar, and foo and bar classes both have sort methods. To me, that seems to make life simpler.

    Perhaps this is why when I try to do things like make a doubly linked list in Fortran 90, it confuses the heck out of me and I end up wrapping modules in modules, and I get namespace problems, whereas in C++ it seems rather straightforward.

    I need to write a big number crunching physics code (don't ask) and I know from prior experience that once you start getting near the 100,000+ line code level, the language features that were minor annoyances before can become major headaches. When codes get that big, namespace encapsulation is key IMLE.

    What I'd like is for SOMEBODY out there to try to convince me that for big numeric codes the Fortran 90 module is great for making truly manageable, modular code, where you aren't liable to find yourself inadvertently walking all over namespace with muddy boots mucking the rest of your code up.... Somehow part of me wants to believe that, somehow or another, there's something inherent about working with a big huge STATE space (that is, the internal representation of some PDE on a huge mesh, particle trajectories, etc) that amends itself well to Fortran90 modules.

    The other stuff - simple multi-array support, complex number support, fast integer power, side-effect free sqr(), that stuff isn't that important to me. It's a shortcoming of C that it doesn't have those, and it's a pain, but I can work around it. And things like 20% speed diffs just don't seem that important to me when the biggest speedup for my sort of programming comes from being able to get something *working* fast and using smart parallel algorithms that don't lock up (I'm using MPI on a beowulf....)

    So please, Fortran90 fans, save me from my evil C/C++ ways and tell me what I really get with the f90 module that I don't get with those languages.

    Last edited: Oct 4, 2008
  2. jcsd
  3. Oct 4, 2008 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Re: Fortran90 vs C vs C++: not a troll!!!

    Two comments:

    (1) C++ is even better than you think. A good, modern C++ numeric library, such as http://www.oonumerics.org/blitz/benchmarks/ [Broken] for linear algebra, can give results comparable to handcrafted C or Fortran code. And there are a handful of things that can be done reasonably in C++ that couldn't be done sanely in C or Fortran without writing a separate program to write your program.

    (2) Why choose when you can use the best of both worlds? Write the bulk of your program in C++ (or even an interpreted language like python). And then, when it comes time to optimize, you can write individual routines in Fortran as necessary.
    Last edited by a moderator: May 3, 2017
  4. Oct 4, 2008 #3
    Re: Fortran90 vs C vs C++: not a troll!!!


    I love Perl and I like Larry Wall's statement about easy things being easy and hard things being possible. Of course you always have to match the tool to the job, so the question is:

    Regarding Fortran modules: What are the the easy things that are made easy by modules, that are hard to do in C or C++?

    Like I said, I mean it sincerely. I think the F language in particular is a very nice, cool, clean subset, but I still don't get what I get with it that I don't already have in C land other than the usual stuff I've already mentioned (easy multi-arrays, complex, etc).


    Anyway I have intel's C and Fortran compiler suite on my cluster so I'm looking forward to playing with the improved interoperability of Fortran 2003, although I'm not sure I'm brave enough to try to mix C++ and modern (>77) Fortran.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook