Replies: 15 comments
-
Title says March, link is for May 😅 |
Beta Was this translation helpful? Give feedback.
-
record class Person { string FirstName; string LastName; } To me, this already feels like the default accessibility is public for records. Why still concern about "changing default accessbility" when adding private properties? Other examples are interfaces, enums. For normal devs, their members are public by default, even though not accurate for language experts. |
Beta Was this translation helpful? Give feedback.
-
My two cents: I really don't like that I can't know without context whether Same thing with public by default without any keyword: it will break the nice rule that having no modifiers on a member means "the most restricted modifier that can be applied here is used", which has been true since C# 1. Quoting gafter in #3231:
Are the four extra characters of the I really hope the LDT won't disallow adding other non public members to a record. Do you need to add some caching or pass some internal data to that nice record? You now have to ditch it completely and rewrite it as a class. Don't get me wrong, I want records! They will really help simplify many classes in some codebases. But if they are too restricted, they risk becoming practically useless (not everything is as simple as |
Beta Was this translation helpful? Give feedback.
-
That's already the case for |
Beta Was this translation helpful? Give feedback.
-
I've pointed this out before, but I would like to reiterate: this is already the case in Scala, and I have never seen it cause any confusion. It mostly just works. Records are extraordinarily useful for creating lots of small types whenever you use them. For them to be useful for this purpose, writing them has to be as short and low cost as possible. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
But they're both properties ;) We know that interfaces members are always I understand the needs filled by this approach, but I personally don't like that there's no middle ground: you're either a simple record without logic nor private data, or you're a fully fledged class. The moment you need to add the slightest logic to your record, you have to rewrite it as a standard class and it won't be as simple as removing the
Thanks, that's good to know! |
Beta Was this translation helpful? Give feedback.
-
Ever since C# 8 they can be private sealed. |
Beta Was this translation helpful? Give feedback.
-
Fixed, thanks. |
Beta Was this translation helpful? Give feedback.
-
IMO a I also don't think that records should prevent other members. There's certainly value in supporting computed properties or methods, and I can imagine that we'd want validator support as well. I don't even think that there's a problem with additional private state, even if they don't participate in value equality. I'm not aware of another language that prevents additional members, including F#. That said, restricting them in the short term wouldn't prevent enabling them again in a future release. |
Beta Was this translation helpful? Give feedback.
-
I'm having a hard time following the records proposal over time as there doesn't seem to be a single living WIP document anywhere. The proposals in here are all out of date. I guess this is the closest thing to a most recent proposal? I'm not even clear whether explicit accessors are allowed or not? I hope so, otherwise the uses for records will be severely limited. I can't see how you could possibly disallow private members. Not having private members means that as soon as you do need a private member you now need to refactor into a normal class, which is a huge cliff to fall off of. Your Person example is actually perfect for illustrating this. record class Person
{
string FirstName;
string LasName;
} Ok, now the Boss wants a computed FullName. record class Person
{
string FirstName;
string LastName;
string FullName => $"{FirstName} {LastName}"; //Is this allowed???
} Actually, let's cache that since this thing is immutable anyway. record class Person
{
string FirstName;
string LastName;
string FullName =>_fullName ??= $"{FirstName} {LastName}" //Is this allowed???
private string _fullName; //Surely, this must be allowed???
} |
Beta Was this translation helpful? Give feedback.
-
Has the LDC discussed records implementing Watching the C# video from Build the the most jarring part of the demo is watching them use |
Beta Was this translation helpful? Give feedback.
-
That might have been so they could more easily demonstrate the difference
between value and referential equality?
…On Fri, 22 May 2020 at 20:21, Sam ***@***.***> wrote:
Has the LDC discussed records implementing == yet? It still seems bizarre
to me implementing types with value semantics that don't have those
semantics on ==.
Watching the C# video from Build the the most jarring part of the demo is
watching them use Equals() explicitly rather than ==.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/dotnet/csharplang/issues/3470#issuecomment-632868973>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADIEDQIL5H33XMSCSOHN3Z3RS3GCJANCNFSM4NEYF76A>
.
|
Beta Was this translation helpful? Give feedback.
-
@spydacarnage It's been an "open question" on whether to have records implement |
Beta Was this translation helpful? Give feedback.
-
Would it not default to the standard definition of ==, which would mean that Equals and == worked differently, which would be even worse? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
May 11, 2020
C# Language Design Notes for May 11, 2020
Records
Beta Was this translation helpful? Give feedback.
All reactions