[fpc-pascal] class constants
Marco van de Voort
marcov at stack.nl
Thu Jan 24 19:45:02 CET 2008
> Henry Vermaak wrote:
> >> I'm not sure what you mean - do you mean would I be willing to write the
> >> support myself?
> >
> > i think he's asking what the use of it is. number 2 under the link he
> > gave.
>
> Oh, ok. Well, I'll try to summarize:
>
> Class constants add the ability to provide scoped, "namespaced" constants.
A constant is already in a scope, the unit.
> Although one can handle basic scoping with global constants, by placing them
> in interface vs implementation, they were not designed to be scope-limited.
> They also do not provide a way to group several constants under a common
> name, though one can simulate this functionality using creative constant
> names.
Stuff them in one unit. unitname.constant.
> Some of the benefits of class constants are: 1. They provide object-oriented
> constants,
That's a description, not a benefit. Taste matters are difficult to measure.
> 2. They simplify coding by saving the developer from having to
> write long constant names to distinguish global constants from each other.
> 3. They reduce coding errors due to the ability to only make public what is
> necessary, keeping what is visible to outside units/classes to a mimimum.
Units/move them to implementation. The chance that random classes in the
same unit clash is negliable.
> Personally, the main reason I need them is for compatibility. I have a large
> Delphi codebase that I'm porting to FPC and it uses class constants all over
> the code.
IMHO that is the only decent reason. Technically IMHO it doesnt make much
sense, it's just a dotnetism, copying blindly from a different world to make
nice feature butlletlists.
And like the rest of the dotnetims, they are relatively little used,
probably mostly out D7- compat reasons. And thus they are waiting for an
implementor. I'm not aware of work being done on any of them (though I have
a vaguely recollection that the strict private and protected exist, but I'm
not sure if in fully compat form).
Besides implementing, making a good study of what they _EXACTLY_ do, and a
bunch of testcases/unittests could really further the cause also.
More information about the fpc-pascal
mailing list