[fpc-devel] class constants

Martin lazarus at mfriebe.de
Mon Oct 19 13:51:29 CEST 2009


Peter Popov wrote:
>
> That is my point: most constants are global in nature. It would be 
> interested to see a class constant which is usefull where a global 
> constant (within a unit) is not.
A class constant could be useful for a default value. Normally those are 
all set in the constructor. But if you encourage self-documenting source 
code or dislike the code-explorer's "unnamed const" count to go up, then 
you may want to use constants.

It would also indicate to someone using your library, that they could 
change the source and use a diff constant. (Hopefully without having to 
check for further occurrences of this value)

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



More information about the fpc-devel mailing list