dotnet / csharplang

The official repo for the design of the C# programming language
11.48k stars 1.02k forks source link

Consider changing record syntax to `record class XYZ(...) { ... }` #3753

Closed Unknown6656 closed 4 years ago

Unknown6656 commented 4 years ago

I'd like to ask the LDT to consider changing the current record-syntax to record class MyRecord(...) instead of record MyRecord(...).

... why?

I would want to propose the change for the following reasons:

The alternative would be to change VS' tooltips and syntax highlighting, in order to hide the class-implementation of the record-concept from the developer.

I hope that there is still enough time left before November (the month in which C#9 will be released to the larger public).

kofifus commented 4 years ago

You are missing my point. It is true that I can probably achieve what I want using my own code-conventions/containers/etc and an analyzer. I am in fact already doing that though I am yet to write the analyzer. However it was exactly a language feature of a record that is restricted and therefore guaranteed to be both strongly immutable and with value semantics that I was expecting/hoping for/disappointed that it is not there. Having such a language construct would have IMO pushed C# to the next level and encourage developers to write more functional/clear/bugfree/safe/etc code. But I feel that we are moving in circles here. I thank you for the responses.

HaloFour commented 4 years ago

@kofifus

Having such a language construct would have IMO pushed C# to the next level and encourage developers to write more functional/clear/bugfree/safe/etc code.

Having these be the default behavior is encouraging developers to write code in such a style. The developer has to go out of their way to break value identity and "readonly"-ness with positional records. What you describe beyond that is not a goal of C#.