C/C++ Fortran90 vs C vs C++: not a troll

  • Thread starter Thread starter mrentropy
  • Start date Start date
  • Tags Tags
    Fortran90
AI Thread Summary
The discussion centers on the advantages of Fortran90/95 over C/C++ in terms of codability, particularly for large numerical codes. A key point raised is the modularity of Fortran90, which allows for better organization of code, although concerns about namespace collisions are noted. Comparisons are made to C++, where encapsulating methods within classes can simplify namespace management. The importance of efficient coding practices for large projects is emphasized, with a call for Fortran90 advocates to highlight its benefits in managing extensive codebases. Ultimately, the conversation seeks to clarify what unique advantages Fortran90 modules offer that are not available in C or C++.
mrentropy
Messages
9
Reaction score
0
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.

Thanks...
 
Last edited:
Technology news on Phys.org


Two comments:

(1) C++ is even better than you think. A good, modern C++ numeric library, such as http://www.oonumerics.org/blitz/benchmarks/ 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:


Thanks.

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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top