Noteworthy differences from Fortran

There is a diversity in the Fortran community. Some people know FORTRAN/Fortran only; To them, the difference is something common to popular dynamic languages (Python, Ruby, R, Matlab, etc) i.e., dynamic typing, interactive usage, packages, etc. If they know some dynamic languages, their interest is how easy numerical coding is possible in Julia. Also, they would be interested in parallel computing performance.

The OP lists more technical details than mental model/way of programming. There are some more examples:

  • Mutable and immutable. Some types are immutable, and it is not intuitive for Fortran programmers. You can’t do str="Fortran"; str[1]='X'. Also, you can’t change the scalar argument of a function because a scalar is immutable.
  • Reference and copy. A variable pointing to another variable is a reference. In Fortran, pointers are not often used. You will be very confused with a=[1,2,3]; b=a; a[1]=100; b[1].
  • Bounds checks and some foolproof options. Julia checks bounds by default. To turn it off, you have to put a macro @inbounds into the code explicitly. Julia has more macros to remove checks or to improve the performance instead of compiler options.
  • Compile at runtime. Very roughly, you can’t save a compiled binary in Julia. The binary is managed by Julia, and the user can’t touch it. The compiled binary is kept in a Julia session, but once Julia exists, the binary will be removed. To avoid the recompilation, make a package to host your programs (and maybe you need PackageCompiler.jl for your purpose).

Besides the details, I think, the difference between Julia and Fortran is in a development model, coding style, and tests. This post is already too long, so I may post these aspects in another post.

EDIT: I added some more details.

  • Macros. Julia can manipulate the code as a data structure before the compilation. A macro provides such a functionality (meta-programming). A macro name starts with a character @.
  • Breaking multiple loops. In Fortran, you can break multiple loops with a labeled-do statement like label: do ... exit label. There is no such built-in in Julia; Instead, you can use @goto and @label macros.
  • Slice or subarray. When you refer to a subarray a[:], Julia always makes a copy of it (even though just look at it). To avoid this, make a view using @view or view().
4 Likes