[fpc-devel] class constants

Andrew Brunner andrew.t.brunner at gmail.com
Mon Oct 19 16:12:08 CEST 2009


On Mon, Oct 19, 2009 at 9:18 AM, Peter Popov <ppopov99 at gmail.com> wrote:
>>
>> An example would be
>> TItemCache = class
>> private
>>   const DEFAULT_CACHE_SIZE = 1024;
>>  ...
>> end;
>>
>> sure a global value would do, but there is no need for the value to be
>> global.
>>
>> Martin
>
> This is a good example. However, the same paradigm can be achived by a
> function:
>
> function TItemCache.DEFAULT_CACHE_SIZE: Integer;
> begin
>  Result := 1024;
> end;
>
> If properly inlined, the compiled code is the same and semantically the two
> are the same.
> Granted, defining it as constant saves the 4 lines needed to implement the
> function :-)
>
> In the same example, a typed global constant gives it a different flavour,
> in the sense that the user of the class can modify the value at run-time,
> e.g. by reading an ini file/registry entries when the app starts.
>
> Peter
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>

Well, if we're looking to add functionality I would think NameSpaces
like in C# would be useful to bind constants and data structures to
namespaces...  Just my $0.02



More information about the fpc-devel mailing list