Replies: 68 comments
-
This is all fine or good, but deciding to make So, based on these decisions, what does the following mean? public struct Point(int X, int Y); |
Beta Was this translation helpful? Give feedback.
-
It was mentioned that the syntax
As of last LDM, this is invalid syntax. When we have a complete primary constructor (not records) proposal, that will probably be a parallel construction to a non-record class with a primary constructor. |
Beta Was this translation helpful? Give feedback.
-
Yes, it could, but now Especially this notion that the following could mean two completely different things in C# 8.0 vs C# 9.0. Seems very unlike how C# has ever evolved contextual keywords. I don't think that the move to evolve the language with the runtime justifies it. public class C {
public record M(int x, int y) { }
} |
Beta Was this translation helpful? Give feedback.
-
You mean from the syntax perspective? That's not how I would implement it, I would just make it an optional token after the
Yup, as mentioned this is a breaking change, and will be interpreted one way before C# 9 and a different way after. |
Beta Was this translation helpful? Give feedback.
-
I understand this makes nominal record more consistent with positional record. But suppose if I were to change Y to have explicit property get/init implementation, what changes should I do? Like below? // data int Y;
int Y
{
get => backingFieldOfY;
init => backingFieldOfY = value >= 0 ? value : throw new ArgumentException("...");
} Or, make the question in another way: does it mean |
Beta Was this translation helpful? Give feedback.
-
@qrli Yes, |
Beta Was this translation helpful? Give feedback.
-
I know that what I'm going to propose here might be a bit weird but wouldn't it be possible to introduce Personally, I prefer |
Beta Was this translation helpful? Give feedback.
-
I see no reason why we couldn't choose to do that. |
Beta Was this translation helpful? Give feedback.
-
I second all @HaloFour 's concerns. Since he already spilled everything i thought of i will leave it at that |
Beta Was this translation helpful? Give feedback.
-
I agree with @eyalsk:
'twas just a joke 😘 |
Beta Was this translation helpful? Give feedback.
-
Joking aside, I totally agree. Not having a breaking change, and having
the ability to potentially avoid somebody suggesting "valuerecord" or
some-such in the future, is well worth having to write "record class" vs
"record".
Also, while structs currently have value equality, the ability to easily
add "with" support to a struct would be something I'd like to see.
…On Mon, 1 Jun 2020 at 11:28, Unknown6656 ***@***.***> wrote:
I agree with @eyalsk <https://github.com/eyalsk>:
Introduce record [class|struct] .... instead of introducing a breaking
change.
------------------------------
[image: image]
<https://user-images.githubusercontent.com/8807985/83400387-05f4ae00-a403-11ea-9394-eb81a284e979.png>
*C# LDT meeting [ca. 2020, colorized]*
'twas just a joke 😘
—
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/3526#issuecomment-636769213>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADIEDQNJBEFJTAFYMH33A7TRUN7DRANCNFSM4NPLCSWA>
.
|
Beta Was this translation helpful? Give feedback.
-
That would be as easy as this, once the work for the factory method attribute gets done: public struct S
{
[Factory]
public S With() => this;
} Though this does presume that any fields of reference types can't be mutated in-place. If there is such a case, you'd do |
Beta Was this translation helpful? Give feedback.
-
We don't even need copy constructors to implement with on structs. We can just dup them and then set fields/properties. |
Beta Was this translation helpful? Give feedback.
-
I don't understand the LDT's seeming obsession with shaving off every possible character for the records feature. Is Snippets/autocomplete can handle most of the typing, and adding/changing types/members is not something most people are doing on a daily basis. You spend most of your time working with the types, not writing their definitions. This isn't like adding |
Beta Was this translation helpful? Give feedback.
-
I'm conflicted about the notion of the IMO, I'm not offended by having to have full and proper property declarations in a nominal record. They are, afterall, the focal point of what that type represents. Having them look and act like regular auto-properties would be fine to me and I think would decrease the cognitive load when learning about these types. What I don't want to have to write is all of the rest of the boilerplate code that goes into value equality and cloning. That's where I personally find the value of records. Not in trying to make the data declaration as terse as humanly possible. The |
Beta Was this translation helpful? Give feedback.
-
This seems to be what Scala is doing: class Base1 {
override def equals(that: Any): Boolean = false
}
class Base2 { }
case class Foo(val x: Int) extends Base1 { }
case class Bar(val x: Int) extends Base2 { }
object Main {
def main(args: Array[String]): Unit = {
if (Foo(123) == Foo(123)) {
println("foo equals")
} else {
println("foo not equals")
}
if (Bar(123) == Bar(123)) {
println("bar equals")
} else {
println("bar not equals")
}
}
} prints:
|
Beta Was this translation helpful? Give feedback.
-
Sure you would. That's the constraint that says this is a reference type. We picked For example you can pass interfaces to your type parameter here, as well as delegates. Interface are not classes. Delegates aren't either. But they are things that satisfy the The same would hold for records. |
Beta Was this translation helpful? Give feedback.
-
Similarly, the |
Beta Was this translation helpful? Give feedback.
-
No. As per above. If they have overloads to handle reference types specially, then records will just work there. |
Beta Was this translation helpful? Give feedback.
-
Why not? |
Beta Was this translation helpful? Give feedback.
-
Why not? Our designs up to now have considered that an important migration path for code. I know of nothing in the design that would prevent or limit that. Indeed, I was planning on writing the ide features to do just this. |
Beta Was this translation helpful? Give feedback.
-
public record Point
{
data int X;
data int Y;
} I would exchange |
Beta Was this translation helpful? Give feedback.
-
That's fair, a record is just another reference type and
Then records are just classes, that's just not a compiler detail. For all intents and purposes records and classes are the same and interchangeable (and they really are under the hood). That's why others and I have difficulties agreeing to the concept of records as their own kind of entity and the drop of the When introducing tuples to people, they don't have to know how it's compiled: as you said I also think of a tuple as a separate entity and the implementation is a detail. With records, people will be taught that records are classes with sugar (a sweet one that is) since they have to know that to use them properly. I really appreciate that you took the time to answer. |
Beta Was this translation helpful? Give feedback.
-
As I said myself:
Just as many other things in the language compile down to other things.
That's a perfectly fine opinion. I don't share it. Something can be it's own entity, but still be compatible with another. Tuples are their own entity for me, but they compile down to a standard struct and can be used anywhere that specifies a value type constraint. That doesn't bother me. |
Beta Was this translation helpful? Give feedback.
-
Happy to :-) |
Beta Was this translation helpful? Give feedback.
-
But a lot of people did care about this. It was actually a large point if contention for people (and still is), that it's a mutable value type. You'll always have some people who care and pay attention to the underlying representation, and some who don't care. |
Beta Was this translation helpful? Give feedback.
-
I have no problem with that. TypeScript classes (before ecma introduced them) compiled down into JavaScript constructor functions. It was just sweet sugar. So what? We could have gone with a If people get told that this is a nice simple shorthand for a class with lots of behavior baked in, I have no problem with that. And that doesn't make me not want a simple syntax here for these. |
Beta Was this translation helpful? Give feedback.
-
I am a little bummed to see struct support getting pushed out for now. One important side effect of making type declarations easier/smaller, is that people will want to define more types now that it isn't as much of a pain. Finer grained types can help the compiler assist in validating correct programs. But if they are all classes it holds this feature back from performance sensitive areas where chatty object allocation would impede performance. Which is doubly unfortunate, since performance oriented code often needs additional help in being proven correct. My current workaround is to define my fine-grained types as struct records in F# then reference the assembly from my perfy C# code to try to have my cake and eat it too. |
Beta Was this translation helpful? Give feedback.
-
I wish primary constructor for (non-record) classes and structs will be in C# 9 and it is consistent with that for records. |
Beta Was this translation helpful? Give feedback.
-
@ufcpp : I really hope that, too! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
C# Language Design Notes for May 27, 2020
Record syntax
1. Record structs?
2. Record syntax/keyword
3. Details on property shorthand syntax
Beta Was this translation helpful? Give feedback.
All reactions