# Variable name case consistency warnings

**URL:** https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362
**Category:** Help
**Created:** [May 2, 2022, 1:35pm UTC](https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362 "2022-05-02T13:35:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![james3](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@james3](https://fortran-lang.discourse.group/u/james3)
#### Post date: [May 2, 2022, 1:35pm UTC](https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362/1 "2022-05-02T13:35:48Z")

</div>

Are there any tools or compiler options that can detect when the case of variable names is used inconsistently? So, if I declare a variable `foo` I want a warning when I use it as `Foo` or `FOO` for example? (This is just to improve readability in code. I don’t actually want a non-standard case-sensitive compiler.)  
Thanks.

---

<div class="post-metadata">

### Author: ![nbehrnd](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@nbehrnd](https://fortran-lang.discourse.group/u/nbehrnd)
#### Post date: [May 2, 2022, 8:18pm UTC](https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362/2 "2022-05-02T20:18:56Z")

</div>

Though not specific for variables, Patrick Seewald’s [fprettify](https://github.com/pseewald/fprettify) has an optional flag `--case` which reads as

> «Enable letter case formatting of intrinsics by specifying which of keywords, procedures/modules, operators and constants (in this order) should be lowercased or uppercased - 0: do nothing | 1: lowercase | 2: uppercase (default: [0, 0, 0, 0])»

which might go into the direction of your interest or may adjusted by you (the project has a permissive GPLv3 license). You need Python to work with this formatter (e.g., for a more consistent indentation in do/for loops) equally may install it _via_ [PyPi](https://pypi.org/project/fprettify/). Speaking for Linux Debian, you then may run this system wide from the CLI. (GitHub equally lists some ports like for [conda](https://github.com/conda-forge/fprettify-feedstock) and [Emacs](https://github.com/osada-yum/fprettify.el) in case these suit better your needs.)

---

<div class="post-metadata">

### Author: ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)
#### Post date: [May 2, 2022, 10:55pm UTC](https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362/3 "2022-05-02T22:55:11Z")

</div>

the (commercial) plusfort spag(1) program has a lot of options for specifying case, where you can ask it to convert to lower, upper, upper-case intrinsics, keywords, …

If the code if free-format it would be easy to use flower(1) (Fortran lowercase) to convert code to all lowercase or uppercase, ignoring case. A standalone single-file version is at  
[https://raw.githubusercontent.com/urbanjost/index/main/bootstrap/flower.f90](https://raw.githubusercontent.com/urbanjost/index/main/bootstrap/flower.f90)

or as part of [GitHub - urbanjost/general-purpose-fortran: General Purpose Fortran Cooperative](https://github.com/urbanjost/general-purpose-fortran)

It would be very straight-forward to change flower.f90 to split into words and sort and look for names that are identical except for case. The orderpack(3f) module can find unique names and the M\_strings(3f) module can eliminate non alphanumeric+underscore characters and split into words, so it would only take a little bit to change flower so after comments are stripped to sort into a unique list of sorted words, and then compare; although if you are using GNU/LInux or Unix just stripping the comments with flower and then running through a few GNU filters would find the words, but it might be hard to keep the original line numbers that way. Do you need it to show you the lines, or is just a little table sufficient; or do you want something like an aspell(1) utility? If you want to just force everything to lowercase flower(1) will do that.

[https://urbanjost.github.io/general-purpose-fortran/docs/flower.1.html](https://urbanjost.github.io/general-purpose-fortran/docs/flower.1.html)

---

<div class="post-metadata">

### Author: ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)
#### Post date: [May 2, 2022, 11:02pm UTC](https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362/4 "2022-05-02T23:02:47Z")

</div>

Another option if you use [fortls](https://github.com/gnikit/fortls) - Language Server is to raise a diagnostic warning about names that are lowercase/uppercase/camelcase, etc. and possibly perform a code action by fixing them. I would have to implement that but serving diagnostics and performing code actions are 2 of the things language server’s tend to do best.

---

<div class="post-metadata">

### Author: ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)
#### Post date: [May 3, 2022, 8:14am UTC](https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362/5 "2022-05-03T08:14:17Z")

</div>

The old SunStudio had a compiler option for that, and I see its successor, Oracle Developer Studio, still has it: `-U` means “recognize upper and lower case as distinct” (see their [documentation](https://docs.oracle.com/cd/E77782_01/html/E77790/aevda.html#scrolltoc)). It issues a warning whenever a variable or procedure is referenced with a different capitalization that the one in its declaration.  
Years ago, I used this as a second compiler and I have to admit it was very good (their IDE is nice as well). Nowadays, however, there is a catch (and a big one, at least for me): the whole compiler suite is for x86 systems (or 64-bit with multilib, which I don’t like), and their Fortran compiler is still F95. It seems Oracle isn’t interested on this project, and just offers the old SunStudio with minor - if any - changes, and with a different name. Their latest version is 5 years old already.

Even though Fortran doesn’t treat upper and lower case as different (for backwards compatibility, I guess), it is still a useful feature as an optional compiler flag. I am surprised common compilers don’t have an option for that, and we still have to rely on external parsers to get this functionality.

---

<div class="post-metadata">

### Author: ![james3](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@james3](https://fortran-lang.discourse.group/u/james3)
#### Post date: [May 3, 2022, 3:32pm UTC](https://fortran-lang.discourse.group/t/variable-name-case-consistency-warnings/3362/6 "2022-05-03T15:32:37Z")

</div>

Thanks for this and all the other suggestions.

The `-U` flag in Oracle Developer Studio does the trick, and this will help a lot in tidying up some code.
