Skip to content

module naming issue #114

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

Closed
smeskos opened this issue Jul 7, 2020 · 11 comments
Closed

module naming issue #114

smeskos opened this issue Jul 7, 2020 · 11 comments

Comments

@smeskos
Copy link

smeskos commented Jul 7, 2020

I found out after a lot of trouble that I couldn't build my project because I had all the modules files in src/ in the form mod_name.f90, when I renamed all files to m_name.f90 and the modules to module m_name respectively, it recognized them all and built successfully.

@milancurcic
Copy link
Member

Right, it's an important detail. :)

I'm curious, did you read the Packaging Guide beforehand? If not, perhaps we need to link to it more prominently from the README. Currently it's at the bottom. If you did read it, was any part of the guide confusing?

@smeskos
Copy link
Author

smeskos commented Jul 7, 2020

Yes, I read it. Let me rephrase, the problem was not with the same name, I already had my files and modules named the same. The problem is with the particular style: mod_name.f90 and module mod_name. It couldn't recognize modules starting with the prefix mod_.

@milancurcic
Copy link
Member

Okay, I see. I don't think that should be the case. @everythingfunctional can you confirm this behavior? Is it expected?

@certik
Copy link
Member

certik commented Jul 7, 2020

We discussed the naming convention in #39 a bit.

I think the above seems to be a bug either way, but in general, we were thinking that we could simply name the modules by a name, and then fpm would enforce the directory structure in the name. So if you are calling your module as mod_name, and put it into src/a/b/mod_name.f90, then fpm would enforce that the module is called a_b_mod_name, but the filename is just mod_name.f90. That way we are essentially allowing to have namespaces.

@certik
Copy link
Member

certik commented Jul 7, 2020

The other issue related to this is that all modules should probably be prefixed by the name of the package, again, enforced by fpm. That way when you depend on it in other dependencies, the modules do not clash. So src/mymod.f90 would start with module mypackage_mymod.

@certik
Copy link
Member

certik commented Jul 7, 2020

CCing @everythingfunctional, it's important that we get this right soon.

I think the way we could do it is to implement what I described above by default and fpm would give an error if the modules are not named correctly. But users could override this in fpm.toml, if they really do not want to use this convention, say with module_naming_convention = false or something like that.

For example, in stdlib we already are naming modules like stdlib_experimental_io. After we move stdlib to use fpm, we would have a directory structure: src/experimental/io.f90, and since the package is called stdlib and since io.f90 is in the experimental directory, the file would start with module stdlib_experimental_io (as it already does). After the module graduates to stable, we move it to src/io.f90 and it would start with module stdlib_io.

@milancurcic
Copy link
Member

milancurcic commented Jul 7, 2020

The other issue related to this is that all modules should probably be prefixed by the name of the package, again, enforced by fpm. That way when you depend on it in other dependencies, the modules do not clash. So src/mymod.f90 would start with module mypackage_mymod.

I agree that we need some solution to prevent name clash with dependencies, but this solution doesn't look like a good one to me. Consider datetime-fortran, which has the package name "datetime", and one module that contains a derived type datetime. How do you suggest I name the module?

The way it's named currently (datetime_module), this would require that I rename the module source file to src/module.f90. It works but it's very awkward to me.

@everythingfunctional
Copy link
Member

If mod_name as the name of a module was not working but m_name was, that's a bug. I'm not sure what the problem is offhand.

I think enforcing modules in a library be prefixed by the project name is probably overkill. If namespacing is needed, we have a way to do that. Just put everything in a folder with the name of the library. I'm not sure having that be the default is necessary.

@smeskos
Copy link
Author

smeskos commented Jul 7, 2020

I tried to replicate my issue with a smaller test case, and I couldn't, this time, fpm worked fine with modules with prefix mod_. I also tried https://github.com/wavebitscientific/functional-fortran from @milancurcic (since his modules are with mod_) and it also worked fine. I can only guess that I am missing something in my main project. I am going to look into it and will come back when I figure it out. Sorry for this false alarm. Regardless, your comments were very interesting and helpful. Thank you all!

@certik
Copy link
Member

certik commented Jul 7, 2020

@smeskos I am glad it works!

@everythingfunctional I don't know. We should discuss it. I feel module names without prefixes should be reserved for the main (user) application. Libraries should hide their modules behind a prefix. That is the common convention in C, which has the same problem (all functions being global). So if we agree that is a good convention, then we should enforce it (users can opt-out).

@awvwgk
Copy link
Member

awvwgk commented Feb 12, 2021

The naming restrictions have been relaxed in both Fortran fpm in the current release. Therefore, I'm closing this issue as resolved. Feel free to reopen if this is not the case.

@awvwgk awvwgk closed this as completed Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants