The post dismisses Julia quite quickly, especially since it is a language essentially purpose built to teach numerical linear algebra. Numerical methods is taught in Julia in at least a dozen universities I'm aware of, including MIT.
Unicode support and a few other syntax niceties make translation from the blackboard to the editor nice and clean. Fortran is great but legibility and easy tooling like (reproducible) package managers are paramount in teaching
- Matlab in the first few science lab courses + first CS course.
- C++ in second CS course
- Fortran for the scientific computing course
I found Fortran worse than matlab. The error messages were difficult to parse, and it was much more difficult to do step through debugging like in matlab.
But later I learned Python, and now use it professionally to do scientific computing, and I would give anything to go back to Fortran. Or use Rust or Julia. Or if Wolfram/Mathematica if that was possible. Anything but Python.
The fundamental problem with Python is that all the math is hacked into it, unlike Julia/Matlab/Mathematica where the math takes first priority and other values are secondary.
Fortran is not a better choice unless you are only thinking about the immediate needs of the course. In the wider world, Python is going to be a lot more useful to the students.
So, the OP is an actual educator whereas I've only really advised grad students or undergrads. I'm surprised being exposed to any new language doesn't come with it's "whys" for students. Like why should we care about type safety anyway? Or why not loop over all indices, why use (:) for some of them? May be I'm not really convinced that the whys from students in a python class are worse than the whys in fortran. Honestly, if there is some compiler option for turning on implicit none by default, I'd just do that too just to get people in the door as that too feels like more confusion than it's worth keeping, although they do need to learn what it means before they leave.
Also, the downside is fortran does not have nice plotting capabilities without an external tool. At least I know of no nice libraries like matplotlib, which again is a point in just teaching them a more general purpose language from the get go to get used to it so they can plot and code in the same language...or perhaps, matlab/octave et al as others suggested. I feel like the niceness of fortran (namely, well defined type safe function/subroutine interfaces and easy path to writing performant code) that isn't offered by python is only useful after the first threshold of learning to put algorithm to paper. The literally second (and arguably for some fields, even more important) task of actually plotting results doesn't have the same convenience as the intrinsic procedures in fortran, whereas if they had learned julia or python, these tools would be at the very least be at the same convenience level of the array facilities, essentially behind a rather easy[^] to use library. In fact, in julia, you're already mostly there although it's not my cup of tea. Perhaps the answer is julia after all.
Does OP's courses just use an external program (like gnuplot) or a black box to plot?
[^] easy to use once you know how to program a little, of course.
It seems pretty clear to me that the best language to use for numerical linear algebra is the language you know and a good curriculum would be structured in a way where your first encounter with a language is not a course where the choice of language is nearly irrelevant.
I think fortran would be cool if they program it by hand on punch card and the teacher then executes these to check the programs. Like in the very early days of programming where you had to submit these punch chards and wait until they get executed on the mainframe by an operator.
I don't see what's wrong with Python for a first course. In fact, you can go very far with Python alone (in terms of performance) if you learn to use Numba well. If that isn't enough, I would go straight to C (opportunistically augmented by C++98 when needed), and learn how to use the GNU Scientific Library and Eigen (the linear algebra library).
> While you have to use np.linalg.norm in Python to compute the norm of a vector, Fortran natively has the norm2 function for that. No
That's what sucks in python as a newbie. Wanted to play with random, which python docs says it's a builtin. Obscure error message. Search the internet, no fix in sight. After more searching i found out that i actually have to "import random" (builtin ??) and use a method ? Wtf.
So definitely python is not for newbies. Fortran code is much easier to underestand.
Stating that Fortran is better for teaching numerical linear algebra is like stating that Latin is better for teaching medicine.
Sure, it might be a better fit, but unless your students have all the time in the world, it doesn't seem very efficient to put your students through the extra burden of learning an unfamiliar syntax, development environment etc.
If it's about teaching and not about efficiency, why not just use plain Python? One could argue it is actually better since students don't have to worry about typing and syntax, and it allows a gentler introduction to commonly used tools like jax and numpy while getting comfortable with the language.
I’m a teaching assistant in a C++ course for second-year physics students. The goal is to teach numerical and data analysis, but the course is structured around a very object-oriented style. For example, every function is defined through inheritance:
Everything in the course (numerical integration, PDEs, Monte Carlo sampling, …) follows this pattern.
The professor is an excellent teacher and students love him. But other faculty worry that our students leave without any real exposure to Python, and that they keep reproducing this heavy OOP style even in situations where a simple lambda or a few lines of NumPy would be far more natural. (Lambdas are shown at the very end of the course, but mostly as a curiosity.)
That’s why I found the blog post so interesting: it shows how natural code can look in Python or Fortran. By contrast, our students’ code is weighed down by boilerplate. It makes me think that sometimes the real difficulty in teaching numerical analysis isn’t the language itself, or whether arrays start at 0 or 1, but the teaching approach that frames every problem through layers of abstraction.
1. Students are allergic to useless knowledge. Prof. could ask them whether they prefer a "better" programming language they will never use OR one 99% of them will use every day at work. 2. Good luck finding TAs and support staff for Fortran-centric courses.
There are two sides to numerical linear algebra. The first is the "linear algebra" part, which is very mathematically sophisticated and the language you choose to represent these concepts is not so important as your understanding. pencil and paper is the ideal place to prove out understanding of this.
The "numerical" part is a minefield because it will take all your math and demolish it. just about every theoretical result you proved out above will hold not true and require extra-special-handholding in code to retain _some_ utility.
As such I think a language which enables you to go as fast as possible from an idea to seeing if it crosses the numerical minefield unscathed is the one to use, and these days that is python. It is just so fast to test a concept out, get immediate feedback in the form of plotting or just plain dumb logging if you like, and you can nearly instantly share this with someone even if you're on ARM +linux & they are Intel+windows
The most problematic issue with python&numpy, as it relates to learning _numerical_ side of linear algebra, is making sure you haven't unintentionally promoted a floating point precision somewhere (for example: if your key claim is that an algorithm works entirely in a working precision of 32 bits but python silently promoted your key accumulator to 64 bits, you might get a misleaing idea of how effective the algorithm was) but these promotions don't happen in a vacuum and if you understand how the language works they won't happen.
edit: & I have worked professionally with fortran for a long time, having known some of the committee members and BLAS working group. so I have no particular bias against the language
Sure, it is fine to teach numerical linear algebra in Fortran - 15 years ago, I was learning with Fortran 77. Yes, there are many benefits of using a different language, even for its own sake. Or using a language without distractions - just to focus on the course, rather than one that can be used for building a website or so. Or without less "magic" than Python.
At the same time, I find most argument bizarre, other - harmful.
From the bizarre region, students asking "What is 'import numpy as np'?". A legit question. If you want to avoid all technicalities, pen and paper is the right approach. All in all, they need to run code somehow and there will be questions like "What is 'implicit none'?"
If they are not asking such question, is is not because they focus some much on linear algebra. It's because they are lost - or at very least - have lost interest.
From ones (in my opinion) actively harmful:
> It’s about teaching the basics of scientific computing to engineering students with a limited programming experience.
This is a big red flag. If they have little background in programming, teach good standards of Python. Otherwise they will get worst patterns, and think that GOTO is the preferred way of coding.
If you think why a lot of academic code looks like mess, one of the reason is using archaic tools and techniques as a standard.
Also - if your focus in linear algebra and avoid magic, you CAN do it without any numpy, just Python lists.
28 comments
[ 4.8 ms ] story [ 42.9 ms ] threadAlso the swapping of u and tmp doesn't work like that in python. Might in fortran.
Unicode support and a few other syntax niceties make translation from the blackboard to the editor nice and clean. Fortran is great but legibility and easy tooling like (reproducible) package managers are paramount in teaching
- Matlab in the first few science lab courses + first CS course.
- C++ in second CS course
- Fortran for the scientific computing course
I found Fortran worse than matlab. The error messages were difficult to parse, and it was much more difficult to do step through debugging like in matlab.
But later I learned Python, and now use it professionally to do scientific computing, and I would give anything to go back to Fortran. Or use Rust or Julia. Or if Wolfram/Mathematica if that was possible. Anything but Python.
The fundamental problem with Python is that all the math is hacked into it, unlike Julia/Matlab/Mathematica where the math takes first priority and other values are secondary.
This was the path I took, before going to Python, Go, and Rust.
Also, the downside is fortran does not have nice plotting capabilities without an external tool. At least I know of no nice libraries like matplotlib, which again is a point in just teaching them a more general purpose language from the get go to get used to it so they can plot and code in the same language...or perhaps, matlab/octave et al as others suggested. I feel like the niceness of fortran (namely, well defined type safe function/subroutine interfaces and easy path to writing performant code) that isn't offered by python is only useful after the first threshold of learning to put algorithm to paper. The literally second (and arguably for some fields, even more important) task of actually plotting results doesn't have the same convenience as the intrinsic procedures in fortran, whereas if they had learned julia or python, these tools would be at the very least be at the same convenience level of the array facilities, essentially behind a rather easy[^] to use library. In fact, in julia, you're already mostly there although it's not my cup of tea. Perhaps the answer is julia after all.
Does OP's courses just use an external program (like gnuplot) or a black box to plot?
[^] easy to use once you know how to program a little, of course.
I'm with Dijkstra on this one. https://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831...
They always want to teach the more elegant and divine method that, in reality, nobody uses.
I studied Pascal and Fortran when they could have taught me more widely used languages. Shame on them.
If Fortran is so useful and clear, just offer some lessons on it. Surely students will be enlightened and captivated by it.
That's what sucks in python as a newbie. Wanted to play with random, which python docs says it's a builtin. Obscure error message. Search the internet, no fix in sight. After more searching i found out that i actually have to "import random" (builtin ??) and use a method ? Wtf.
So definitely python is not for newbies. Fortran code is much easier to underestand.
The professor is an excellent teacher and students love him. But other faculty worry that our students leave without any real exposure to Python, and that they keep reproducing this heavy OOP style even in situations where a simple lambda or a few lines of NumPy would be far more natural. (Lambdas are shown at the very end of the course, but mostly as a curiosity.)
That’s why I found the blog post so interesting: it shows how natural code can look in Python or Fortran. By contrast, our students’ code is weighed down by boilerplate. It makes me think that sometimes the real difficulty in teaching numerical analysis isn’t the language itself, or whether arrays start at 0 or 1, but the teaching approach that frames every problem through layers of abstraction.
Practicality beats purity.
The "numerical" part is a minefield because it will take all your math and demolish it. just about every theoretical result you proved out above will hold not true and require extra-special-handholding in code to retain _some_ utility.
As such I think a language which enables you to go as fast as possible from an idea to seeing if it crosses the numerical minefield unscathed is the one to use, and these days that is python. It is just so fast to test a concept out, get immediate feedback in the form of plotting or just plain dumb logging if you like, and you can nearly instantly share this with someone even if you're on ARM +linux & they are Intel+windows
The most problematic issue with python&numpy, as it relates to learning _numerical_ side of linear algebra, is making sure you haven't unintentionally promoted a floating point precision somewhere (for example: if your key claim is that an algorithm works entirely in a working precision of 32 bits but python silently promoted your key accumulator to 64 bits, you might get a misleaing idea of how effective the algorithm was) but these promotions don't happen in a vacuum and if you understand how the language works they won't happen.
edit: & I have worked professionally with fortran for a long time, having known some of the committee members and BLAS working group. so I have no particular bias against the language
At the same time, I find most argument bizarre, other - harmful.
From the bizarre region, students asking "What is 'import numpy as np'?". A legit question. If you want to avoid all technicalities, pen and paper is the right approach. All in all, they need to run code somehow and there will be questions like "What is 'implicit none'?"
If they are not asking such question, is is not because they focus some much on linear algebra. It's because they are lost - or at very least - have lost interest.
From ones (in my opinion) actively harmful:
> It’s about teaching the basics of scientific computing to engineering students with a limited programming experience.
This is a big red flag. If they have little background in programming, teach good standards of Python. Otherwise they will get worst patterns, and think that GOTO is the preferred way of coding.
If you think why a lot of academic code looks like mess, one of the reason is using archaic tools and techniques as a standard.
Also - if your focus in linear algebra and avoid magic, you CAN do it without any numpy, just Python lists.