Using records when ever I can in my projects and they're definitely making things a lot easier :-) DebuggerDisplay straight outta the box, support for attributes, init-setters, etc.
Something else that may deserve its own highlight is the record "with" keyword to copy and override specific properies. That was a gamechanger when i started working with state management in blazor, especially with the init setter
2:40 "I've made IceCream abstract" - how? Line 16 says otherwise, since you called it directly? Clarification needed, ta Understand the Other Records are inheriting from (base) IceCream internal record IceCream(string Flavour, string Colour) - would make this abstract? or does it need to be Protected? or am I off Base here?
I don't see the point. Yes, there are classes that only are used for data, but this can change very quickly and you add some methods, logic, and so on to them. Even when they are mostly used for Data, there are often just master classes that are used in every "data class".
AFAIK at compile time the record is converted into a class so you can consider it a syntactic sugar designed to reduce boilerplate the dev has to type out. If you don't need all the features of a class you define a record as a one-liner instead. If you're content typing out a whole class definition with a ToString override that properly serializes, you can still do that.
Think of records as just classes which the compiler performs additional things automatically. The compiler creates the automatic tostring method and compares values. The real power is that you dont need to write the comparrison logic yourself, just use the record keyword and c# generates that code for you. You can now pass that value to a logger and it will automatically convert to json in the .tostring. i hqve also found the with keyword to copy a record but override specific properies in a single concise statement. Ex var email2 = email1 with { subject = "copy: " + email1.subject }; it reduces your code by a significant amount
Irrelevant code at the end. var c = NuttyIceCream has nothing to do with the subject! You should have displayed that in the case of class references, their address differ! That's why the two objects are different. As opposed to "records", where the addresses of two objects, but with same data, remains the same. In other words, it was relevant to actually display the addresses of both dictionary objects (holding same data), and both the class objects (holding same data).
you're not telling me that one is saying "I don't remember how class comparison works" and surprise, there is a prepared example to show... that "I don't remember how it works" looks pretty much staged, isn't it? besides that, good demo.
Bro, of course it is. They did it in case someone (probably newbie/beginner) gets confused or forgets how it was with "class". Cuz one can confuse and say "Wait, how is that any different with the class?". Reminder only.
Keep them coming, love the short and interactive format
100!!!
I enjoy the simplistic way records is explained and the style of these videos. Awesome.
Using records when ever I can in my projects and they're definitely making things a lot easier :-) DebuggerDisplay straight outta the box, support for attributes, init-setters, etc.
Something else that may deserve its own highlight is the record "with" keyword to copy and override specific properies. That was a gamechanger when i started working with state management in blazor, especially with the init setter
Thank the gods for representation. I have always been the only black dev my entire career. U 2 are awesome!
Lmao stfu
How do you use this in a web world where converting to json, etc. is required?
Cant wait to use this at work. We are still working on c# 7.3 which isnt bad but again, i cant wait
This is interesting. I didn't see the examples print to console in the video. Hey, what do records look like when you serialize them to json?
records are just compiler generated classes
@@TheMannihilator cool, that's what I figured. Many thanks.
2:40 "I've made IceCream abstract" - how? Line 16 says otherwise, since you called it directly? Clarification needed, ta
Understand the Other Records are inheriting from (base) IceCream
internal record IceCream(string Flavour, string Colour) - would make this abstract? or does it need to be Protected? or am I off Base here?
really great
So basically you define the the props, class name and default constructor all in 1 line!? Cool
Yay Ice Cream! Also thanks for the video :)
Great Stuff!!
I don't see the point. Yes, there are classes that only are used for data, but this can change very quickly and you add some methods, logic, and so on to them. Even when they are mostly used for Data, there are often just master classes that are used in every "data class".
AFAIK at compile time the record is converted into a class so you can consider it a syntactic sugar designed to reduce boilerplate the dev has to type out. If you don't need all the features of a class you define a record as a one-liner instead. If you're content typing out a whole class definition with a ToString override that properly serializes, you can still do that.
IMO, classes just used for data should not contain any logic inside them.
If I'm not wrong the record is immutable, while the class is not.
Think of records as just classes which the compiler performs additional things automatically. The compiler creates the automatic tostring method and compares values. The real power is that you dont need to write the comparrison logic yourself, just use the record keyword and c# generates that code for you. You can now pass that value to a logger and it will automatically convert to json in the .tostring. i hqve also found the with keyword to copy a record but override specific properies in a single concise statement. Ex var email2 = email1 with { subject = "copy: " + email1.subject }; it reduces your code by a significant amount
Nice!
One on F# :) pls
Irrelevant code at the end.
var c = NuttyIceCream has nothing to do with the subject!
You should have displayed that in the case of class references, their address differ! That's why the two objects are different. As opposed to "records", where the addresses of two objects, but with same data, remains the same.
In other words, it was relevant to actually display the addresses of both dictionary objects (holding same data), and both the class objects (holding same data).
ayayaya
Первый! Спасибо за видео!
what for plagin in vs has Kendra ?
you're not telling me that one is saying "I don't remember how class comparison works" and surprise, there is a prepared example to show... that "I don't remember how it works" looks pretty much staged, isn't it? besides that, good demo.
Bro, of course it is. They did it in case someone (probably newbie/beginner) gets confused or forgets how it was with "class". Cuz one can confuse and say "Wait, how is that any different with the class?". Reminder only.