j3-fortran / fortran_proposals

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

Upper/Lower case variable names #263

Open 8bitmachine opened 2 years ago

8bitmachine commented 2 years ago

Currently Fortran ignores case for variable names. Originally using capitals, editors currently use, almost exclusively, lower case as typed and which many seem to prefer. However, I would propose to allow upper and lower case to be used distinctly. This would require a new directive element such as CASE SENSITIVE which if absent allows the compiler to continue to ignore case. as I would find it convenient to be able to use both in variable names. It will mean having to pay attention when used, such as m and M, when for example nested loops or indirect references may need several integers such as i,j,k,m,n; while real variables could use M,N etc. This should not preclude the use of engineering notation like k or K (which would also be useful) if these are attached to real numbers as that should be implicit in the context.

wyphan commented 2 years ago

This is gonna be interesting if implemented. IMHO it's definitely gonna break backwards compatibility. Unless you have a really strong reason why Fortran should treat VAR, var, Var, or vAr (pun intended) differently, other than making it behave more like C/C++, Python, and all the other programming languages that are case-sensitive.

Also, I would suggest something other than CASE for the keyword since that's already in use for SELECT CASE and will trip not only lexers, but also syntax highlighting!

certik commented 2 years ago

@8bitmachine do you want to be using k and K for two different variables?

If you just want this feature to make the compiler enforce case sensitivity, that could already be implemented in compilers without changing the standard: the compiler could warn you if you use a variable name in a case insensitive manner.

8bitmachine commented 2 years ago

@certik Yes, that is the idea. I like minimal typing and often use M for a matrix (real) and want to then use m as an index if needed, for example, especially if references are indirect (as in mapping a physical grid to a matrix location). Or I may want k for an index and K for Boltzmann's constant. So yes, and it will make Fortran more C-like. Reading data using engineering notation is not a problem if using ASCII as k and K are identifiable. While I'm at it, has anyone suggested making pi (=3.14159265358979323 etc) a standard variable?

8bitmachine commented 2 years ago

@certik - Another point is that if a compiler does the job without changing the standard then that means portability is at risk. I don't think this should be a compiler function. Unless Fortran demands compilers meet a standard critierion for this.

certik commented 2 years ago

Above I suggested it could be a compiler function only to warn about inconsistent case. Since you want to allow making k and K to be two different variables, that would have to be a change in the standard.