Fortran90 vs C vs C++: not a troll

  • Fortran
  • Thread starter mrentropy
  • Start date
  • Tags
    Fortran90
In summary, the discussion revolves around the advantages of Fortran90/95 over C/C++ in terms of codability, particularly for big numeric codes. The main appeal of Fortran90 seems to be the module feature, which allows for easier namespace encapsulation. However, some argue that C++ can also achieve this with methods. Others suggest using both languages, with the bulk of the code written in C++ and individual routines optimized in Fortran. There is also mention of Fortran 2003 and the improved interoperability with C++. Overall, the benefits of Fortran90 seem to be in its ease of handling multi-arrays and complex numbers, but it may not offer significant advantages over C++ in terms of overall codability for
  • #1
mrentropy
9
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
  • #2


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:
  • #3


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.
 

1. What are the main differences between Fortran90, C, and C++?

The main difference between Fortran90, C, and C++ is their intended use and programming paradigms. Fortran90 is primarily used for scientific and numerical computing, while C and C++ are general-purpose languages with a focus on system programming and low-level operations. C++ also includes object-oriented programming concepts, making it more versatile for a wider range of applications.

2. Which language is the fastest for programming?

There is no clear answer to this question as it depends on the specific task and implementation. Generally, Fortran90 is considered the fastest for numerical computations due to its efficient handling of arrays and mathematical operations. C and C++ are also very fast due to their low-level nature and lack of overhead. However, with proper optimization techniques, all three languages can achieve similar levels of speed.

3. Which language has the most user-friendly syntax?

This is subjective and can vary from person to person. However, many people consider C++ to have the most user-friendly syntax due to its support for both procedural and object-oriented programming paradigms. Fortran90 and C have more rigid syntax rules, making them less intuitive for beginners.

4. Can programs written in Fortran90, C, and C++ be used together?

Yes, it is possible to use programs written in Fortran90, C, and C++ together. While each language has its own syntax and features, they can all be compiled to machine code and called by other programs. In fact, many scientific and engineering applications use a combination of these languages for different tasks.

5. Is one language better than the others overall?

Again, this is a subjective question and depends on the specific use case. Each language has its own strengths and weaknesses, and the best language to use will depend on the requirements of the project. It is important to consider factors such as speed, functionality, and community support when choosing a language for a specific project.

Similar threads

  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
2
Replies
40
Views
2K
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
5
Views
9K
  • Programming and Computer Science
Replies
18
Views
2K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
34
Views
3K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
Back
Top