41 lines
1.5 KiB
Markdown
41 lines
1.5 KiB
Markdown
|
|
# C# Language Design for Feb. 24, 2020
|
|
|
|
## Agenda
|
|
|
|
1. Nominal records proposal
|
|
|
|
## Discussion
|
|
|
|
### Nominal records
|
|
|
|
https://github.com/dotnet/csharplang/issues/3226
|
|
|
|
We've been trying to leave space open for something we're calling "nominal records" where the
|
|
concept is that we establish some new system for constructing types based on names, instead of
|
|
the order of parameters in a constructor.
|
|
|
|
Here we have a refreshed nominal records proposal to examine and consider.
|
|
|
|
The proposal says:
|
|
|
|
> The main thing you lose out on with nominal construction is a centralized place - the
|
|
constructor body - for validation. Property setters can have member-wise validation, but
|
|
cross-member holistic validation is not possible. However, for a feature such as records that is
|
|
for data not behaviors, that seems to be a particularly small sacrifice.
|
|
|
|
We don't necessarily agree that this is a small restriction, and there may be some way to add
|
|
support for it.
|
|
|
|
When it comes to the `With` we do need to decide what members are copied over in non-destructive
|
|
mutation. One strategy is to use the "surface area" of the object, which is defined as the
|
|
constructor parameters, along with the public fields and properties that have some sort of
|
|
"setter".
|
|
|
|
Alternatively, we could copy over the state of the object. This would be equivalent to the use
|
|
of the `MemberwiseClone` approach as we discussed in previous design meetings.
|
|
|
|
**Conclusion**
|
|
|
|
There are many details to work out, but there's consensus that we want to investigate adding
|
|
nominal records in the future.
|