Shorthand for positional record inheritance #4081
Replies: 3 comments
-
I view this as more of a use case for adding required properties to the language to make nominal records a viable solution here, personally. Positional constructors are just brittle across hierarchies, particularly when you start mixing multiple assemblies into the mix, and I'd prefer to investigate nominal properties as the solution. |
Beta Was this translation helpful? Give feedback.
-
I also vaguely remember this... I'm really not sure though why you're using positional records in this case. Isn't a positional record normally thought of as essentially a tuple, with the usual rule-of-three holding true? With required properties this should cease being an issue. |
Beta Was this translation helpful? Give feedback.
-
I was thinking recently that this part of the records proposal seems to have disappeared at some point. The Inheritance, especially in a framework using constructor Dependency Injection, can be a pit of failure because of the base class brittleness. In places where I know there will be an expandable inheritance hierarchy I often prefer using "property bag" types these days rather than "real" constructor parameters (or interface/abstract method parameters...). That way, adding a new property won't instantly break all implementors. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I swear I remember this being discussed, but couldn't find the issue/discussion.
I find myself writing records that repeat the same parameters over and over again, e.g.:
Yes, there exist cases when I do not include every single parameter from the base record's primary constructor in the derived record's primary constructor or do not pass them as-is, but they are definitely in the minority. I propose a token that can both go into the derived record's primary constructor to show that it contains every parameter from the base record's primary constructor and that can go into the inheritance clause to avoid repetition (and show that we're not trying to call the parameterless constructor if it exists), e.g.
...
:Beta Was this translation helpful? Give feedback.
All reactions