20 ms·
Fortran is easy to learn
- yjftsjthsd-h 5y agoSo I don't doubt that "modern Fortran" is a nice language, but last I'd heard, it also effectively didn't exist in the wild; Fortran remains king of numerical computation by virtue (largely if not exclusively) of having a vast number of packages already written spanning decades of use... but not, generally, spanning to new versions of the language. So is it good enough to use the language in spite of its ecosystem?
- trutannus 5y agoFrom the article: > The idea of introductory languages is not necessarily that they are suited to commercial endeavors, but rather that they are (i) easy to implement algorithm in, (ii) readable, and (iii) do not contain things that will confuse and bewilder.
- Bostonian 5y agoIt's true that many of the famous Fortran libraries such as Lapack are Fortran 77 or close to it. However, there are lots of projects using modern Fortran, especially at universities and national labs, in the areas of astrophysics, computational fluid dynamics, earth science, climate and weather prediction, and electronic structure and quantum chemistry. A list of GitHub Fortran codes by category is at https://github.com/Beliavsky/Fortran-code-on-GitHub https://github.com/Beliavsky/Fortran-code-on-GitHub .
- necheffa 5y agoNo. I write Fortran professionally and it is a real pain in the dick to get anything done. It has some nice SIMD and matrix operation syntactic sugar but that is about it. If you want to get anything useful done you are better off writing in another language. The Fortran ecosystem is running on fumes from the inertia of these massive legacy code bases that no one wants to pay to rewrite. But then complain that it is expensive to get anything done in them.
- m_mueller 5y agoThis surprises me. I wrote a lot of Fortran doing research and found it very strong for numerics. Having first class multidimensional arrays with debuggers being able to understand slicing operators is a nice boost for productivity, because half the time is often spent figuring out why two results don’t agree. The main missing feature was generic functions and that’s where I think Julia brings some real advantages to the table. But SIMD, multicore, MPI and GPU support is afaik. still more mature on Fortran and that’s where it counts when programming cluster applications.
- cbkeller 5y agoI agree with you that Fortran is running on more than just legacy here. At the same time, I also think Julia has caught up a lot as far as SIMD, multicore, MPI and GPU. For SIMD, Chris Elrod's LoopVectorization.jl [1] is an (IMHO) incredibly impressive piece of work (which incidentally provides the foundation for I think the first pure Julia linear algebra library competitive with BLAS). Multithreading is pretty easy with things like `@spawn`/`@sync` and `@threads for` in the base language, as well as super low-overhead multithreading from the Polyester.jl [2] package (which LoopVectorization also uses to provide a version its vectorization macro that'll also multithread your loops in addition to SIMD-vectorizing them). MPI.jl [3] has been totally problem free for me, though I wouldn't be surprised if the Fortran bindings still have an edge somewhere, and Cuda.jl [4] seems to provide pretty seamless GPU support which should play nicely with MPI.jl's Cuda-aware MPI [5], but I don't work as much with GPUs myself. [1] https://github.com/JuliaSIMD/LoopVectorization.jl https://github.com/JuliaSIMD/LoopVectorization.jl [2] https://github.com/JuliaSIMD/Polyester.jl https://github.com/JuliaSIMD/Polyester.jl [3] https://github.com/JuliaParallel/MPI.jl https://github.com/JuliaParallel/MPI.jl [4] https://github.com/JuliaGPU/CUDA.jl https://github.com/JuliaGPU/CUDA.jl [5] https://juliaparallel.github.io/MPI.jl/latest/usage/#CUDA-aware-MPI-support https://juliaparallel.github.io/MPI.jl/latest/usage/#CUDA-aw...
- m_mueller 5y agoWhat about debuggers? For Fortran there are some powerful commercial debuggers available, incl. Parallel debugging and even reverse debugging (being able to step backwards based on snapshots).
- TruffleLabs 5y agoAs for FORTRAN in the wild, there are many simulations used by the US government still in use, example like Enhanced Surface-to-Air Missile Simulation (ESAMS). Would it be a good language to use outside of specialized needs? Probably not.
- yjftsjthsd-h 5y agoI'm not questioning Fortran in the wild, I'm questioning modern Fortran in the wild. Are those simulations Fortran 2008, or FORTRAN 77 that nobody dares touch?
- aragilar 5y agoThere's modern stuff being written in astro(nomy/physics) (I can attest to some of the codebases listed in https://github.com/Beliavsky/Fortran-code-on-GitHub#astrophysics https://github.com/Beliavsky/Fortran-code-on-GitHub#astrophy... being modern, at least in terms of development), but I'd say C++ likely does have the upper hand for newer codebases (unless things have changed dramatically last time I looked, algorithms that don't nicely align with nd-arrays are still painful in Fortran). I've also heard rumours of Julia and even Rust being used (the latter because of the ability to reuse libraries in the browser e.g. for visualisation), but the writers of these codebases (and the Fortran/C/C++/Java) are unusual—Python and R (and for some holdouts, IDL) are what are most people write in (even if those languages call something else).
- pjmlp 5y agoAs much as C11, C++11, Java 11, C# 8, Python 3, and later exist in the wild. After a certain threshold is very hard to get people to move on when the IT managed compilers just work, and coding isn't a full time activity.
- analog31 5y agoA minor quibble: The article leaves out the commands needed to actually run the program. Also, just for grins, the first language I learned: 10 INPUT "Height above sea level(m)", H 20 D=SQR(2*6367.45*(h/1000.0) 30 PRINT "Distance to horizon", D RUN
- HWR_14 5y agoMinor quibble: You omit units from the output.
- bobochan 5y agoYes, if you read the first Dartmouth BASIC documentation you immediately understand that Kurtz and Kemeny were designing a language that students could teach themselves, with the goal of them being able to transition to Fortran.
- analog31 5y agoAmusingly, my physics and math classes all used FORTRAN, but my teachers were OK with me translating the programs to BASIC so I could run them on my crude MS-DOS computer. I had a copy of the IBM FORTRAN compiler, but it was this cumbersome beast that required two diskettes -- one contained the compiler and the other contained the linker, or something like that. And the complete compile/link workflow took several minutes. BASIC, and then Turbo Pascal, were game changing because you could run a program instantly. BASIC even had crude array math via the MAT statement though I don't recall the details. I got to my senior year, second semester, and had a meeting with my advisor to make sure I had met all of my graduation requirements. He looked at my record and said: "Hey, you were supposed to take a programming class. But you know how to program, don't you?" I said yes. He checked the box to waive that requirement for me. Then I started breathing again.
- zozbot234 5y agoOne nice thing about the INPUT facility in BASIC is that it's truly designed for interactive use out-of-the-box and does its own error recovery on inputs that are incomplete or fail to parse. With other languages (FORTRAN, C/C++) you generally have to implement that part manually.
- yosito 5y agoThere's still some cryptic stuff in the Fortran example. I don't know what (*,*) or :: mean. It's even more cryptic than printf or chomp or float.
- Bostonian 5y agowrite (*,*) "hi" means write to standard output (the first asterisk) using a default format (the second asterisk) chosen by the compiler. I agree it's a bit obscure. An alternative is print*,"hi" The :: just separates the type of variable from the variable names. The code shown compiles and runs the same if the :: is removed, but there are cases where the :: is needed.
- wk_end 5y agoIt's not clear to me that, once you explain all this, you end up saving any time vs. the Python version. And once your students want to do anything besides "read a number and perform a simple calculation on it", Python is likely to start winning out very rapidly.
- wumpus 5y agoI don't think the point was to score which language was best.
- TruffleLabs 5y agoMy FORTRAN 77 experience in college also included the control lines in the file to have the operating system of the CDC Cyber 172/6600 (a hybrid of two Control Data Corporation super computer/mainframe). The first lines of the file outlined the account submitting the file, where the input & output would be, and some other items to just make the compile/run happen.
- jmclnx 5y agoThat is what I learned FORTRAN on too, a CDC cyber something (a year earlier). I do not even remember what happened to my text book for that class. And my first job was in FORTRAN a year later (which I messed up royally). As someone else mentioned, I have been thinking of getting back into FORTRAN.
- kristianpaul 5y agoIs it easy to remember?
- deleted 5y ago[deleted]
- djur 5y agoIgnoring the presence of "(*, *)" in the Fortran program -- which is the equivalent of all of the format string and type complexities in the C, Python, and Julia programs -- is a serious deficiency of the argument here. As soon as you start writing something more complicated than Hello World: The Sequel, those complexities become something that language learners need to engage with.
- hpcjoe 5y agoAgreed. I'm a (very) long time Fortran user, and a more recent C, Python, and Julia user. I'd agree that scanf is a pain. The chomping/parsing bit can be, in all cases, hidden behind a convenience function, which if you like, you can name "read". FWIW, I've been using Fortran since the mid 1980s, C from the mid 90s, Python from the mid 00s, and Julia since 2012 or so. All of these languages are fine for the example provided, and all are understandable. Each of these languages require some minimal boilerplate around the core algorithm to make it work. Specifics of input and output mechanisms would be language/dialect specific. Really, each of them is fine for this trivial example. Its when you start getting into serious translation of the underlying math into something the language will understand, that the real difference stand out. That's when both Fortran and Julia stand out. Both are designed to make this process as painless as possible. Fortran was designed and built almost 70 years ago. IO was very painful then, and while the language itself is very simple and easy to understand, the IO system is still quite similar to the early days. The "(,)" notation combines units (file descriptors), and formatting. It is not different in intent than the scanf and other functions. Why Fortran and Julia are so easy to use comes from the expressiveness of the language, the simple mechanism of writing code that looks close to the formulae in question. There is no fiddling with array indexing that doesn't start where the formula indicates. No allocating arrays of arrays to build matrices. That is, it is simple to go from conception to working code very quickly. In a manner that really does look like the way you would do it on paper. That's why Fortran is still in use, and growing. And why Julia is catching on quickly.
- wilbdhm 5y ago> Why Fortran and Julia are so easy to use comes from the expressiveness of the language, the simple mechanism of writing code that looks close to the formulae in question Why would it not in any other languages?
- liveranga 5y agoFortran seems to be undergoing a minor renaissance at the moment. Modern Fortran is a fun read and the FPM tool is an attempt at creating an ecosystem similar to cargo for Rust. * https://www.manning.com/books/modern-fortran * https://fpm.fortran-lang.org/en/index.html
- pjmlp 5y agoUntil recently the best Fortran compilers were proprietary, I guess having gfortran catching up and those adopting LLVM not wanting to be left behind has helped.
- gnufx 5y agoThat may depend on what you mean by "best". GNU Fortran has always been portable and generally decently competitive with proprietary ones speed-wise over the years and architectures. Also often more reliable. I wish it got properly funded.
- pjmlp 5y agoThe best buck for money on HPC clusters, those supercomputers using Intel and IBM proprietary compilers, which are now based on LLVM on more recent versions, thus also need to support Fortran to finish the toolchain transition.
- gnufx 5y agoI thought in the past was at issue. Anyway if you mean "bang for money", GCC is usually zero money, and is more reliable in my experience of research computing support. I've had long experience measuring its output. Fairly recently I ran the Polyhedron Fortran benchmarks, which seemed to be used to market proprietary compilers. In the bottom line, gfortran was essentially equal to ifort (then-current releases and roughly equivalent options on SKX). It's infinitely faster than ifort on ARM and POWER, of course. I could have improved the results for gfortran by individual attention to the codes (some of which were somewhat broken anyway). In HPC the quality of compiled code, within reason, often isn't actually the bottleneck anyway.
- orange_joe 5y agoI feel like this post is full of details papered over to prove its point. Others have brought up the fortran details, and with an extremely limited knowledge of fortran, I'll focus on a python detail. You absolutely doesn't need an import statement to perform a sqrt, as you can raise a number to a fractional exponent ( sqrt(x) = x * (1/2)).
- twobitshifter 5y agox ** (1/2) You mean, and one could make a point about that being a non-standard way of raising exponents for a complete novice
- kragen 5y agoIn Python 2 you have to use x**(1/2.0) unless you from __future__ import division.
- wk_end 5y agoI believe that in Python 1.3 you have to use pow(x, 1/2.0), but that's hardly relevant.
- kragen 5y agoThere are several orders of magnitude more people using Python 2 than Python 1.3.
- wk_end 5y agoPython 2.7 is 12 years old at this point. Twelve years! That's the difference between Windows XP and Windows 2.1. It's completely unsupported software. There may be people still using it (sadly, embarrassingly), but anyone choosing to teach it to new programmers - what this article is about - is sabotaging them. Its quirks are irrelevant here.
- kragen 5y ago
- travisgriggs 5y agoFortran, my first real language. I haven’t looked at any since 1993. I wrote whole interactive term screen engineering tools with it. I had a whole system/scheme for how I did line numbering (3xxx for formats, 2xxx for gotos, etc). Some of what I cobbled together is still being used for nuclear fuel assembly design work flow. I have no idea which year’s flavor of Fortran is shown… are implicit variable types based on what letter the variable starts with still a thing? I notice the “real :: …” in the listing… I thought it was kind of quaint feature as I started learning “real languages” after that. All these years later, I kinda thinks it’s clever/original now.
- BeetleB 5y agoFirst: Very convenient to provide a numerical program to showcase. Mainly: > Certainly things like I/O are still problematic for the novice programmer in these languages. Poor I/O basically killed my interest in programming in most languages when I was a novice. BASIC was great for this. QuickBasic was, and probably still is king. People new to programming want to do fun stuff, and it's very hard to do without I/O. Me and most of my peers spent a fair amount of their hobby programming writing very simple games, or doing fun graphics stuff (drawing lines, circles, etc). After doing this for a while in BASIC and QB, "serious" languages like C/C++ were pure Hell. I could literally do none of the cool things I used to with only a rudimentary command of the language. Did not know about Perl/Python until much later. In my opinion, if you want learning languages to be fun, provide one where: - Text I/O are no-brainers - You can easily respond to keypresses (i.e. detecting if a button was pressed and not having to wait till the user hits Enter). - Rudimentary graphics: Plotting a point, drawing a line and circle. Coloring it as desired. - Easy way to generate random numbers. Teach people these things, and they can have a lot of fun with loops, conditionals, and functions.
- gurjeet 5y agoSomething tells me you have more ideas on how to make a language or programming environment more welcoming, and less intimidating for new learners. Please go on :-)
- BeetleB 5y agoNever thought of it beyond what I wrote - mostly voicing my own personal frustrations with learning languages. I finally had to learn C/C++ in university, and was quite good at it, but avoided programming until I learned Perl some years later. I do think that if one is an engineering student (not necessarily CS/CompE), then it's more useful to teach how to do useful stuff (e.g. automation) in languages like Python. In my day most schools used either C/C++ or Java - both of which are not very useful for people whose primary job is not coding. Engineering students would take that one course and that's it. However, I suspect most engineers will benefit greatly if they knew Python. Lots of tedious stuff to automate. Even if the introductory course uses Python, I think they should cover useful tasks for automation - handling directories, and perhaps some basic network related stuff via requests. If you can't squeeze it into one course, make another one and make it mandatory. It'll be more useful than many engineering courses they'll take.
- longemen3000 5y agoThere is a very useful function in Julia, named Base.prompt (I don't remember if it's exported or not, but better be safe height_str=Base.prompt("Height above sea level(m): ") height =Parse(Float64, height_str)
- sundarurfriend 5y agoTIL! I wonder why it isn't exported. There's also apparently a `Base.getpass`, that doesn't echo the entered characters and returns a `SecretBuffer`.
- dandotway 5y agoAncient FORTRAN, as opposed to complicated modern Fortran/C++/Rust, has a huge advantage if you ever crash your spaceship on a resource rich alien world and have to build a programmable computer from scratch from first principles using only knowledge that a single human could memorize. Modern languages require nontrivial compiler theory to parse a sequence of language symbols into an Abstract Syntax Tree (AST), etc. But Ancient FORTRAN is essentially designed to be read in and translated just a few 80 column punch card lines at a time, much like assembly languages. Compilers were written that could fit inside computers with only a few thousand words of 16 or 18 bit memory. Magnetic Core memory from that era was often made by hand, by little old ladies weaving it in factories I've been told, and was used for the Apollo moon spacecraft and was extremely reliable: https://en.wikipedia.org/wiki/Magnetic-core_memory Ancient LISP and BASIC variants also stand out in this regard of not requiring you to undergo years of training and theory to implement and fully understand. Fabrice Bellard's minimalist but complete quickjs.c Javascript interpreter is presently about 54,000 lines of C: https://github.com/bellard/quickjs/blob/master/quickjs.c Javascript is an enormous, complicated, designed-by-committee language, as are essentially all other languages we are forced to use. I do hope there is a renaissance of simpler technology, technology not driven by competitive egos but by a desire for the joy of simplicity and understanding. But such simpler technology won't be useful for building backend infra for Big AdTech ad-bidding exchanges so that we can be bombarded with ads for One Weird Trick to burn belly fat or whatever.
- aap_ 5y agoI would disagree on that. Parsing theory made it easier to write parsers, not harder. Separating the process into lexical and syntactic analysis makes for a much clearer structure than some ad-hoc parser. And writing a recursive descent parser for a language with an appropriate grammar is not hard and can be quite enjoyable.
- jstimpfle 5y agoI don't think recursive decent parsers is what people think of when it's about "parsing theory". In my mind the theory is more about classifying arbitrary languages that were not necessarily designed to be easily parsed by machines, and about models to parse them nevertheless. If you write a recursive descent parser, you're probably parsing a language that was explicitly designed to be parsed with straightforward code, and that can mean the language is compromising on brevity and expressivity sometimes.
- npalli 5y agoNot sure why the Fortran code is that much simpler, I mean if you don't want to futz around with the IO stuff, C++ can be lot more straightforward. #include <iostream> int main(void) { float height, dist; std::cout << "Height above sea level(m): "; std::cin >> height; dist = sqrt(2*6367.45*(height/1000.0)); std::cout << "Distance to Horizon " << dist << " km\n"; return 0; }
- deleted 5y ago[deleted]
- BruceEel 5y agoHave always been intrigued by Fortran but never made an effort to learn it. I do get the article's point about easy text I/O, but what about data structures? I have a hobby project I'd like to port (from PHP prototype) to a compiled language so, what about things like dynamic arrays, DAG's, associative arrays... would I have a hard time trying to implement/use those in Fortran?
- hatmatrix 5y agoFortran excels in array computation but I was advised against using it for graph structures. I think with Modern Fortran it would be not so onerous go handle, but maybe because good libraries already exist in other languages.
- BruceEel 5y agoThank you, that makes sense indeed. What I'm liking about 'modern' C++ for example, is the ability to populate nested data structures like (std::map containing std::vector containing ojb instances) using literal initializers, in a sort declarative-style programming. Useful especially for testing & prototyping. Rust, OTOH, seems rather intimidating to me.
- IMSAI8080 5y agoTeach those kids properly: perl -e 'print(sqrt(<>*12.7349))'
- mkovach 5y agoFORTRAN is pretty easy to learn. One of my first programming gigs was, basically, writing a CGI program to present scientific reports on an OpenVMS system that used Apache. I had zero to do with the setup and FORTRAN was used because they had license for that compiler. This was the late 90s and it was a FORTRAN 90 compiler. It was fairly easy to learn the language and port the C/Perl/TCL CGI things I normally did. In fact, I ended up writing library much like Don Libes cgi.tcl that was somewhat popular back then. Surprisingly one of my favorite data projects (https://retrosheet.org https://retrosheet.org) has tools that will output data in a format that makes it really easy to read in FORTRAN. So, I still use it quite a bit to do some heavy lifting with my baseball research.
- ChrisRackauckas 5y agoI would say Fortran is a pretty great language for teaching beginners in numerical analysis courses. The only issue I have with it is that, similar to using C+MPI (which is what I first learned with, well after a bit of Java), the students don't tend to learn how to go "higher level". You teach them how to write a three loop matrix-matrix multiplication, but the next thing you should teach is how to use higher level BLAS tools and why that will outperform the 3-loop form. But Fortran then becomes very cumbersome (`dgemm` etc.) so students continue to write simple loops and simple algorithms where they shouldn't. A first numerical analysis course should teach simple algorithms AND why the simple algorithms are not good, but a lot of instructors and tools fail to emphasize the second part of that statement. On the other hand, the performance + high level nature of Julia makes it a rather excellent tool for this. In the MIT graduate course 18.337 Parallel Computing and Scientific Machine Learning (https://github.com/mitmath/18337 https://github.com/mitmath/18337) we do precisely that, starting with direct optimization of loops, then moving to linear algebra, ODE solving, and implementing automatic differentiation. I don't think anyone would want to give a homework assignment to implement AD in Fortran, but in Julia you can do that as something shortly after looking at loop performance and SIMD, and that's really something special. Steven Johnson's 18.335 graduate course in Numerical Analysis (https://github.com/mitmath/18335 https://github.com/mitmath/18335) showcases some similar niceties. I really like this demonstration where it starts from scratch with the 3 loops and shows how SIMD and cache-oblivious algorithms build towards BLAS performance, and why most users should ultimately not be writing such loops (https://nbviewer.org/github/mitmath/18335/blob/master/notes/Memory-and-Matrices.ipynb https://nbviewer.org/github/mitmath/18335/blob/master/notes/...) and should instead use the built-in `mul!` in most scenarios. Students should leave the course knowing generally how BLAS is implemented but also how to use it most effectively. There's very few languages where such "start to finish" demonstrations can really be showcased in a nice clear fashion.
- HelloNurse 5y agoFORTRAN is the only programming languages that made me sick. I understand contemporary iterations are more human-friendly, but even COBOL is less ugly.
- nyc111 5y agoIs elisp the simplest? (entered on *scratch*) (setq r 6367.45 h (/ 42.0 1000)) (sqrt (* 2 r h)) 23.12716584452146
- nuker 5y ago"The determined Real Programmer can write FORTRAN programs in any language." That Python example in there :)