I sometimes wish that FreePascal didn't have const modifier for function arguments at all. Because I often find myself thinking whether I should use it in every particular case or not
procedure WriteStuff(s: string);
//or
procedure WriteStuff(const s: string);procedure CalcNumber(i: Integer);
//or
procedure CalcNumber(const i: Integer);
I am kind of aware of effects caused by const modifier. For example, when string argument is declared const, compiler does not enable reference counting for it (in this particular procedure)
However, it does not make things easier for me because I still have to think "do I need reference counting in this case or not". With reference counting enabled it feels somehow safer while with reference counting disabled the code should generally work faster
Do you put const everywhere or avoid it at all? or spend time thinking in each case?
What about class instance variables?
procedure PrintObject(o: TMyObject);
//or
procedure PrintObject(const o: TMyObject);
In 99% of procedures I do not assign values to arguments in procedure body. So should they be const? Not sure if const makes code more readable or otherwise