-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reclaiming .f
file extension for modern Fortran (free form)
#363
Comments
A comment about the syntax highlighting is that (at least locally), it can be changed without too much effort to still treat |
@certik because the standard is silent on file extensions, I assume that the goal is to influence compiler developers. Recent compiler support surveys by Chivers and Sleightholme track 10 compilers. That seems like a lot of people to influence and therefore a big effort. I imagine it might face less resistance to propose a new extension that's not widely used. One approach might be for the developer community to add support for the new extension in open-source compilers and then get some projects to adopt to the new extension if those projects only care about compiling with the open-source compilers. That might go a long way toward demonstrating to the vendors that the community wants and supports the idea. Some suggestions:
|
@rouson thanks for the comment. This issue is for |
I'm not sure I'd ever expect the compilers to change their default behavior for But if we wanted to invent a new extension, I might go with |
@everythingfunctional to reformulate what you said, we are not leaving the users behind, I can easily imagine we would add a simple option to |
Now that I understand the aim better, this proposal makes more sense -- although I'd still suggest choosing something new rather than overloading something well-established. I have a new suggestion: |
@certik , yeah, that statement was a bit hyperbolic. We do of course want to have an option to revert back to the old ways, if for know other reason than to make the transition easier for users wishing to adapt older code to use I do like @rouson suggestion of |
After spending a whole day filing bug reports due to new compiler and build systems releases, I'm not sure what gain we are expecting by deviating from existing conventions for file extensions. File extensions outside of the range of f and f90 will most likely introduce breakage down the line with either compilers and/or other build systems, which can become hard to debug once fpm allows to automatically export those build files. |
@certik I will consider the cons one by one.
I agree and I like that you correctly mention "by now", i.e. it can be only a transitory confusion
Fair point, but not really a big deal as already explained by @everythingfunctional above in a better way than I could.
I'm not sure that I understand what you mean. I suspect that the real "con" can be understood investigating the cause of such disappointment.
I think this is a "pro" 😄 Please let me explain. If I am not wrong, one of the main motivations to start I think that @awvwgk's experience in the comment above reinforces some of these points. |
However, as the originator of the idea, I would like to point out that my aspiration is broader than "just" reclaiming |
While I for sure enjoy to deliberately break existing tool chains (usually with benign intentions to improve the overall robustness), it's not something I would put up as a project aim. There is a worth in build systems like meson and CMake and I wouldn't call them broken for Fortran. Especially meson comes with a powerful project management system which allows to easily reuse code, which is no worse for Fortran than for C++. CMake has its particularities, but those are not aimed against Fortran, they are available for all supported programming languages on equal footing. I certainly don't enjoy writing CMake build files because it requires a lot of boilerplate I get for free in meson, but the resulting build system is solid across platforms and compilers which enables to focus on the important task at hand: writing better software. On the actual topic of reclaiming the f extension for free format source code. There are already huge Fortran projects, like Vasp and Turbomole, that use only f as extension for their Fortran source, which is mostly free format. Obviously there has to be a way to still use fixed format source code in such a huge code base from the past decades. This is usually done manually in a huge Makefile. For new projects this is less of a problem, so adopting f as default extension would work, with the minor annoyance of having to get the free-format argument right for every supported compiler. |
I think that we are saying the same exact thing (maybe from a different point of view): CMake and meson work really well (but also Autotools, once everything has been set up properly, ok except it's not cross platform, but I hope you'll get the point in a second). The problem is exactly writing all the necessary boilerplate that does not let you focus on writing better software. If we had already a valid, good all-around Fortran build system, why on Earth are we going the long way to build BTW, thanks for the examples and the links: I was not aware of Vasp and Turbomole. It gives me a lot of hope! |
Because it's fun. Why would somebody take on the effort to write meson in the first place when there was CMake and autotools around? The Gnome project now moved completely from autotools to meson, so maybe meson was a good idea and offered something you wouldn't get in autotools. If you look at meson you will notice it can do so much less than CMake, meson is not turing complete like CMake, there is no real reason to use meson, except that meson build files require a fraction of the lines you would write for the equivalent CMake project while you still can do 90% of your usual tasks with ease. So what's up with fpm? Why would we choose a configuration file format like TOML as input over a powerful DSL like offered by meson? If you need the DSL of meson to express non-trivial dependencies in your project, fpm will hardly ever become a real alternative, but if you want to prototype, you can get away with a single line in your fpm.toml input and start immediately. There is a gap fpm can fill for Fortran, it won't replace CMake or meson, at least in my opinion, but maybe it will allow us to seamlessly integrate with existing CMake and meson projects instead of fracturing the Fortran community with yet another build system (remember FoBiS, foray, ...?). |
The I really do not understand so much concern. Am I missing something? |
All these other build systems that you discuss--CMake, Meson, autotools--are (mostly) language agnostic. fpm is language specific. It's exactly what Fortran lacks and needs. Just like Cargo for Rust. We didn't start with the question how can we make CMake, Meson, or autotools, but better. We started with the question, what is it that Fortran needs? What will make a Fortran programmer happier? With special attention to new Fortran programmers, an endangered and almost extinct species. Try giving CMake or autotools to somebody new to these tools and watch them pull their hair out for a week straight. Let's face it, unless you dug your way through the mud and became an expert, using them sucks. I can't speak for Meson. These tools are also not package managers but build systems, as far as I understand them. So fpm does not aim to replace these tools. It's more orthogonal than competitive with them. Projects that need them will continue using them. You already don't need these tools for most new Fortran projects, and experience is vastly superior IMO. Sure, designing and building fpm is a lot of fun. But saying we do it just for fun is misleading. |
I should have worded it better: |
I wrote more on how I see the role of fpm in Understanding intent. |
Just two quotes to go back to the pros and cons of the discussion: @awvwgk wrote:
@milancurcic wrote:
I totally agree with both and, from my standpoint, this is enough to "take home" the message that if we break direct compatibility with such tools is not a "con": they are already complicated, require time, effort and attention regardless. Plus, if we develop the relevant back-ends, the problem evaporates entirely. Said that, I realise that I have been imprecise with my my wording and I am sorry if I might have also sounded too provocative (it was not my intention). |
My experience is that CMake is very powerful but complicated (and verbose). Meson is more simple to use, with a Python like syntax (fpm seems to be of the same family, and I like that). Although Meson is quickly evolving, it still does not install correctly the What I like in fpm is that it is totally oriented toward Fortran. It is simple to use, with a clear syntax. It is perfect for launching small projects (probably it will soon be OK for bigger projects). But the fpm killer feature is of course the way it can manage dependencies: already, being able to automatically git clone other fpm projects is awesome. But if it becomes able to do that with CMake or Meson, wow! That's what Fortran needs to cure its scattered ecosystem. To return to the subject, I have divided opinions about the |
Let's discuss CMake elsewhere (especially since we all agree on the pros and cons anyway and are just reformulating the same arguments with different words) and focus just on the The fact that Vasp uses My personal preference so far is this:
This issue is symbolic, at least for me. It is how Fortran is perceived, and if we managed to reclaim it and keep all the tooling working, I think this could be very exciting for newcomers to the language. And also it would be proof that our community is serious about Fortran and has the manpower (or will) to change things. However (and I can't stress this enough): doing something like this is only worth it if we are 100% serious about this. It is not worth doing if we are not convinced, as it will only fracture the Fortran ecosystem more. My recommendation at this point: let's keep using |
@certik The way you phrased the title of this issue is a big question and beyond the scope of fpm. Regarding that question, I agree with your proposal. But the question can be much simpler in the context of fpm: Should fpm assume free-form or fixed-form for .f files? Or perhaps the question is: Should fpm even make assumptions based on source file suffix? (I think not) I think fpm should assume free-form for all Fortran source files, and explicitly instruct the compiler to build fixed-form if specified in fpm.toml or by some other configuration means. Then you're not doing any kind of reclaiming, or having to convince compiler makers. You're just setting what we think should be a sane default in fpm, and perhaps even make a recommendation about suffix in the fpm guide. Consider this scenario:
If fpm is succesful in the long run (the Cargo of Fortran), .f adoption will happen naturally and effortlessly. |
In some way the problem of free- and fixed-form is really just a problem of language classification. Given the large strides made in natural language processing (NLP) in the past few decades, I wonder if the classification of a much less complicated man-made programming language can be so difficult. At least within the Some cons of this approach:
If we would try to pursue the auto-detection path, we have a lot of tagged data sets due to the existing convention of Edit: some programming language classification tools as proof of concept
|
I thought about auto-detecting free/fixed-form in |
Down the road this would break most of Fortran syntax highlighting. At least during a short transition period (likely on the order of decades), code editors would become forced to auto-detect or programmers would need to adjust their syntax highlighting settings manually. (For me personally it is not a problem, but for a beginner this might be discouraging.) Alternatively we would need to convince people to start renaming fixed-form files to |
You can't reliably auto-detect - it is possible to write code that is correct whether you interpret it as free form or fixed form. Fixed form is obsolescent. If you want fpm to assume free-form for .f you can, but you'll be going against decades of convention and it is likely to cause more problems than it solves. |
I realize such cases might exist hypothetically. But I don't think they pose a problem. In this special case you can just interpret the file as free-form. If it doesn't compile, then it must be the other form. If it doesn't compile as either, well then something is broken, the code, the compiler, or the standard (in this precise order). |
Upon reading some more about programming language classification, the most likely useful feature used to separate between the two forms are comments ( Since the language tokens are the same in both free- and fixed-form they cannot be used reliably. Luckily due to historical language features, and differing programming styles, it is likely that the frequency of tokens (including initial whitespace) can still be used for classification. It would be counter-productive to write your modern Fortran code in an old-fashioned way using computed GOTO's, labelled statements, and other deprecated features, even if theoretically possible. Of course you can do it, even if just for the pleasure of proving a classifier can be wrong sometimes. |
I am a newcomer to Fortran, and this issue is something that coincidentally have been on my mind when I first picked up this language some weeks ago. First, without having a background in the history of fortran, it was confusing to know what extension to pick. I wanted to write "modern fortran", but using the "f18" for the latest standard feels a lot like naming a file after the current year. Then I found out a lot of modern fortran code just uses ".f90" so I stick to that. Aesthetically it has been disturbing me, since Fortran is the only language I know that does not have unified convention (ok, you might say C++ has cpp, cxx, and cc, but these are of a different nature than Fortran's jungle of versions). As for a constructive proposal, I myself thought of using ".ff" for all my files (to differentiate it from ".f"), but Taking a pragmatic stand, I would just like to be able to use fpm and plain ".f" files for all my future projects. |
Just to mention some thoughts found in previous discussions about this topic:
All would still have issues with the assumptions utilties that supply highlighting might have. Currently the suffix is totally outside of the standard specifications and is just a (well adapted) convention. Support of .F|.F90 implying preprocessing (and which preprocessor), support of previous "standards" such as .for, .ftn, ... is spotty. Many have argued the standard should state some preference for suffixes when source is in system files, which you have to admit is pretty obviously common. One system allowed for directives in a single file that even allowed sections of C code mixed with fixed and free-format Fortran. I really liked that for building Fortran/C interfaces. I like the idea of "reclaiming .f" but because there are a number of compilers and tools that would have to change it seems a bit of a challenge without some kind of guidance or feature from the standard itself. If I were going to try to go down this path I think I would say that .f is preferred but equivalent to .f90 and implies free-format and that fixed-format should use .for or .ftn; (which would already be supported by a number of tools and compilers -- a good number treat .for and .ftn as equivalent to the current behavior with .f). I use .ff and .FF for essentially all new code, which in my environment implies a specific pre-processor is used, which is not generally applicable but I mention it because I think at some point If there were a suffix rule in .for seems to be generaly the same as .f, .ftn seems to sometimes be treated like .f and sometimes like .f90; looks like .f77 is supported more than I thought. Updating the fortran Wiki and/or adding a page with recommendations in fortran.lang might be a good place to start. I can see using .f77, and .f90 is widely supported but since I do not see anything enforcing .f03, .f15, .f08, actually mean that it is checked as conforming to a certain standard I think those should be STRONGLY discouraged. If anyone can add to this it would be great: Many compilers have options to specify assuming fixed or free-format. Some defaults are Cray:
FREE and FIXED
The FREE and FIXED directives specify whether the source code in the program unit is written in free source form or fixed source form. The FREE and FIXED directives override the -f option, if specified, on the command line.These directives apply to the source file in which they appear, and they allow for switching source forms within a source file.Source form can be changed from within an INCLUDE file. After the INCLUDE file has been processed, the source form reverts back to the source form that was being used prior to processing of the INCLUDE file. Intel:
Gfortran:
SEE ALSO
~ |
I just want to clarify this: compilers do not need to change. I opened a new issue #366 for a subset of what was discussed here. |
Since there is no standard for suffixes the compiler support varies extensively. Last I checked the Intel compiler had no switch to change the suffix meaning so .f always means fixed-format; but has very flexible directives such as "!DEC$ FREEFORM and NONFREEFORM that let you change even in the middle of a procedure (which sounds horrible but can be justified when using INCLUDE files). So to use the compiler you would have to copy/link the file to a different filename, for example. So the compiler does not HAVE to change but if it does not compiling a ".f" file as free-format becomes awkward. Every compiler is free to do what it wants. Some can compile from a pipe, some let you define suffixs to search for like ".fixed" and ".free". So no matter what fpm could always make file copies (my own build system does that primarily to allow for multiple concurrent builds so that is not totally unreasonable) but you cannot depend on the compiler being able to compile a ".f" file as free-format (although it is a common feature - GNU, NVidia, and Cray has such a switch, for example). |
You don't need that kind of switch. All you need is
|
That was what I meant was missing. Oddly, the man page for ifort I have does not contain the -free switch, but I tried it and it works with the version I have; I started taking a survey because I certainly have used compilers in the past that had no such switch and I remember one in particular that also did not support .F and .F90 implying preprocessing; so far (Cray, GNU, NVidia, now Intel) they have one but they certainly are not required to have it as there is no language standard, just a de-facto standard that has painfully emerged (.fort, .ftn, .for, .f77, ...). |
ifort also has I do not believe it is worthwhile spending any effort to change established usage of extensions. If you want fpm to assume that all sources are free-form, go ahead, but I anticipate future complaints when someone tries to package some existing fixed-form code. When I wrote my post in 2013, I thought it was way too late to effect such a change - it's even later now. Spend your time on something new. |
Here is another interesting case: For bigger projects like SymEngine I like to keep the main repository (https://github.com/symengine/symengine) in C++ (in this case) and then have wrappers in other languages as separate repositories with an extension, e.g.:
As you can see, for Fortran I used I am posting here to see what others think. It's about 5 months since I opened up the above issue, and I still like to just use |
This seems like an interesting way to "dip our toe in the water". Any ideas how may users it has? Are they "modern" Fortran users? This would be an interesting experiment to see what chances we have of succeeding in this endeavor. |
FWIW, I'm still in favor of adding |
SymEngine has quite a few users, including quite a few in the Julia community. The Fortran wrappers I think have exactly zero users because they are not complete yet. Once we make them usable, they will have at least one user: me. :) It's hard to predict how many users they will have, but I think they can potentially have lots of users. With LFortran working down the road, I would like to create tutorials how to do almost anything in Fortran that can be done in Python and Julia. Symbolics is one part of that. Once people can see the potential, I think we will have a lot of users. |
If we are looking for a project to check this out in practice, I can volunteer some of mine, like toml-f or dftd4, the former is part of the foundation of fpm, while the latter has a decent user base across different projects (like Vasp) and quite a few dependencies itself. Both support fpm, meson and CMake as build systems because they have to integrate with different ecosystems. So far I only have seen implementations of free format with First step of course would be to implement it in fpm itself. |
I am also in favour of this proposal. |
Let's do it. |
I support this proposal (reclaiming .f file extension for modern Fortran free form) as strongly as I can.
|
Please checkout #577 (comment) where I described how to add an option for disabling implicit typing in fpm. The same logic can be applied for always using free-form. I think the free-form makes a straight-forward feature for a first contribution to fpm and I'm happy to guide anyone interested through the process of implementing it. |
@certik Has this issue been resolved? If so, has the change been implemented? |
Unfortunately it has not been implemented yet. |
This has been a low hanging fruit for a while, therefore I didn't pick it to give new contributors a chance to get started with fpm, but I think that is no longer a blocker for me. I implemented part of the required infrastructure in #864, please have a look and let me know if that is what you had in mind. |
I might have shot myself in the foot here. My comment yesterday was inspired by a new project that starts with getting some Fortran 77 code to compile and writing a tiny bit of new code plus a unit test for the new code. I now have |
Hello all. I would be very glad if |
This was first seriously suggested here:
#359 (comment)
This deserves an issue of its own. Let's discuss the pros and cons, here is a start:
Cons
.f
for fixed-form and.f90
for free-form (see @sblionel's post for the history of this). Thus creating even more confusion..f
filesfpm
easily, it might break some other existing tools around FortranPros
.f
is a nice extension, natural for FortranRelevant other issues: #250, #359.
The text was updated successfully, but these errors were encountered: