
The new features of Fortran 2018 [pdf] - Tomte
https://isotc.iso.org/livelink/livelink?func=ll&objId=19441669&objAction=Open
======
thanatropism
Modern FORTRAN looks more like Matlab than FORTRAN 77. The syntax has been
completely overhauled since at least ‘95.

For a while I was translating my Matlab codes to FORTRAN; it was surprisingly
easy. But I was being too naive with array resizings in Matlab and most of the
speed gain (which was like 2-3 orders of magnitude) could be achieved in
Matlab itself by preallocating memory.

To this day I have the nervous tick of initializing arrays with zeros even in
numpy.

~~~
whatshisface
> _To this day I have the nervous tick of initializing arrays with zeros even
> in numpy._

The typical way to create arrays in Numpy is with `np.zeros(size)`. What is it
that you're doing?

~~~
pithon
Note there's also `np.empty(size)` if you know you're going to initialize all
the values in a later step, in which case it can skip assigning zeros to every
element.

------
jsty
Fortran users of HN - what are the best resources (online / books / ...) to
pick up Fortran in 2019? Are there any open source codebases you'd consider as
good to read through?

~~~
dionysus8
Modern Fortran by Milan Curcic seems to be a pretty good book.

[https://www.manning.com/books/modern-
fortran](https://www.manning.com/books/modern-fortran)

Most other ‘modern fortran’ books assume you have knowledge of older fortran
versions.

~~~
acqq
Thanks! "Publication in Fall 2019 (estimated)" at the moment: "8 of 13
chapters available"

Table of Contents and samples on the author's site:

[https://milancurcic.com/book/](https://milancurcic.com/book/)

Here's author's recent series of articles "Analyzing stock price time series
with modern Fortran":

[https://milancurcic.com/2018/11/06/analyzing-stock-price-
tim...](https://milancurcic.com/2018/11/06/analyzing-stock-price-time-series-
with-modern-fortran-part1.html)

------
GnarfGnarf
Ahhh... FORTRAN -- my first language: CDC 3100, 1965. What magic.

~~~
fsagx
FORTRAN77 on a VAXCluster in 1986.

Still have my copy of "FORTRAN 77 For Engineers and Scientists" just in case.

It was very easy to pick up for someone who had only used AppleII or TRS-80
BASIC.

~~~
waynecochran
I used to have Fortran77 notepad for hand writing code — later I would type it
in. Always began in the 8th column if I remember right?

~~~
username223
Yep -- old-school fixed-format Fortran had one column for the "c"(omment)
marker, seven for the statement number (maybe 5 plus spaces on either side?),
then 72 for the code before you fell off the end of the punch card.

~~~
drfuchs
No, you get all 7 spaces for the statement number; live it up a little!

Don't know if it's still the case, but in FORTRAN IV you don't need spaces
between keywords and variable names. So when the compiler sees "FORI=2" it has
to look still further ahead to decide if this is a for-loop (FORI=2TO9DO) or
an assignment to a variable named FORI. Decidedly not a context-free grammar;
you can't even figure out the tokens without the ad-hoc parser getting
involved.

~~~
gnufx
No. In fixed format form, statement numbers are columns 1-5. "FORI=2TO9DO" is
an unclassifiable statement; try "DOII=...".

~~~
drfuchs
You’re right! I was remembering columns 73-80 reserved for “card number”.

------
fanf2
The most notable thing I spotted is they have deleted the arithmetic IF from
the language, which must be one of the more characteristic features of classic
FORTRAN.

~~~
whitten
I agree. The non intuitive reason stated is that there is a standard that
specifies a sign for zero, and numeric IF doesn't distinguish between them,
and it depends upon labels which are hard to optimize.

Another notable capability is that procedures default to recursive and there
is a way to state they are non_recursive.

------
bberrry
What's the degree of backward compatibility with FORTRAN releases? I imagine
most FORTRAN codebases as being huge and old, so it makes me wonder how many
can adopt the latest versions.

~~~
jhrmnn
Each new standard usually removes a very small number of features, but Fortran
2018 is mostly a superset of Fortran 77. Most compilers retain absolute
backward compatibility, so they can compile a superset of Fortran 66 to 2018,
and often some custom language extensions on top.

~~~
walshemj
Only some of the real ancient pre FORTRAN IV stuff has been removed.

------
cfcf14
I've been really interested in learning Fortran for a while- I work doing a
lot of computational stats/ML and typically my tools are python, R, or Golang.
Is there any use-case for Fortran in production settings or should I just
accept it would be purely a personal satisfaction project?

~~~
4thaccount
It's very fast and there is a new Manning book about to come out on Modern
Fortran that is all about parallel Fortran.

In addition to being fast, I find it considerably easier to read than C++ as
it isn't as low level and doesn't have as much noise (at least the later
versions like Fortran 90).

It also makes writing numerical code easy as it was truly built for high
performance scientific computing.

A lot of older scientific projects run on Fortran and although I know some
projects that were migrated to C++, it wasn't due to any defect from the
language besides it not being taught very often in colleges now outside of
some astrophysics classes where it was once a mainstay in engineering and
science curriculums.

There are several compilers available, but a lot of them are commercial and
some are expensive. There are free versions as well of course.

~~~
eru
Though the main reason (for a while) that Fortran compilers could produce
faster code was that they were allowed to assume that variables (including
arguments to your functions) don't alias each other.

See
[http://beza1e1.tuxen.de/articles/faster_than_C.html](http://beza1e1.tuxen.de/articles/faster_than_C.html)

~~~
Ragib_Zaman
I don't understand the "Though" part of this. The only reason any compiled
language may be faster than another is because a compiler knows/assumes more
about the code (either through users specification, or restrictions of the
language).

~~~
eru
Yes. That's the remaining reason when compilers for the languages in question
have gotten as good as they can get.

------
tkdc926
WATFOR anyone? My first programming language in college. Spring 1969.
[https://dl.acm.org/citation.cfm?id=363059](https://dl.acm.org/citation.cfm?id=363059)

~~~
cicero
I used WATFIV in 1982.

------
damian2000
Fortran 77 was the language I used in my first job in 92 on DOS and Unix.
Can't see the benefits over other languages like C, Go, Python though. Unless
you've got some specific high performance floating point ops requirements?

~~~
username223
Quite a few scientists and engineers have those requirements. I wouldn't
choose it for writing a web server or text processing, but Fortran is actually
a pretty nice language for dealing with numbers and arrays. It also has
decades' worth of well-tested numerical libraries, which can be very subtle
and hard to get right.

~~~
eru
Thanks to the magic of computer science, we can package up a lot of those
libraries for use with other languages as well.

~~~
username223
Sort of, but we haven't figured out how to make language boundaries disappear.
For example, row- vs. column-major ordering of arrays is an eternal pain when
communicating between C and Fortran.

Numpy, R, Matlab, etc. are good scripting languages for a lot of Fortran, but
if you ever need to peek under the hood...

~~~
pjmlp
Not in C++, thanks to the power of user defined types.

------
jpincheira
I just love it that Fortran is #1 on the front page.

