Stdlib: Module naming convention

Created on 15 Dec 2019  路  3Comments  路  Source: fortran-lang/stdlib

Tangential to #3. The choice of a module naming pattern is important because a module with a generic name can cause conflict in the client code. In the absence of namespaces, the standard library modules should have a specific enough prefix to prevent such conflicts.

One approach could be to use

  • stdlib for the top-level module;
  • stdlib_<group> for specific modules, e.g. stdlib_collections, stdlib_sorting, etc. you get the idea.

In the recent years, I tend to name modules with a mod_ prefix, e.g. mod_functional. I see in the wild that module_, m_ prefixes, or even _m suffix are used. If I name the source file the same as the module, then I can easily see which source files contain modules and which don't. To me, this is useful if I haven't looked at the library in a long time, but now I can't think of any other benefit to this "convention". If this convention is used for stdlib, then we'd have:

  • mod_stdlib
  • mod_stdlib_<group>

However, this seems unnecessarily verbose, and most library files are likely to be modules anyway (with the exception of tests which would be programs in their own directory, see #7). Thus, if we use the stdlib_ prefix universally, I don't think we need mod_ or similar.

Most helpful comment

We follow a convention on our project where there is one module per file, and the module name matches the filename. This is close to Python, where the file is the module. This has worked very well for us. (We also do not use any _mod style suffix.)

All 3 comments

This would be ultimately fixed by https://github.com/j3-fortran/fortran_proposals/issues/86, then the top level module would be called stdlib and everything else will be nested underneath, such as sorting, linalg, etc.

Until then, I suggest to use underscore to emulate "nested modules", so as you suggested, I would use stdlib_linalg, stdlib_sorting, etc.

I don't like the mod_* convention, as I try to recommend for every .f90 file to be a module. For stdlib I think every .f90 file can be a module.

I don't like the mod_* convention, as I try to recommend for every .f90 file to be a module. For stdlib I think every .f90 file can be a module.

Or submodule... but yes I agree.

We follow a convention on our project where there is one module per file, and the module name matches the filename. This is close to Python, where the file is the module. This has worked very well for us. (We also do not use any _mod style suffix.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vansnyder picture vansnyder  路  6Comments

vmagnin picture vmagnin  路  10Comments

MuellerSeb picture MuellerSeb  路  5Comments

certik picture certik  路  9Comments

masuday picture masuday  路  5Comments