Fortran in 100 Seconds

YouTube video just posted here at the Fireship channel, which has 1.36e6 subscribers. In 3 hours, the video already has 42K views, 5K likes, and 300+ comments.

Topics Covered

  • History of Programming Languages
  • When was Fortran invented?
  • Who created Fortran
  • Is Fortran still used?
  • Fortran basics tutorial
  • What is Fortran used for?

The author uses the .f95 extension for the short code presented, unfortunately (better is .f90 to signify free source form). He spends some time explaining implicit typing and the need for implicit none. Removing implicit typing has been much discussed here. The language is spelled FORTRAN in the video title. I wish he had mentioned that modern Fortran has array operations, like Matlab.

I discussed the author’s other videos here.

11 Likes

I guess us releasing today v3.1.0 of Modern Fortran for VS Code was appropriately timed!

3 Likes

I personally prefer .f95, any reason why .f90 is better?

My reasons are given in the thread Is there a "standard" file suffix for modern Fortran code?

2 Likes

It seems that among the Fortran compilers only ifort does not recognize the .f95 file extension, but this issue can be easily handled:
Switch to allow ifort v8.0 to recognise *.f95 files - Intel Communities.

As such, I guess there is no problem using the .f95 file extension.

The only problem with that video is… the 100 seconds. You can only scratch the very tip of the iceberg, and that only by speaking as fast as he does in the video. Inevitably, the past of the language takes over the majority of the extremely limited time available, since Fortran has a long history and you can’t just skip that.
Nevertheless the fact this video got many views and likes that fast is refreshing. And perhaps the fact it’s that short helped some people to a least hear about the reason terms like “high level programming language” and “compiler” were invented.

As for the file extension, I recently reluctantly adopted .f90 realizing the fact changing suffix every time a new standard is released leads nowhere, and .f90 is the de facto standard nowadays.

2 Likes

Maybe the author is used to Python where one may define and use variables «on the fly», but the example to loop with

program myApp

   implicit none

   do n = 1, 10
      doubled = n*2
      print *, doubled
   end do

end program myApp

won’t work.

loops

1 Like

It should work correctly, but that thread explains why it’s not a great idea. As does the one linked by @Beliavsky.

1 Like

Regarding file name extensions, in hindsight it is unfortunate that the chosen terms “fixed” and “free” both start with “f”. As is, an extension like *.ff is somewhat ambiguous. If they had used some other synonyms for these, like “structured” and “unstructured”, then extensions like *.sf and *.uf might have worked. Ironically, the “free” form source code has more constraints on the programmer than the fixed form. Namely, spaces are required in many contexts in free form, keywords cannot have embedded spaces (with a few exceptions like enddo, endif, etc.) and literal constants cannot have spaces (1 234 567 890). In fixed form none of those constraints apply, and there is instead the column fields 1-5, 6, 7-72, 73-80 that have special meaning.

However, given the history and usage in the language, *.f and *.f90 seem adequate.

It is unfortunate that the video uses *.f95, which is mostly just confusing since there have been numerous language revisions since the 1995 standard, no one really programs using the f95 standard anyway, and actual usage of the *.f95 extension is rare.

2 Likes

No, it won’t work due to implicit none.

What does implicit none have to do with using .f95 as the file extension?

No, the problem is not with .f95 file extension, but implicit none forcing you to declare integer :: n, doubled, which is why the sample code wouldn’t work. Unless implicit none is removed, then n is automatically an integer type, and doubled is automatically real type.

Edit: just realized I meant to reply to Fortran in 100 Seconds - #7 by nbehrnd instead of your comment Fortran in 100 Seconds - #8 by ashe , my bad

If only the Fortran standard can eliminate implicit mapping, the IMPLICIT NONE would no longer be necessary for safe coding.

There will be no need to bring up the legacy of integer types with I-N, etc. and

10+ seconds can be better utilized in such a 100 second “elevator pitch” to tout the better features of Fortran. Alas …

Sigh :anguished:

1 Like

Of course, in such a brief video, only little can be shown. It is an appetizer for the language in general and not a class like e.g., the by Derek Banas. Though one may argue if the video caption already links to fortranwiki, an additional (prominent) link to fortran-lang.org or an additional slide with points of entry to the language were beneficial. Some of the commenters of the video indeed mention interest or/and a need to learn Fortran.

Yet regardless how constraint the examples advertising a language are, they must represent a benefit for the interested; else, they likely move on to the next. E.g. (with cheerful smile), a vim cup

vim_mug

(image credit to zazzle.com)

For examples depicting code, my anticipations are that

  1. these work when applied verbatim just as one is asked to provide a MWE addressing a question in a discussion. So not something like Amazon’s Fortran notebook mentioned earlier by Ivan (here). At present, the do loop in the short video does not meet this criterion.

  2. that they reflect contemporary custom e.g., in terms of the syntax. Once some insight is accumulated, on still can gain additional one by looking into earlier approaches, learn to read and maintain source code inherited. Possibly because Fortran provides better backward compatibility across standards than e.g., Python 2 vs. Python 3, there still are beginner classes teaching Fortran as FORTRAN 77:

    (screen photos of an ongoing class 2021/2022 by Redha Aouati (University of Constantine, Algérie); uploaded April 2022 to youtube).

Anticipations don’t always match realizations.

I’ve left a comment tor the creator to use an example that works and one that conveys a tad more in order to make it worth the ~10 seconds it takes up, sure to be ignored is the following:

   integer :: n
   do n = 1, 10
      ! Factorial of n
      print "(i2,'! = ',g0)", n, product([( i, integer :: i=1,n )])
   end do
end
2 Likes

Is this implied do loop correct? I couldn’t run it on GFortran. If it is correct, then I am confused because I thought all variables need to be declared in the beginning. Also, does implicit saving apply here?

Yes, starting Fortran 2018 revision, the implied-do-control where the construction of arrays are involved can be

[ integer-type-spec :: ] ac-do-variable = scalar-int-expr , scalar-int-expr [ , scalar-int-expr ]

With implied-do in DO CONCURRENT, array construction, FORALL and DATA statements, the scope of the construct or the statement is what applies to the index (or the indices). The type-spec of the index or indices can thus accompany those constructs / statements.

Note no implied SAVE comes into play with the declaration of such index variables.