# Variables, fields, arguments and properties naming

**URL:** <https://forum.castle-engine.io/t/variables-fields-arguments-and-properties-naming/1391>\
**Category:** Pascal\
**Created:** [October 17, 2024, 8:52pm UTC](https://forum.castle-engine.io/t/variables-fields-arguments-and-properties-naming/1391 "2024-10-17T20:52:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noscow](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/noscow/32/964_2.png) [@Noscow](https://forum.castle-engine.io/u/Noscow)\
**Post date:** [October 17, 2024, 8:52pm UTC](https://forum.castle-engine.io/t/variables-fields-arguments-and-properties-naming/1391/1 "2024-10-17T20:52:10Z")

</div>

Good day! 🙃  
I want to do refactoring of the some classes in my code. And in the one hand I like idea to use for the all class fields prefix “F” and for all procedures arguments prefix “A”.  
It seems useful, when I want to set fields, for example:

```auto
procedure TInanimate.SetInanimate(AName, AUrl : String);
begin
  FName := AName;
  FIconUrl := AUrl;
end;

```

And I like having a standard for naming fields regardless of whether there is a `property` for that field.  
But in the second hand this seems little ugly. And, as I see, this is not very common practice in the CGE examples…  
I think it is not only the a matter of taste, but way to make code some better. So, what naming you like, what you recommend and use? And what names you like for the properties, if you not use `Fxxx` fields names?  
Thanks!

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [October 22, 2024, 2:43pm UTC](https://forum.castle-engine.io/t/variables-fields-arguments-and-properties-naming/1391/2 "2024-10-22T14:43:04Z")

</div>

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](https://castle-engine.io/coding_conventions) ) – 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:

- [components/customform/custforms.pp · main · FPC / Lazarus / Lazarus · GitLab](https://gitlab.com/freepascal.org/lazarus/lazarus/-/blob/main/components/customform/custforms.pp?ref_type=heads)
- [components/opengl/openglcontext.pas · main · FPC / Lazarus / Lazarus · GitLab](https://gitlab.com/freepascal.org/lazarus/lazarus/-/blob/main/components/opengl/openglcontext.pas?ref_type=heads)
- [lcl/asyncprocess.pp · main · FPC / Lazarus / Lazarus · GitLab](https://gitlab.com/freepascal.org/lazarus/lazarus/-/blob/main/lcl/asyncprocess.pp?ref_type=heads)

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 🙂
