[Tutor] Hi

Steven D'Aprano steve at pearwood.info
Sat Apr 11 19:12:17 CEST 2015


On Sat, Apr 11, 2015 at 08:35:08PM +0400, Vick wrote:

> Given that all scientists like to code in Fortran but does it mean that
> Python is inferior to it in terms of mathematical / scientific computation?

Scientists do not like to code in Fortran. Anybody who tells you that is 
mistaken. If they wanted to be programmers, they would have become 
programmers, not scientists. If they *have* to program, they will, but 
they would rather do science, not programming.

No, Python is not inferior. It is just different. It is designed to have 
different strengths and weaknesses compared to Fortran.

Strengths of Fortran:

- You can write very fast, powerful numeric programs.
- Fortran excels at high-speed number-crunching.
- Fortran is an old language, in fact it is the first (and therefore 
  oldest) programming language. Because it has been around since the 
  1950s, there are lots of Fortran libraries you can use -- if you can 
  find them, or afford them.

Weaknesses of Fortran:

- It is difficult to write Fortran code.
- It is an old language which lacks modern programming features.
- It is hard to work with strings or do anything except 
  number-crunching.
- It is a very low-level language, which means you have to care about 
  things that have nothing to do with the problem you are trying to 
  solve, like memory.


Strengths of Python:

- It is a modern language with many modern features that Fortran lacks.
- It is easy to work with strings and other associated data structures.
- It is a high-level language that automatically looks after all the 
  boring book-keeping details, like memory.
- It excels at rapid application development.
- It excels at being a glue-language for calling pre-written C or 
  Fortran libraries.

Weaknesses:

- Pure Python code may be a bit slower that C or Fortran code. (But that 
  doesn't matter, if you can call a C or Fortran library to do the heavy 
  lifting, and leave Python to do the parts that C or Fortran struggle 
  with.)


When people tell you that "real scientists" write their code in Fortran, 
they are being macho pretentious fools. Do "real scientists" also make 
their own test tubes from sand they dug out of the ground themselves? 
No, of course not. It isn't 1800 any more, and the average scientist no 
more needs to program in Fortran than they need to grind their own 
lenses. Some scientists may still need to use Fortran, but that is a 
sign that they are still stuck with using ancient computer programs, not 
a good thing to be copied.

To give an analogy, Fortran is like flying a Suyez rocket. It is very 
difficult to learn to fly, but once you master it you can go into space 
in seconds. But it will takes years of training and months of 
preparation for each flight.

Python is like driving a car: it won't get you into space, but it takes 
weeks to learn to drive a car, not years, and you can jump in the car 
and drive to the shops with no preparation needed.

And you can get in your car and drive to the Suyez rocket, but you 
cannot get in the Suyez and fly to where you parked your car.

Which is better? Well, it depends. If you want to drive to the shops, 
the Suyez is completely useless. It costs fifty million dollars every 
time you use it, and you cannot even get to the shops.

If you want to spend six months writing a Fortran program to analysis 
your data, you can, and when you have finished, it will run in five 
seconds. Or you can spend six days writing it in Python, and it will run 
in five minutes. Which is better?

To be more precise: Python can use Fortran and C libraries to do the 
heavy lifting, the difficult work. Doing that from Fortran or C is a 
horrible experience: they are hard languages to learn, and hard to use. 
But using those libraries from Python is fast, and fun, and easy, and 
that means that scientists can spend more time doing science and less 
time trying to program the computer.



-- 
Steve


More information about the Tutor mailing list