We should have a tutorial how to use strings in Fortran. I used to struggle with that a lot too. And still do a bit.
The solution is to have a compiler option that would warn if you declare a variable as Am and use it as am and vice versa. That way it’s easy to enforce in your team.
Again, I think should be possible to implement in a compiler.
Will take some time to fix, but it will get fixed with GFortran, Flang and LFortran.
Can you be specific what you mean by “quirks of traditional mode”? We’ll have to support the C preprocessor in LFortran, but it poses all kinds of challenges, such as how to format the code automatically, since the preprocessor is run before the parser, so it is not part of the AST that is used for formatting.
I half-remember a conversation on comp.lang.fortran that the % sign was chosen to avoid clashing with DEC structure/record extensions that use . for selecting fields. I don’t remember the technical reasons for why derived types could not use the same syntax.
Intel Fortran does this with the -warn:interface option, so that for the codes
function twice(x) result(y)
real, intent(in) :: x
real :: y
y = 2*x
end function twice
program main
print*,twice(2.1d0)
end program main
you get
c:\fortran\test>ifort -nologo -warn:interface twice_single.f90 xtry_twice.f90
xtry_twice.f90(2): error #6633: The type of the actual argument differs from the type of the dummy argument. [2.1D0]
print*,twice(2.1d0)
-------------^
compilation aborted for xtry_twice.f90 (code 1)
I believe the big problem was that Fortran 90 also allowed user defined operators with the syntax:
operator-name : “.” name “.”
so that expressions like
… an_id .cross. another_id …
can be ambiguous. The “DEC” extension was defined before user defined operators were available, and originally only had to deal with a few ambiguities, e.g., .OR., .AND., .LT., … Note also that most “DEC” extensions actually originated in other compilers. I believe that this extension, in particular, originated in Livermore’s Fortran compiler where it was used along with “DEC” pointers to write operating systems for super computers.
Despite emphatically disliking %, I’m not sure that . is the best thing to replace it with for the aforementioned reasons. While I’d definitely be in favor of something else being added to the language standard, I’m unsure about the wisdom of making a compiler-specific extension for a purely aesthetic issue (note unsure, not categorically against).
But with that said, I’d be curious to hear any other ideas people have about alternatives to both % and .? I like -> from C, personally. There are also unicode symbols like → that could be added as optional, without any risk of breaking existing language features (but that said I know nothing about the status of unicode in Fortran source files or even in strings for that matter).
I like -> also. In C and C++, that means the variable on the left is a pointer. In Fortran this is unspecified, but it might very well be a pointer underneath (depending on the compiler), so -> is actually very natural to use. I added it to the above issue.
Self-documenting-code features (naming constructs, associate construct, intent(in/out)
– These features, including the necessity of including all variable definitions at the top of subroutines/programs, seems oddly verbose. However, as a programmer who sometimes has to dive into a large Fortran codebase but who doesn’t want to know the entire codebase, these idiosyncrasies of the language are immensely helpful. Not saying I see large codebases use associate or name constructs, but I personally plan to if I ever make larger codebases.
Native multidimensional array support
Simple language but fast and robust (with recursion, modules, derived types, interfaces, etc)
Least favorite:
Writing to file in binary; the format isn’t specified enough and so one has to use an external library for cross-platform file communication. My ideal would be an intrinsic numpy-like easy interface for saving multidimensional arrays compactly, that is guaranteed to be readable by any standard-compliant Fortran compiler.
In the interests of balance I like % and don’t see any point in trying to change it for something else. Using ‘.’ instead (on compilers that support it) causes strange compiler problems when making method calls inside compound ‘if’ statements.
Favourite:
native array support
structure (modules / submodules)
oo
Least favourite:
the amount of code that has to be written to get round the lack of templates
the general verbosity - I’d much prefer to declare a dummy variable where it’s used (like C++) than having to give it a line at the top of the procedure
not really the fault of the language but the lack of a decent IDE on all platforms can be a real problem, perhaps a tutorial on the options somewhere?
Native support for matrices (I mean automatic arrays in particular; allocatable arrays are OK but automatic arrays are closer to mathematics).
Intrinsic support for matrix/vector operations: matrix addition/multiplication, transpose, slicing, broadcasting, …; without such intrinsic functionalities, a language should not be called a “formula translator”.
High performance.
Least favorite (sorry, I have more than three):
The robustness and performance of automatic arrays and intrinsic matrix/vector operations can still be improved (largely).
Speaking about robustness, automatic arrays and intrinsic matrix/vector operations can lead to stack overflows (segfaults) under the default settings of some major compilers; this kind of major failure seems to be weirdly permitted by the Fortran community (e.g., see this 13-year old report to Intel and the latest experiment reproducing the same failure); this is unimaginable in other popular languages with the same functionalities, e.g., MATLAB/Python/R/Julia, unless you are encountering a bug that has to be fixed.
As for performance, the intrinsic matrix/vector operations in Fortran normally cannot achieve the same performance as the intrinsic matrix/vector operations in MATLAB under default settings unless you are capable enough to make your compiler link to the correct library, which may be nontrivial as discussed in another post on this discourse. I know, MATLAB achieves high performance only because of the Fortran code underneath, but it is difficult to understand why Fortran itself does not optimize its intrinsic matrix/vector operations (under the default settings, without the need for particular options) in the same way.
As mentioned in many posts above, the native support for matrices (arrays) and matrix/vector operations is one of the core strengths of Fortran. I do not see any reason why the community should be indifferent to its robustness and performance in this regard.
Lack of support for functions with multiple returns. True, we have subroutines that can return arbitrarily many results, but functions are less error-prone and often more intuitive.
Lack of interactivity. Fortunately, LFortran @certik is solving this problem.
With the ability to return a scalar derived type or an array of derived types, possibly allocatable, Fortran functions are already pretty flexible, although returning multiple values would be nice.
Favourite thing that I don’t think was already mentioned: complex arithmetic as part of the language rather than a library having to be fetched, with many complex intrinsic functions (though I had to roll my own for some that have real but not complex intrinsics)
Least favourite: nncarlson complained of no reliable free compiler. My experience of reporting over 100 compiler bugs is that free and commercial compilers have both had bugs, but gfortran fixed them faster. Once I complained about a commercial compiler’s bug and was told the standard was ambiguous; the next version of the standard removed the ambiguity.
My least favorite feature about Fortran is that the linker has not been defined in the standard, especially a minimum functionality.
I think that INTERFACE should be automatic and reviewed at the link stage, especially for the count of subroutine and function arguments. The report should not be errors, but warnings that can be over-ruled, as in the case of F77 wrappers with mixed variable types.
This is actually available in the NAG Fortran compiler. It will produce an error if any argument mismatch is found, the check is actually global to all files linked. GFortran has a similar feature since version 10, limited to a single file.