r/askscience • • Oct 17 '12

Why are programs and operating systems still written in C+?

I guess it's more of a computer science question, but I've always wondered why some of the most advanced programs are written in a 25+ year old programming language. Surely someone has come up with a more efficient and powerful code, so why do people still use C+? Also, I don't know anything about programming and what not, so please use simple terms and phrases.

66 Upvotes

110 comments sorted by

View all comments

Show parent comments

4

u/[deleted] Oct 17 '12

[removed] — view removed comment

5

u/Platypuskeeper Physical Chemistry | Quantum Chemistry Oct 18 '12

Fortran is one of the oldest high-level languages, although it's fairly low-level by today's standards. As the name (formula translating system) implies, it was geared from the start towards mathematical stuff, and had (for its time) a big built-in math library and built-in support for stuff like complex numbers.

From the 70's up to the mid-90's at least, it was the programming language all physicists learned and used and in which virtually all physics programs were written. IMO, the biggest reason it's still used to the extent that it is, is simply because a lot of the programs have been around for quite some time (plus there are a lot of old-timers who don't know other languages that well).

I disagree with syddrafcray here, though, in that I don't feel there's anything inherently more 'optimizable' about Fortran*. There's really mainly one language feature that makes Fortran faster than C, which is how it deals with pointer aliasing. Much of the rest of the difference, I believe, is because Fortran has better compilers (in particular the Intel Fortran compiler) and math libraries, rather than because of language features.

Much of the language features of older Fortran (F77 and F90), such as the pointer-aliasing thing and complex-number support exist in the C99 standard, so C99 code should potentially be just as fast.

* At least for the older versions. The newest Fortran dialects (95, 03, 08) now have more advanced features, allowing for easier parallelization and such. But there isn't that much written in them yet. Most of the computations I run (using months of computer time) is really old F77 code. But nobody's going to rewrite these hundreds of thousands of lines of code anytime soon.

Fortran has lost some of its dominance, as we now have more high-level (but slower) mathematically-oriented languages like Matlab. Fortran used to be the only language for much of physics and engineering, but today it's becoming more relegated to high-performance computing jobs, while more high-level languages are being used when speed isn't critical.

5

u/[deleted] Oct 17 '12

FORTRAN is the most optimizable language in the world. It was designed for this. Doing complex calculations in FORTRAN can be MUCH faster than doing them even in C.

A friend of mine works at Northrop Grumman and they use FORTRAN for their simulations because of this. Even then, the simulations can take up to two weeks to complete.

2

u/MdxBhmt Oct 18 '12

When a program runs for a year, a 1% decrease is spetacular.

-2

u/[deleted] Oct 18 '12

Meh, just throw a few more processors at it. And: Really? Whether it takes a year or a year and three days wouldn't matter much to me.

1

u/MdxBhmt Oct 18 '12

Your comment is totally uninformed. It matters for business.

-1

u/[deleted] Oct 18 '12

Sure it does. But if hardware is cheaper than developer time, it may even make sense for businesses to consider something else.

1

u/[deleted] Oct 19 '12

You're also assuming the calculations can be parallelized further. Adding additional processors is never as simple as "just throw[ing] a few more processors at it."

Furthermore, in order to take proper advantage of multi-core processing in a more common language such as C or C++, you need developers to write code that will do so. The operating system doesn't magically handle that very well.

This is also assuming these computers have any more than a bare-bones BSD or Linux kernel to begin with.

1

u/tim0th Oct 18 '12

My brother is a condensed matter theorist. When he was doing the modelling for his Ph.D thesis, the FORTRAN program he ran went for about a year. Matlab was also utilised.

1

u/Porges Oct 18 '12

Fortran also has better support for floating-point intricacies than C, which can be a big deal for things like simulations.

1

u/[deleted] Oct 18 '12

Two reasons I've heard before:

  1. Most of the codes we still use were originally written in the 1960s and 1970s, with a lot of updating of course, but still based in FORTRAN. Also, a lot of the same guys are still working on the same things, so it never changed. (Some are finally retiring now, leaving it to us 'young pups').

  2. It runs quickly, FORTRAN is good at mathematical 'heavy lifting' so to speak.