C# makes a distinction between Constants and Read-Only variables. I'm not sure which other languages have this facility, but I've found it useful. For those unfamiliar with C#, a readonly variable may ONLY be set at definition time or in a constructor of a class.
Because of this defintion, a C# readonly variable is an example of a more general class of variables (sometimes known as WORMs - Write Once, Read Many).
Over the last six months, I've started to investigate specific adornments for WORMs. In my Naming Architecture, WORMs look similar to Constants, but are sufficiently different to stand out.
(For those interested, constants are UPPERCASED_UNDERSCORE_SEPARATED and WORMs are lowercased_underscore_separated)
This has proving interesting and beneficial since I started. As I said elsewhere, one of the objectives of my Naming Architecture is to ensure I don't inadvertantly use an RValue as an LValue.
Now, to the reason for this post...
Method parameters can be (conceptually) input only, output only or both. Input only parameters can be by value or by reference. Some languages (such as C++) allow you to define input only parameters as const - which means the variable can't be used as a LValue. Now, how do we define a constant?
I'm going to define a constant as an element whose value does not change. (Aside: this definition doesn't allow for "runtime constants" - these are WORMs) Thus, a method parameter, by defintion, is NOT a constant and, in fact, the C++ const attribute is really a readonly designator.
Should I use WORM adornments for method parameters I do not intend to change? As far as I can see, a Read-Only method parameter falls under my defintion of a WORM since its value is specified at the point of defintion (so to speak).
Interestingly, C# syntax doesn't seem to allow you to specify a method parameter as readonly (I may have that wrong).
Thoughts anyone?
Paolo