I think I have the same feelings as you (consistency is good, but also “A
for all params and F
for all fields” looks a bit ugly). I haven’t really “resolved” these feelings with 100% strict rules in my head, after more than 20 years of coding in Pascal
So, my general rule of working:
-
Private fields get F
prefix always, which means: field FXxx
backs a property Xxx
.
-
Parameters get A
prefix (or An
, like AnItem
, following English rules) if it is really necessary, which means: they would otherwise conflict with field/property name.
… but I don’t treat these 2 conditions (“… always …” for fields, “… if it is really necessary …” for params) strictly. So you will find throughout CGE deviations from these rules:
- occasional code where I didn’t use
F
prefix for private fields. Maybe the class has lots of private fields, not backed by properties.
- occasional code where I used
A
/ An
prefix for parameters even though it is not strictly implied by the above rule. Maybe it was historically necessary.
Somehow it works for me
Important factor here is that both these decisions are about internal things – i.e. the prefix F
is only for private fields, or A
for parameters of routines. None of these things determine the public API of Castle Game Engine. E.g. public fields, if ever, in CGE look just like properties (and may change into properties at any point), never have F
prefix.
So, I guess I don’t feel very bad about being a bit inconsistent in applying these prefixes, because I know I can always change it – without affecting CGE users at all. There is a fear that it will cause trouble for contributors (this would be a reason to make these rules more strict, and also document in Coding Conventions | Manual | Castle Game Engine ) – but so far, it seems all contributors picked up this rule and follow it, 90% consistently, just like me So it works.
As always, this is just “what I do” (and I guess it determines CGE source code).
I think LCL code is a bit similar, but maybe more strict in following these rules:
In above (~random 3 unis from LCL), LCL seems to follow similar rule as me for A
param prefix (so some params have it, some don’t) but more strict rule for F
private fields prefix (it seems 100% of their private fields have it).
Opinions / thoughts / alternative approaches are welcome