15 comments

  • patagurbon 4 hours ago
    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

    • noobermin 4 hours ago
      Saying fortran is not legible is not an argument that holds water against fortran 90. I don't want to be uncharitable but I don't know how anyone can have this opinion unless they just don't have much familiarity with it.
      • patagurbon 2 hours ago
        I didn’t say it was illegible. I said legibility is paramount, and I don’t think it makes the right trade offs in that regard to be a great teaching language

        It’s far more legible for numerics than a lot of languages, maybe except Julia and Chapel. Julia was just driven in large part by teaching mathematics at mit and I think that shows

      • jcranmer 3 hours ago
        A large share of the illegibility of Fortran code is actually just the aversion of numerics code to having meaningful variable names.
        • atrettel 6 minutes ago
          I second this. When I worked on some older Fortran codes, I had to keep a cheat sheet for the variable names and what they meant or controlled. It definitely made the code hard to read.
  • abdullahkhalids 4 hours ago
    My scientific computing journey was

    - 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.

    • noobermin 4 hours ago
      May be you learned all of these extremely recently before for decades I would definitely say C++ error messages were far worse than anything a fortran compiler has ever barked at me for. The bad days are definitely over but I still think C++ template errors can still be the thing of horrors even today. I know you compared matlab to fortran but you even said you took C++ just prior to this and I'm amazed that didn't harden you for anything gfortran/ifort would throw at you.
    • bluedino 4 hours ago
      What are the obstacles in your using Fortran (or Rust or Julia) in place of Python?
      • abdullahkhalids 3 hours ago
        Many other researchers I work with have almost no programming experience outside of Python or other high-level languages. Switching to Fortran or Rust will significantly slow down our work for at least an year or two while people catch up.

        Julia would be easier to switch, but it's still months of work to port over existing libraries.

    • naijaboiler 4 hours ago
      correct. Python is a general purpose language pretending to speak math.
  • noobermin 4 hours ago
    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.

    • shakna 4 hours ago
      Fortran has a few nice plotting libraries. [0] Including matplotlib.

      Personally, I've only used ogpf, which is a single-file library, making it easier to run for beginners.

      [0] https://fortran-lang.org/packages/graphics/

      • noobermin 3 hours ago
        I did a cursory scan and some of these seem not my cup of tea, but honestly ogpf looks rather pleasant for quick plots. Thanks! I might use this.

        That said, the point of these being external libraries and thus making them a bit less convenient still sort of stands, as being external libraries means you need to link them which exposes more CS tier stuff (installing libraries, make files, etc) that distracts from just learning codes, which again just motivates using a tool that abstracts some of that behind a managed package and library system.

        I'm assuming you could use things like lfortran in jupyter which I imagine might allow these things to be bundled, although I haven't followed that effort as of late.

        • pklausler 2 hours ago
          What language does have built-in plotting capabilities that don't depend on external libraries?
          • dgacmu 2 hours ago
            Language vs system with a language?

            Mathematica, matlab, maple, octave, etc.

  • criddell 4 hours ago
    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.
    • cultofmetatron 2 hours ago
      if you're smart enough to learn fortran and learn to impliment and undersatnd numerical methods in it, I would argue that learning python will be an afterthought. You can learn python along with numpy in a week tops if you already understand the theory. I believe a lot of numpy libs are written in fortran code anyway though I could certainly be wrong there.
      • esafak 46 minutes ago
        Why learn Fortran? Let it die already.
  • tomrod 4 hours ago
    Fortran, Octave, or Julia are excellent for learning linear algebra.

    This was the path I took, before going to Python, Go, and Rust.

  • dkga 2 hours ago
    I personally think R and Julia are much better at this.
  • veqq 3 hours ago
    APL is better, obviously. There are even dozens of textbooks for teaching math with its notation.
    • flint 47 minutes ago
      I was going to mention APL, then decided to scroll through the discussion.
  • GhosT078 1 hour ago
    Ada is also excellent for linear algebra and other numerical programming.
  • stathibus 5 hours ago
    If you are unwilling to teach through python's warts you should use Matlab, not fortran.
    • dubya 5 hours ago
      I’d suggest Octave over Matlab, because current Matlab has tons of distracting AI and autocomplete front and center. Probably really helpful for getting a plot just right or implementing an algorithm from a paper, but not so good for learning the basics.
    • goerz 5 hours ago
      Even better: Julia (although Fortran is pretty good!)
      • adgjlsfhk1 4 hours ago
        I translated the jacobi example to julia, and it does seem to address every one of his gripes with Python.
      • QuadmasterXLII 4 hours ago
        I love julia, but the default workflow is

        Step 1) Write the function using high level abstractions Step 2) Glance over the generated assembly and make sure that it vectorized the way you wanted.

        • mofeing 4 hours ago
          > Glance over the generated assembly and make sure that it vectorized the way you wanted.

          Isn't that sth you would also need to do in Fortran? IMO Julia makes this so easy with its `@code_*` macros and is one of the main reasons why I use it.

          • wtcactus 4 hours ago
            In my experience, Fortran compiler is heavily optimized. It competes head to head with C.

            Julia’s on the other hand, many times puts out very unoptimized code.

            Mind you, last time I looked at Julia was 2-3 years ago, maybe things have changed.

            • patagurbon 2 hours ago
              If you write Julia similar to Fortran, with explicit argument types and for loops and avoiding allocations it shouldn’t be too far off. Fortran IIRC has a few semantics which might make it more optimal in a few cases like aliasing

              But indeed there are almost certainly less performance surprises in Fortran

    • a-dub 4 hours ago
      this is the way. octave or matlab.

      people like to complain about matlab as a programming language but if you're using it that way you're doing it wrong.

      matlab (the core language) is awesome for expressing matrices and vectors and their operations as well as visualizing the results. matrix expressions in matlab look almost identical to how they look in mathematical notation (or how one might write them in an email). you shouldn't be using programming language flow control (or any of the other programming language features), you should be learning how to write for loops as vector and matrix operations and learning from the excellent toolboxes.

      • OkayPhysicist 1 hour ago
        IMO, the issue is that "Scientific computing" covers several disparate use cases.

        When you care about the math, Mathematica. It's a replacement for several pages of hand-written math, or a chalkboard.

        When you care about the result, MatLab. It's a replacement for your calculator, and maybe Excel.

        When you care about the resulting software? Python/Julia/Fortran.

    • kergonath 4 hours ago
      Fortran is much more approachable and more regular than Matlab. Really, there’s no contest.
  • randomNumber7 3 hours ago
    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.
  • QuadmasterXLII 4 hours ago
    Am I crazy or is the Jacobi iteration flipping the sign of u every iteration?

    Also the swapping of u and tmp doesn't work like that in python. Might in fortran.

  • Bostonian 6 hours ago
    A follow-up post is https://loiseaujc.github.io/posts/blog-title/jacobi_experime... "Jacobi method: From a naïve implementation to a modern Fortran multithreaded one".
  • constantcrying 3 hours ago
    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.
    • wombatpm 1 hour ago
      You would think. I was a TA for numerical methods for undergrad engineers. Saw lots of bright students who understood the material but could debug their code. Several grad students started a 1credit seminar course on Fortran fundamentals. We worked those students like dogs, but when they took the numerical methods course they came back and thanked us because they knew how to get their code to compile and how to use the admin graphics package.
  • toolslive 2 hours ago
    > No off-by-one error – By default, Fortran uses a 1-based indexing. No off-by-one errors, period.

    I'm with Dijkstra on this one. https://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831...