Why is C Preferred for Numerical Analysis over Fortran?

  • Context: Fortran 
  • Thread starter Thread starter geouke
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion centers around the comparative advantages of C and Fortran for numerical analysis, particularly in the context of academic work versus industrial programming. Participants explore the suitability of each language for various applications, learning curves, and the relevance of legacy code in scientific computing.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • Some participants suggest that C is more standardized and has broader applications than Fortran, which is specifically designed for numerical computations.
  • Others argue that the choice of language should depend on the specific problem and existing codebases, noting that Fortran is still widely used in scientific fields.
  • There are mentions of the importance of interoperability and support for different operating systems when choosing a programming language.
  • Some participants highlight the historical context of programming languages, noting the evolution from Fortran to C, C++, and newer languages like Python, suggesting that trends in education may influence language popularity.
  • One participant emphasizes the value of legacy Fortran code and libraries in scientific computing, arguing that they are often more reliable and easier to integrate than C code.
  • There is a discussion about the learning curve associated with C compared to Fortran, with some asserting that Fortran is simpler to learn and program in.

Areas of Agreement / Disagreement

Participants express differing views on the advantages of C versus Fortran, with no consensus reached. Some advocate for the use of Fortran in specific contexts, while others promote C for its versatility and standardization.

Contextual Notes

Participants note that the discussion is influenced by personal experiences and specific applications, which may limit the generalizability of their claims. The relevance of legacy code and the evolution of programming languages are also highlighted as factors in the debate.

geouke
Messages
9
Reaction score
0
I am a graduate geology student and have been using MATLAB for about a year now. I began learning C a while back to have a broader tool-set to work with but found that it just got in the way of learning material more specific to my major. Besides, MATLAB does everything I need anyway.

That being said, I do appreciate that free compilers are available for languages like C and Fortran and that they can execute models more quickly. I began to read an introductory text on Fortran the other day and it seems to be easier to learn than C. Perhaps like MATLAB, it is designed more for numerical analysis than general applications.

My question is this: is there really any advantage for someone like me to learn C instead of Fortran? I do not plan to write programs for a living, the standard tool-set used by the USGS to model groundwater flow (MODFLOW) is already written mostly in Fortran, and C seems to have a steeper learning curve and does not seem to execute programs any more quickly.

I am probably opening an old can of worms. I guess I am wondering why someone who works primarily with numerical analysis or modeling (in an academic sense rather than industrial) and does not plan to market themselves as a programmer upon graduation should learn C rather than Fortran. Cool tricks aside, why should C be the standard for serious numerical work rather than Fortran?

Thanks!
 
Technology news on Phys.org
C as a language is more standardized than Fortran and has more uses as a programming language. True Fortran was designed to do numerical computations well. The variations in either language you might see are in libraries on various platforms or how C would interact with a given OS (windows vs unix/linux/macosx...).

The reality is you learn the language you need to use. If the problem you're working on references other peoples work and they used Fortran then you should use Fortran. If you're thinking of making your work available on many platforms then you might consider C/C++. If you plan to market your work on Android or make it available everywhere then you might consider Java.

With respect to Java, the Open Source Physics project has a large collection of simulations all done in Java using the the OSP library of ODE solvers, and display components that while not the fastest is more flexible than Matlab especially if you're sharing your work with others who may not have Matlab.

My language preference right now is Scala, touted as a better Java than Java with Object Oriented and functional programming capabilities merged together interoperating seamlessly with Java and running on the latest JVM.
 
Hey geouke and welcome to the forums.

Funnily enough depending on the type of work, you have positions which are known as 'legacy programmers', which deal with working with and maintaing codebases that are written in old languages and platforms. In these cases, solid experience with something like FORTRAN or even COBOL is a requirement for getting the job.

But the reason for using newer languages is many-fold and depends on the specific application.

One is functionality, another is potential for optimization (very good compilers especially for specific architectures are common for something like C++ as well as FORTRAN), another is readibility, another is flexibility, another is related to development time for creating applications, another is interoperability (using specific OS functionality, communicating with other programs through things like DLL's).

Interoperability is a very important one because nowadays, you have not only single programs using multiple libraries communicating together, but different applications in their own process space communicating together.

Finally, and this is a very important factor, has to do with the support of a particular language/technology/operating-system/library/standard. Having something as a standard is critical. Windows is good for developers because of the sheer amount of support that it gets not only from software developers, but also from the hardware vendors themselves. This is one reason why linux wasn't a popular thing in the past, because windows had a much better driver model and framework which is really nice for hardware vendors (not to mention that windows came prepackaged with every new PC and still does which entice hardware vendors to support windows).

When you factor all these kinds of things and the attitudes of software development as they progress and mature, you get the shift from things like FORTRAN to C++ to .NET to whatever the next generation of development environments will be.
 
Yes, geouke, why not Fortran?!

For what you have in mind, there is absolutely nothing wrong with Fortran.

Some of the hype about teaching a particular new language at school which then drives the next generation of programmers to start writing software in another language is sometimes driven by novelty, fashion, or pure financial interest by an individual company. That's why schools, for various reasons, have gone from teaching Fortran to C to C++ to Java and now you see them including Python...talk about becoming the language of choice by your own merits without a marketing engine (Java, Sun Microsystems) behind you.

Fortran stands for FORmula TRANslation, and it was invented to do math.

C was invented to write Unix :-) and it is more of a systems kind of programming language.

C++ is object oriented programming and many people were getting hit with memory leak programs, etc.

Java was supposed to be answer to C++ problems.

Python...well, I let you read about Python.

In any case, in your field and in general for the sciences, Fortran is a lot more popular than the typical programmer thinks.

There is a lot legacy code, great long standing libraries that do all sort of linear algebra and other simulation that have been around so long that are now pretty much bug free...that's were part of the value is.

Also, typically, Fortran is more standardized than C...if somebody give a fortran library to something or there is a package out there from a given company, you can comile it along with your program and it typically incorporates a lot easier than if you were programming in C.

Fortran, for the longest time, did not suffer of memory leaks and things like that...I don't know if that trend continues or whether with Fortran 90 and 2003 with structures, pointers and allocation...it is starting to suffer too.

Anyway, I do program in Fortran and C...I would agree than Fortran is much simpler to learn and to program in.

And if you would learn Python...you could do a bunch of things...if it gets numeric intensive, you always wrap your fortran code by executing f2py and simply call your fortran from python.

Good luck.

gsal
 
Thanks for all of your helpful replies!
 

Similar threads

Replies
16
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
86
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 397 ·
14
Replies
397
Views
21K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K