In the news group archives I came across the mention of using a record discriminant to get a value that is constant as part of the record a few weeks ago. ![]()
Do people use that trick?
Should people use that trick?
In the news group archives I came across the mention of using a record discriminant to get a value that is constant as part of the record a few weeks ago. ![]()
Do people use that trick?
Should people use that trick?
Can you provide a link to the post? Thanks
I dislike this idea, but to its credit, it’s simple.
I’d rather hide the value in question insided an ADT with const-like behaviour and compose it into the record to make the intention explicit.
Which trick? Is defining a subtype with a constraint classified as a trick?
Using or arguably abusing? the record discriminant in order to get a constant record component.
O, is that what you were referring to. I never saw it as an issue, give that it is a deliberate aspect of a discriminant.
Maybe {$name}_Constant would provide clarity.
It doesn’t feel like a trick to make something a discriminant if it is a component that needs to be set when the object is created and cannot be changed thereafter. The only annoying thing is that discriminants are limited to elementary objects. However, with an “access constant” discriminant you can effectively include composite constant objects as well.