j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

Using mixedCase #168

Open certik opened 4 years ago

certik commented 4 years ago

@everythingfunctional wrote in https://github.com/j3-fortran/fortran_proposals/issues/56#issuecomment-602876857 and I am moving it to a separate issue here:

As a side note, what's the community consensus on mixed case? I've been working for the past few years under the assumption that it was ok to use mixed case as an aid to the reader, even if the compiler didn't care.

certik commented 4 years ago

The Fortran community has historically been agnostic if you use mixed case or upper case or lower case, so from this perspective, you can use whatever you prefer.

However, instead of each of us using incompatible naming conventions, I would like if we can come together as a community, and agree on a more unified style that we all follow. And then provide tooling (compilers) that can enforce it. Similar to Python's PEP8.

I like the Python's approach: https://www.python.org/dev/peps/pep-0008/#function-and-variable-names:

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

and I suggest we follow the same.

See also the discussion at:

https://github.com/fortran-lang/stdlib/issues/3

which lead to:

https://github.com/fortran-lang/stdlib/blob/5d1e09131cad56467549ecd9d6b977cec19b2f35/STYLE_GUIDE.md

Also https://www.fortran90.org/src/best-practices.html#naming-convention. One can browse current open source Fortran codes here: https://github.com/fortran-lang/stdlib/wiki/List-of-popular-open-source-Fortran-projects. Some codes use mixedCase, but most codes seem to use lower_case_with_underscores.

Leonard-Reuter commented 4 years ago

This is a related to https://github.com/j3-fortran/fortran_proposals/issues/118

I also like Pythons approach, and my Fortran programming is atm close to pythons PEP8:

Additionally, I follow two advises from the book 'Modern Fortran: Style and Usage':

certik commented 4 years ago

I think what we need here is an automatic formatter that can enforce these things. For things where there are multiple opinions, we can allow it to be configurable, so that each project can set it up the way they like, similar to clang-format.

I like all your suggestions, except the subroutines where I personally prefer all lowercase (but I understand your argument about arrays). But this can be configurable in the formatter.

HaoZeke commented 3 years ago

For what its worth, I prefer camelCase myself. The snake_case variables to me seem longer somehow. Enforcing project level specifications feel out of scope for the J3 committee. Anything like PEP8 would be something for the standards committee but I would definitely strongly be against (completely ruins backward compatibility for one thing).