Properties were getting even cleaner in C# 11

  Рет қаралды 57,706

Nick Chapsas

Nick Chapsas

Күн бұрын

Пікірлер: 201
@LeMustache
@LeMustache 2 жыл бұрын
I've been waiting for the "field" feature for so long. I hope it'll finally drop in c# 11 without any issues.
@BittermanAndy
@BittermanAndy 2 жыл бұрын
Agreed. Every time I've had to manually create a separate backing field, a part of my soul has died.
@pfili9306
@pfili9306 2 жыл бұрын
IKR, it's mindblowing how such feature is only added now. It already feels like a natural part of the language, and it's not even there yet.
@KeyboardKrieger
@KeyboardKrieger 2 жыл бұрын
Same here. Don't get why it's not already implemented. It'll kill so many lines of useless code.
@kevindt100
@kevindt100 2 жыл бұрын
Still waiting
@nathan_guyette
@nathan_guyette Жыл бұрын
It's the small things that really stack up over time to make working with the language a pleasure to work with. Semi-Auto-Properties will be a nice addition. Also, I've been watching your videos for some time now and I must say, you provide consistent quality content without a bunch of fluff. Thank you.
@highlanderdante
@highlanderdante 2 жыл бұрын
Usually I'm against feature bloat, but this feature was well thought out and well designed... It's readable and super useful, I'm all for it.
@orangeguy5374
@orangeguy5374 2 жыл бұрын
It’s copied from Kotlin, they didn’t really design much. Still good though
@CrippleX89
@CrippleX89 2 жыл бұрын
@@orangeguy5374 Yeah it was all ctrl+c ctrl+v, nothing to really think about eh? Such lazy programmers, blergh! Let's not start about "copying" features from other programming languages - basically *every* programming language in the history of programming languages took inspiration of others and thank god they did, otherwise learning a new language would be a complete nightmare! I'm really sick of an attitude like yours
@Morten746
@Morten746 2 жыл бұрын
Absolutely love this feature! I’ve always been annoyed about having to clutter my code with the backing fields.
@antonmartyniuk
@antonmartyniuk 2 жыл бұрын
I like the feature. I don't complain as new keywords and features are added in C#. I like that C# is evolving as a language. And you as a developer choose what language feature you want/need to use and which not. If you don't like new features - it's your right, but one day it may become handy for you. Be pragmatic and not dogmatic
@computer9764
@computer9764 2 жыл бұрын
Many different ways to accomplish something scares people off; they mostly want 1 way of doing something "correctly" and not worrying about sifting through 10 different versions of the same code. I agree to an extent; I just don't think it's reasonable to expect C# devs to keep learning what the language is. Not evolving leads to stagnation and extinction. Evolving without the proper footholds can cause weird mutations.
@mindstyler
@mindstyler 2 жыл бұрын
@@computer9764 I think it is very reasonable to expect any human to keep learning.
@computer9764
@computer9764 2 жыл бұрын
@@mindstyler Humans should keep learning, but do you really want to learn a different way to do math every time you do it?
@sandsalamand3763
@sandsalamand3763 2 жыл бұрын
@@computer9764 If I could learn a math technique that would require 1 line to calculate something instead of 5 lines, and still be just as easy to understand, then yes.
@mindstyler
@mindstyler 2 жыл бұрын
@@computer9764 if it's better or easier, absolutely
@Otonium
@Otonium 2 жыл бұрын
I like it. I'm using this functionality with MVVM Community toolkit, and I think it is very nice seeing this as part of the official language specification. Thank you!
@jongeduard
@jongeduard 2 жыл бұрын
MVVM's PropertyChanged-notifications are basically kind of the main-reason to want this feature. Having writing the backing field every time is nothing more than a pain, as it's all just for that notification and nothing more.
@angelmunoz6332
@angelmunoz6332 2 жыл бұрын
How are you doing to use this feature still not released with c# 11 ?
@WinwinLS
@WinwinLS 2 жыл бұрын
It was a pleasant surprise to hear your ask a question at the C# 11 talk at NDC CPH, and I instantly recognized your voice! Hope you had a great conference!
@seekersofwisdom85
@seekersofwisdom85 2 жыл бұрын
Nick will be most famous youtuber in this domain in 5 years.
@thehuggz-i9k
@thehuggz-i9k 2 жыл бұрын
This is super cool and will definitely make it's way into my daily to day. I've been wanting these property changes for YEARS. It didn't take much playing around with properties to realize their shortcomings and come up with a laundry list of improvements. The real crime is that it's taken MS 20 years to get their act together and make them awesome. Thanks for the great work Nick!
@joga_bonito_aro
@joga_bonito_aro 2 жыл бұрын
Very nice! And also the fact that Interfaces got overhault too, (static abstract, operator for something like IIsNumber) it just keeps getting better and better!
@Hugo-pj4bm
@Hugo-pj4bm 2 жыл бұрын
The new way to do lazy inits looks damn clean, I love it!
@kevindt100
@kevindt100 2 жыл бұрын
Yesss finally. I think i've been crying about this for a year now.
@evanboltsis
@evanboltsis 2 жыл бұрын
The new features are awesome. I saw Mads what's next in C# 11 video and got excited.
@RoughSubset
@RoughSubset 2 жыл бұрын
What a time to be alive as a C# developer!
@ryan-heath
@ryan-heath 2 жыл бұрын
Makes resharper and the like more and more important to discover when to use / apply these new concepts, until they become your second nature.
@mkwpaul
@mkwpaul 2 жыл бұрын
This definitely makes the language a bit more complicated again... but I think this is totally worth it. Boilerplate is the bane of larger software projects and if they're gonna have properties as a language feature for abstraction then it makes sense that they'd go all the way with making them as concise as possible. Especially in WPF Projects that heavily depend on the INotifyPropertyChanged interface this will be a godsend. Good stuff.
@AlFasGD
@AlFasGD 2 жыл бұрын
Every single adjustment makes the language more complicated, I hate seeing this "argument" everywhere. Complicating the language further is not a deal, as long as the design is well-defined, looks clean and fitting, and works seamlessly.
@DaddyFrosty
@DaddyFrosty 2 жыл бұрын
@@AlFasGD great take, also people make the point that it will be harder for beginners, but I disagree. I came from c++ for me it was a complete mindfuck but eventually you start loving the power of the language and really c# magic is not complicated. But it was very unclear that a property is a pair of functions pointing to a field.
@AlFasGD
@AlFasGD 2 жыл бұрын
The main difference between C++ and C# is that C# has more concepts fundamentally built into it from the very beginning, allowing it to expand further without much interference. C++ has adopted several strange symbol combinations that make it even harder to import new features, and the syntax that is being reserved becomes increasingly more obscene.
@TampaCEO
@TampaCEO 2 жыл бұрын
Anything that allows me to write LESS CODE would be considered a win. I love condensed code that can be crushed to a single line. This is probably why I loved Lambda expressions when they first came out. Thanks for the update! Can't wait to "wow" my coworkers. :-)
@leonardomoreno23
@leonardomoreno23 2 жыл бұрын
It is right, something I feel like 'omg another possible interview question I should learn' but this particular feature looks handy.
@KlaytonCavalcante
@KlaytonCavalcante 2 жыл бұрын
This is a feature that is long missed. It was always strange to me that I had "value" without having to declare something like "set(value) { _field = value; }" but had no "field" and thus having to always use an explicit backing field. Now I'm in peace. hahaha
@therealgamer8150
@therealgamer8150 2 жыл бұрын
What I like about these features is that they are very optional. You can do it all manually if you want and these are unlikely to ever get in your way if you don’t want to use them. So I’m not concerned about the language becoming bloated. However, it’s good that we have videos like yours explaining how they work. It took me ages to understand the difference between a property and a field
@lolyasuo1235
@lolyasuo1235 2 жыл бұрын
This is definitely something people gona use. We were waiting for something like this.
@alexwexov4298
@alexwexov4298 2 жыл бұрын
These feature videos are amazing !
@serus164
@serus164 2 жыл бұрын
Could you do a video about lock keyword or threads synchronization in general?
@VaAlexander
@VaAlexander 2 жыл бұрын
OnPropertyChanged is right on spot! Was waiting for it for so long to get rid of backing fields
@pdevito
@pdevito 2 жыл бұрын
So siked for this! Was bummed when it dropped from c#10, so glad it made it in now.
@jongeduard
@jongeduard 2 жыл бұрын
Very usefull. Like others say: feels like something we already wanted for a long time. It's too often that small amounts of logic, for example the OnPropertyChanged()-thing, are needed. And in such a case it always feels as a waste to also need to add the whole other ceremony with the backing field. Furthermore I am also VERY happy that they did not force the underscore-fieldname notation as an automatic thing, but that they came up with just a keyword which has always the same. Most important thing here is that I am not particulary happy with the whole underscore usage at all for backing fields that many (most?) people do today (including Microsoft guys themselves), but not everyone (others, including me, have learned to prefer this-notation), while it kind of violates earlier guideliness in the past from Microsoft as well (to never prefix things, doing so was always considered a bad practice). So hopefully it kinda ends the need for that debate as well.
@AlanDarkworld
@AlanDarkworld 2 жыл бұрын
Heeey C# finally gets the "field" soft-keyword! No more fiddling with underscore-prefixed duplicates! That's great news.
@slatki05
@slatki05 2 жыл бұрын
I'm sure that not many people know that Kotlin has had those features for a very long time. It's such an underrated programming language...
@JustArion
@JustArion 2 жыл бұрын
I love it, now my wish for extension properties / events is all that is left in my wishlist
@dimalisovyk5277
@dimalisovyk5277 2 жыл бұрын
Cool stuff. I wish they added it from the very first version, cause now we have 10 ways to define a property
@kemsekov6331
@kemsekov6331 2 жыл бұрын
I was sceptical about another "new feature" but this one seems reasonable good and intuitively makes sense.
@techwatching
@techwatching 2 жыл бұрын
I love all these future fatures. I don't think having more and more features is a bad thing for C#. Everyone can choose to use them or not, but I think it brings value to a lot of people.
@davidreis5086
@davidreis5086 2 жыл бұрын
this is something i wanted to have a time ago. it's nice they're implementing this
@DaddyFrosty
@DaddyFrosty 2 жыл бұрын
Great feature and yes this is so spot on. I have too much stuff on a virtual prop that is just a lambda getter to a semi expensive function. Adding this as a feature is a godsend. On top of that I honestly think there should be a prop keyword for just default get set, props are needed a lot of the time for various reasons and it would be way more clean.
@asdfxyz_randomname2133
@asdfxyz_randomname2133 2 жыл бұрын
How is 3:45 valid code in C# 11? There is a backing field _fullname and the compiler does kinda know about it because of the setter, but he can't simply infer it from the setter in more complicated cases, because there could be multiple or more complex "backing fields". For example the following: private int _year; private int _month; private int _day; public DateTime Date { get; set { (_year, _month, _day) = (value.Year, value.Month, value.Day); //or something along the line if I made a mistake here, you get the idea } } What would the compiler assume as the backing field? How would it handle such cases? Other than that, I do like the field keyword.
@nickchapsas
@nickchapsas 2 жыл бұрын
The compiler generated backing field is always the same type as the property. Ignore the one I explicitly specified, I just didn’t delete it yet at that point in the video. In your example your setter will use custom fields but the getter still points to the DateTime generated backing field
@asdfxyz_randomname2133
@asdfxyz_randomname2133 2 жыл бұрын
@@nickchapsas ah, so the setter will assign to the keyword "field", which explains how the getter knows about that field.
@vladkorsak2163
@vladkorsak2163 2 жыл бұрын
Thank you, Nick for this awesome content! We love it.
@danielguimaraesscatigno4236
@danielguimaraesscatigno4236 2 жыл бұрын
I always wondered why Properties needed the attribute declaration, finally they made it possible to get rid of attributes when working with properties
@samysammour9983
@samysammour9983 2 жыл бұрын
I really think it is a very helpful short way of doing properties. However, it will be rarely used as we most of the time use simple properties but it is nice to still have the option in cases needed
@castormann
@castormann 2 жыл бұрын
This is so great. I love the .NET team
@JeffGraw
@JeffGraw 2 жыл бұрын
Love this. I hate having to create backing fields that should only be accessed by a property yet are still visible to the entire class. You can do the lazily initialized expression bodied property thing already, although you need to use a backing field. At first blush, needing to create an extra method feels less evil than needing to create an extra field, since you can't mutate the method like you can the field (although the method itself could mutate state, ugh). That said, public string FullName => field ??= new Func(() => "nick chapsas").Invoke(); is possible, which finally encapsulates everything except the actual output of the property from the rest of the class. The syntax is rather unfortunate, however. Edit: A better way to do multi-line lazy getter-only auto property initialization is to ditch the expression bodied access altogether and just put all the logic in the getter. Eg: public string FullName { get { if (field != null) return field; var expensiveStuff = "nick chapsas"; return field = expensiveStuff; } }
@multiHappyHacker
@multiHappyHacker 2 жыл бұрын
They are great options to have.
@bambosa4952
@bambosa4952 2 жыл бұрын
I really like this feature, it also gives you the option to pass an auto property by ref (sort of) if you just cache the backing field value and pass it's reference.
@phizc
@phizc 2 жыл бұрын
Is that supported? I mean, it should, but I don't know if it is (haven't checked). You'd do public ref AddressStruct { get => ref field; }
@bambosa4952
@bambosa4952 2 жыл бұрын
@@phizc No because the a property can't be a ref. You would just be able to pass the reference to something that cares about it on the getter or setter. It has limited uses but is something you wouldn't have been able to do without first creating your own backing field.
@phizc
@phizc 2 жыл бұрын
@@bambosa4952 I know that you need a backing field, and since the 'field' keyword is a way to get the backing field of the auto property, that'd be how you'd get the reference of the backing field. I just tested it in sharplab. It doesn't work, but that's because it creates a readonly backing field. That might be improved I think. Edit: ignore that I made the Addr struct a record struct. Bad example since it's immutable. I wrote it that way since I'm a phone and it's shorter.. Anyway, this works: public record struct Addr( string Street, string City); Addr _Address; public ref Addr Address => ref _Addr;
@bambosa4952
@bambosa4952 2 жыл бұрын
@@phizc Awesome, that's interesting and good to know. Also you could stop the field being readonly by providing a setter on your property. A get only auto property or one with init only setter will provide a readonly backing field.
@phizc
@phizc 2 жыл бұрын
@@bambosa4952 unfortunately not.. ref properties can't have setters.
@burtonrodman
@burtonrodman 2 жыл бұрын
all great moves in my opinion. and clean
@swedishprogrammer
@swedishprogrammer 2 жыл бұрын
This feature is great! 🙏
@TizzyT455
@TizzyT455 2 жыл бұрын
I was needing the field keyword when I implemented my database so that users wouldn't need to write so much boiler, I ultimately redesigned my database but this definitely would've made the implementation work.
@shenlong3879
@shenlong3879 2 жыл бұрын
I love all these recent C# improvements. It's going to take me a while to learn them all and get used to them but a lot of them, especially with properties address things that have always annoyed me. I work with a lot of new technologies all the time so I constantly have to learn any evolve anyway. I just have to catch up with it all in the near future.
@JavierAcrich
@JavierAcrich 2 жыл бұрын
Was this finally implemented? I can't get it to work in VS17.4.0 preview 2.1 targeting net7. The field keyword does not compile for me.
@11clocky
@11clocky 2 жыл бұрын
The feature was pushed to C# 12.
@hodor2704
@hodor2704 2 жыл бұрын
I am embracing each one of the new C# features. I haven't learnt them all yet but I will. I don't think it's right thing to point to new features and say "do we have to learn all these stuff?". If I am not able to learn some new features of the main language I am using to earn my living, maybe I should consider another profession. Each one of them are to make our lives easier.
@LeMustache
@LeMustache 2 жыл бұрын
Did they decide to delay this feature? I can't see it in any "coming in c# 11" articles.
@phizc
@phizc 2 жыл бұрын
Regarding more keywords: as long as they're context sensitive it doesn't matter. Counter-example: in/out. You can't have variables with these names because they're keywords, but the keywords can only be used in specific places such as a modifier for method arguments and generic arguments, so they should not be treated as keywords anywhere else. Edit: I'm guessing that field will be a context sensitive keyword and only be treated as such in properties. Like "value". You can use that as a variable name or argument even though it is a keyword in properties. Regarding more ways of doing things that you need to keep track of: You really don't. You can keep using any of the old ways. Nothing is forcing you to use any new features. Only if you encounter it in somebody else's code would you have to understand it, and it looks quite self explanatory, and if not there's Google.
@Masterrunescapeer
@Masterrunescapeer 2 жыл бұрын
This is a great feature, was kind of forced into restructuring for lazy initialization for some expensive DB requests, this will make it a bit simpler for the next person reading it.
@thaveeshakannangara9221
@thaveeshakannangara9221 2 жыл бұрын
love the content you make, keep it up.
@crack8160
@crack8160 2 жыл бұрын
as long as you can write it like you used to, it's all good.
@lgsscout196
@lgsscout196 2 жыл бұрын
whoever complains about it, just do it the old way. its a feature to provide shortcuts, to write things faster and cleaner. its not a obligation to use it.
@Bliss467
@Bliss467 2 жыл бұрын
as long as the new feature is idiomatic, i'm fine with it. you can intuit what `field` does in both property get/set and lazy contexts do. similarly you could intuit what the argument can't be null syntax was doing.
@Taneth
@Taneth 2 жыл бұрын
Yes, been waiting for this one.
@riten
@riten 2 жыл бұрын
Well, there isn't really a reason for people to get angry at this. It is just syntax sugar. You are not losing performance for not remembering this, just convenience.
@AiguretDuren
@AiguretDuren 2 жыл бұрын
Incredible feature!
@MetaArcher
@MetaArcher 2 жыл бұрын
this looks awesome, finally!
@luca-dallavalle
@luca-dallavalle 2 жыл бұрын
Very informative, thanks!
@nitrous1001
@nitrous1001 2 жыл бұрын
shorter than Lazy thats for sure!
@benamiel6180
@benamiel6180 2 жыл бұрын
Nice! In eight years from now maybe schools will use it too
@figloalds
@figloalds 2 жыл бұрын
Damn this is so good, FINALLY.
@vadimardasov4919
@vadimardasov4919 2 жыл бұрын
When you are working with C# and Kotlin at the same time and it seems fanny comparing: 1. C# approach will come soon: public string SomeLazyProp => fields ??= SomeHardStuff(); public string SomeHardStuff() { return "Something"; } And 2. Kotlin approach already exists: val someLazyProp: String lazy { "Something" } C# is a great language and I love it but sometimes he can spy on others
@computer9764
@computer9764 2 жыл бұрын
I like it. I want easy, baked-in reactivity, though 😉
@Crozz22
@Crozz22 2 жыл бұрын
As long as new features solves a problem or makes code shorter and more expressive, I would call it the opposite of bloat.
@d347hm4n
@d347hm4n 2 жыл бұрын
With the OnPropertyChanged example, often the implementation uses [CallerMemberName] or a string. Would nameof(field) give you FullName or would it be the backing field?
@anderskehlet4196
@anderskehlet4196 2 жыл бұрын
CallerMemberName should work as normal. If it's called in a property, then it's the name of the property that gets passed. nameof(field) doesn't seem to be allowed at all. Makes sense since generated fields have unspeakable names anyway.
@DemoBytom
@DemoBytom 2 жыл бұрын
Is that lazy init thread safe? Meaning can two separate threads invoke the InefficientStuff() method if they happen to be triggered at the same time, or is there sam built-in lock in the null check + assignement? I assume it's not thread safe, but I'm not sure.
@k3daevin
@k3daevin 2 жыл бұрын
Had the same thoughts. Looks nice but I doubt it being thread safe.
@GumbootMan
@GumbootMan 2 жыл бұрын
That part isn't new, it's just short for: field = field ?? InefficientMethod(); which sets field to the method return value if field is null, otherwise it sets field equal to itself. The only new C# 11 part is that 'field' refers to the backing field of the property. Hence I can say with confidence that it is *not* thread-safe, sorry!
@nickchapsas
@nickchapsas 2 жыл бұрын
It is not thread safe no. You can make it thread safe by wrapping it in Lazy
@Rothbardo
@Rothbardo 2 жыл бұрын
How does he get that compiled code view to the right? Anyone have a video on that? It seems super useful for beginners.
@A.V.F.P
@A.V.F.P 2 жыл бұрын
As far as I know you can write string prop {get;} = ComputingVal(); To have the exact behavior but with much cleaner code, also just a little bit faster
@nickchapsas
@nickchapsas 2 жыл бұрын
No that's not valid C# code. It only works for static members, which makes it very nieche. Non static members cannot be used with that syntax
@limbique
@limbique Жыл бұрын
Does the `InefficientStuff` needs to be static?
@davidkoren1642
@davidkoren1642 2 жыл бұрын
in the trasnlator how can you call a variable name with these:"" i.e. string k__BackingField
@conway9214
@conway9214 2 жыл бұрын
What would happen many threads invoked the getter at the same time?
@ianmarteens
@ianmarteens 2 жыл бұрын
Is that “lazy assignment” thread-safe?
@evilpigeon4976
@evilpigeon4976 2 жыл бұрын
I love this feature and I'm glad they went with "field" instead of an underscore, which is a gripe I have with switch expressions.
@rafalz3987
@rafalz3987 9 ай бұрын
Is this available in Visual Studio?
@maurosampietro9900
@maurosampietro9900 2 жыл бұрын
New features are actually useful, the problem is in real world scenarios is not easy to just drop support to old runtimes and embrace these new features. and/or it’s not easy/feasible/possible to #if NETVERSION and take advantage of them. What do you usually do in that case? I’m currently supporting .net45 and everything in between through net60 in my projects
@drewkillion2812
@drewkillion2812 2 жыл бұрын
People that worry about too many changing features in c# haven't worked with CSS.
@RasmusSchultz
@RasmusSchultz 2 жыл бұрын
I wish they had started with a complete, coherent design for classes, constructors, fields and properties - every new feature solves for one particular problem and adds more complexity, more choices, more pros and cons you have to weigh for every addition to your codebase, more inconsistencies among codebases, and more time wasted debating, reviewing opinionated pull requests for alignment with your personal code standards and unimportant details. Simply put, it's already more complex than it should have been. But even then, many things still feel rough - like for one, still having to add boilerplate constructors for simple models. I can't even honestly suggest a way out of this situation, because much of the inherent language complexity is in the actual VM and runtime. Deprecations maybe? But of course you'd still need to come up with a complete and coherent design that is backwards compatible with existing syntax. I'm afraid it's too late for C# to dig itself out of the hole it's in. It's an okay language, as it is - but much like PHP, I think it's too late for it to ever become a great language. At some point, all you can do (short of starting over) is to step on things, and step harder, and eventually everything ends up bent out of shape. Perhaps something like Kotlin for C# could get this language out of it's rut? Of course that's still like starting over, in a sense. But maybe that's what's needed. A new syntax with a simple, complete, coherent, more opinionated design? Similar semantics, better ergonomics, stricter type checking, etc... It's a lot of work though - perhaps even more work than just building an entirely new language... 🤷‍♂️
@fleedum
@fleedum 2 жыл бұрын
What would "public string FullName ??= InefficientStuff()" do? Or invalid?
@mindstyler
@mindstyler 2 жыл бұрын
Then it's just a field, not a property
@fleedum
@fleedum 2 жыл бұрын
@@mindstyler Care to explain the difference? I'm here to learn.
@mindstyler
@mindstyler 2 жыл бұрын
@@fleedum no? it's a public field. To learn the difference, google is your friend.
@zabustifu
@zabustifu 2 жыл бұрын
In general, I don't think you really have to keep in mind all the new ways to do things, as thankfully, your IDE, Resharper or whatever will remind you when you forget.
@semuhphor
@semuhphor 2 жыл бұрын
Am I missing something, or is there the possibility of unexpected results? I call the prop to get a field from a function that is calculated the first time, but subsequently it returns only that value ... but later the underlying function that returned the initial value returns something else.... ?
@andrewaggb
@andrewaggb 2 жыл бұрын
I run into these situations all the time so I'll use it regularly. Really a shame it wasn't in the language years ago.
@Andrew90046zero
@Andrew90046zero 2 жыл бұрын
I had no idea that field thing for attributes existed and that’s interesting! Definitely some use cases i can think of with that. Are there any other ‘attribute specifiers’ that i should know about? I know there is the ‘assembly’ and ‘module’.
@phizc
@phizc 2 жыл бұрын
'return' is one. It affects the return value of a method.
@Ashalmawia
@Ashalmawia Жыл бұрын
I still dream (in vain) of the day when properties are first-class... so much effort in C# goes into working around the fact that they can't be treated as a single thing.
@goodoleme747
@goodoleme747 2 жыл бұрын
Oh that’s awesome
@MrNickP
@MrNickP 2 жыл бұрын
Everything they do to make writing code easier makes reading code more complex.
@minecraftermad
@minecraftermad 2 жыл бұрын
The problem with bloat isnt that theres more stuff but that there's more stuff that doesn't bring anything new or worst case scenario makes code longer or less legible. The reason why c++ bloat is bad is because the features seem like an afterthought where as here it's fully integrated.
@MartinMaat
@MartinMaat 2 жыл бұрын
Why is field not colored blue, like value? It is a reserved keyword, not an explicitly declared member (much like value).
@phizc
@phizc 2 жыл бұрын
Limitation of sharplab. It will be blue in VS/Rider/VS Code when it's ready for use.
@rw7545
@rw7545 8 ай бұрын
Was this feature dropped? I can't find trace of it in .NET 8
@jeroeno_boy
@jeroeno_boy 2 жыл бұрын
I will definitely use this…. When unity supports C# 11
@rodrigoflorex
@rodrigoflorex 2 жыл бұрын
Great feature! It was really annoying to put logic in properties because of the boilerplate code. I'd rather have the tool and not use it than need it and not have it.
@polares8187
@polares8187 2 жыл бұрын
C# seems more scary every single day
@flyingmadpakke
@flyingmadpakke 2 жыл бұрын
Once, many people had learn traditional Chinese with over 50.000 symbols, today we have to learn modern C# with over 50.000 keywords, I don't see the issue here.
@Psykorr
@Psykorr 2 жыл бұрын
Hmm I don't know.. I never use properties like that. Well I avoid having rong running things there. A property should just be a quick way to get a value as currently is in memory or set it. Some lookup or quick calculation is fine, of course, but getting or setting things in a data base or calling a remote instance from your property is terribly bad imo. Because most of the time reading a code base you assume this expression 'var something = object.Property;' you'd expect something to be assigned what ever Property has at the moment, not that this property will start calling remote code or something. Then you have to start double checking all the properties if they also do this. Compare to this' var something = repo.GetAllSomething();' But I don't know, it's just one feature, I would like to know if you can see the whole design doc or some design goal overall, like what is the goal of the language in 5 or 10 years. Now I just get the feeling they just want to get in popular things as they pop up here and there.. It kind of feels a little desperate and short sighted so there fore I would like to see if there is actually a long term plan for all these features
@lordicemaniac
@lordicemaniac 2 жыл бұрын
but is the new lazy way to set initial value thread safe?
@PetrVejchoda
@PetrVejchoda 2 жыл бұрын
thats likable
@krzysztofzon8661
@krzysztofzon8661 2 жыл бұрын
The ,,field'' keyword feature is great, it will make the code a lot cleaner, but something seems off with the ,,??=" keyword. I think that logic like that should be more verbose, but mayby it's just my habit
@amichelis
@amichelis 2 жыл бұрын
Okay, excluding the field keyword, I've already used many times ??= Keyword. It's not a new thing. I don't know if it works differently now, but the syntax itself was valid before
@nickchapsas
@nickchapsas 2 жыл бұрын
Never said it wasn't. You just no longer need an explicitly defined backing field anymore
@theycallmejpj
@theycallmejpj 2 жыл бұрын
Lol, to me C#11 is a type of chord. I thought this was a piano video. The algorithm got tricked!
The weirdest C# 11 feature but also the best one
10:22
Nick Chapsas
Рет қаралды 50 М.
Are events in C# even relevant anymore?
16:19
Nick Chapsas
Рет қаралды 171 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
Why is Microsoft Harming .NET Open-Source?
9:37
Nick Chapsas
Рет қаралды 6 М.
The Right Way To Return API Errors in .NET
10:40
Nick Chapsas
Рет қаралды 65 М.
How to Measure Time Correctly in .NET
9:43
Nick Chapsas
Рет қаралды 50 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 264 М.
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 148 М.
Why I won’t need constructors anymore in C# 11
9:39
Nick Chapsas
Рет қаралды 135 М.
Why all your classes should be sealed by default in C#
11:43
Nick Chapsas
Рет қаралды 93 М.
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 261 М.
JSON support gets a major missing feature in .NET 7
9:53
Nick Chapsas
Рет қаралды 50 М.
When You Shouldn't Use Await Async in .NET
7:51
Nick Chapsas
Рет қаралды 50 М.