It is truly inspiring that geniuses like him stumble across something as trivial as IsNullOrEmpty function. It just proves that all experts are fundamental humans who might forget small things. Excellent explanation btw. That one line code you have written in the return middle name function is genuinely interesting. Thanks!
@tzadiko4 жыл бұрын
I don't understand what you're saying. IsNullOrEmpty is not in any way new in C#8. It has been around a really only time
@reinterpret_cast4 жыл бұрын
Nope. What it proves is that experts still feel pressure when presenting stuff for broader audience. He wouldn't stumble across it if he were coding alone.
@1dfe-4e68-bd9f3 жыл бұрын
it could happen to anyone. it was happen even with Richard Hendricks). this guy explains very clearly. thanks a lot
@mysteriouslyhandmade5 жыл бұрын
1. Nullable Reference Types 2. Degenerate Object Deconstruction using curly braces 3. NotNullWhen() Attribute 3. Suppressing compiler complaints for possible null reference exception using ! AKA I Know Better :D 4. Controlling Nullable compiler warning per file using #nullable disable/enable operator 5. Try to target .NET3.0 and .Net Standard 2.0
@ChrisBoot5 жыл бұрын
A very interesting talk. Thank you. Who'd have thought a 25 minute video on null would be as engaging as it was!
@bogdangaliceanu63265 жыл бұрын
"dammit operator" is actually the ideal, most memorable name :))
@ahmadkelany5 жыл бұрын
24 minutes talking about nothing 😂 As always, great video.. thank you.
@AsanSultanovNet4 жыл бұрын
24 minutes talking about null.
@andreranulfo-dev86074 жыл бұрын
Literally.
@dhsl5 жыл бұрын
It and switch expressions make me remember PHP, a lot of options to do the same simple thing, it led us to a complete mess most of the times. In 2021 someone will be launching a brand new stricted c# to avoid these type of redundancy and unecessary things. Null coalescing already solve most of the nullable checks in a very elegant way. Nobody needs to learn that an underscore represents a default command in a switch block. If you want to do experiments you should create a new language as F#
@rotgertesla5 жыл бұрын
Well said. This make me worried for the future of the language. I think they are doing a big mistake here.
@Kollegah99975 жыл бұрын
Mads thanks for bringing C# to the next level!
@rotgertesla5 жыл бұрын
11:15 I am sorry to have to say this, but it is a very unreadable synthax: "is { }" . It becomes even worst when you had "{Lenght: var length}". This should never be allowed. Also, Disabling Null check in the middle of a file is very dangerous for future maintenance. This will soon lead to unmaintainable code.
@kestasjk5 жыл бұрын
You need to explain how its “unreadable”
@Chiramisudo4 жыл бұрын
It'll be almost as bad as searching about Discards from a random snippet in some legacy code, lol. Good luck future new devs finding out what the heck that pesky underscore means in your code then legacy code 10 years from now. 😋
@nordy20105 жыл бұрын
Wow! Just... wow! Great job team! This looks really, really awesome! Can't wait to get to use it in a code base at work!
@AdamCollings5 жыл бұрын
Very nice. I can see this forcing me to be less lazy when it comes to null.
@jhbonarius5 жыл бұрын
did he just say "return person?.MiddleName is {Length: var length} ? length : 0" looks nice? I think it reads terrible. Not what I would like to see in maintainable code. But tbh I see so many potential pitfalls in the things that are presented... it's made really easy to write unmaintainable code this way. Just add in some ? and ! and disable some warnings... tadaaa
@FilipCordas5 жыл бұрын
I Agree looks like minimized JavaScript.
@Gabzes5 жыл бұрын
What? The goal of void safety is that the compiler forces you to check for null before you use a variable that is nullable.
@rpesc79185 жыл бұрын
Agreed, previous pattern matching that was released is helpful and reads nice, but this "MiddleName is {Length: var length} ? length : 0" does not read well at all. i'll stick with null coalescing operators and the like
@Chiramisudo4 жыл бұрын
Aye, and totally goes against the "don't be clever" rule. This syntax reeks of clever code and would be difficult for new developers to search on, lol.
@Chiramisudo4 жыл бұрын
I would have much preferred the excruciatingly obvious and self-explanatory SQL syntax: `(person?.MiddleName is not null)`. Elegant, simple, intuitive, and maintainable.
@benjaminmeier83005 жыл бұрын
14:55 thats how I program most of the time ;-)!
@namelastname40774 жыл бұрын
you're fired
@Sathyaish5 жыл бұрын
Oooohhhh! Nullable reference types! Just like Kotlin.
@Sathyaish5 жыл бұрын
So glad to see a video by Mads after so long. Mads, you're beginning to look a bit like a mix of Doug Crockford and Don Box. :-)
@alfiewhitson77265 жыл бұрын
the day that C# introduces multiple return statements to functions is the day that hell freezes over. Unfortunately, today is this day and that's why I switched to C++. Also please add in more pre-compiler stuff. I completely don't understand how you can only have #if statements yet you don't allow for #define. That's really weird, if not bordering on stupid. It'd really make my life, and probably the lives of many others, very much easier if you could just simplify the bloody string variable, at least at the compiler level so that strings are by default stored as a char vector because having to declare a char array, to then pass a string array to a separate string to then cast that new string to a char array to then iterate through that array to then find a single character to change, and to then have to re-write all of that back to my initial string uses up far too much memory and is frankly only going to teach developers how to be greedy when it comes to using stack memory rather than create convenience for them. If the whole idea behind high level languages such as C# is to take the place of lower level languages like C++ and C, eventually firmware development using C# will become more feasible than it is now, therefore heap memory optimisation will become more or less paramount to writing applications that can run efficiently on devices such as the Raspberry Pi were there isn't very much stack memory and heap memory optimisation is considered equally as important as the "system architecture" of the C# compiler and how it distributes memory. Not only this but this adamant culture surrounding stack memory usage is going to bugger up Linux process ID's as well if sub-processes are going to be prioritised/used like this. If that completely becomes common practice, you are going to reach your PID_MAX_LIMIT (in English that's the process ID maximum limit variable in Linux) quicker than you can breathe in. In which case, you'd have to start using GPU's for system process management which destroys the entire fucking purpose of even having a "dedicated co-processor" which should be used for stuff like AI development and openGL stuff correlating to games development and what not : in short, in the foreseeable future, if not now, why should I have to rely on the .net framework's compatability with linux in order to be concerned about inefficient memory management techniques which I should not have to worry about in a high level programming language in order to have a 128/256/512 bit interfaced co-processor manage that when this sort of thing should just be managed by my CPU which should barely even be thinking about going anywhere near my L1 cache. Why are you not worrying about this, when this is going to gratify the absolute tits out of Moore's law which I thought that every hardware manufacturer ever was working against becoming a literal reality ?????!!!!!!!!!!!!
@Chiramisudo4 жыл бұрын
10:33 Excellent! How can we do this prior to 8.0? Something like `(person?.MiddleName is object)` perhaps? Is this logically equivalent?
@avi125 жыл бұрын
11:17 Now C# looks more like a weird version of Kotlin
@derhottemax5 жыл бұрын
Looks great - hopefully eliminates lots of „ if (foo == null) „ verbosity
@cas44254 жыл бұрын
AMAZING
@robertmcalery45745 жыл бұрын
Is this a case where "the road to hell is paved with good intentions"?
@deltaskyhawk5 жыл бұрын
I hate annotations ... it is like a macro language on top of a language. It is not represented in the syntax of the language.
@avi125 жыл бұрын
11:57 Seems like C# borrows some features from JavaScript ECMAScript 2015
@gergelymarko5 жыл бұрын
Option
@tonipihlar45375 жыл бұрын
nullable should have already been in C# 1.0!
@WorstDeveloper4 жыл бұрын
At 15:50 it says that the value passed to the method is not null if the method returns false. But that means that an empty string will return true and trigger the null check as well, right? Which means that it will fail to check for null values when you pass an empty string as an argument.
@everyonesview5 жыл бұрын
Great stuff
@TheSpacecraftX5 жыл бұрын
When you say you weren't allowed to use the "damn it operator" I'm thinking you just weren't allowed to drop f-bombs on the video and used damn as a middle ground.
@Steve-Richter5 жыл бұрын
I would like typescript to have extension methods and c# to have anonymous objects and the spread operator. Is that asking too much?
@zangetsu2k85 жыл бұрын
is it really impossible to make the object reference not set to an instance of an object error to say which property or field was null?
@Classicv55 жыл бұрын
Seems like the first ‘feature’ adds compiler challenges and the subsequent features fix them inelegantly. Can’t believe you think declaring variables in a degenerate object constructor also used as an inverse null check is desirable..
@gaatutube4 жыл бұрын
That weird syntax ... concise but definitely not maintainable. Six months down the line when the boss asks for a new feature, even the original coder would forget what the heck was that supposed to do. KISS is always the best policy.
@UzairAli0015 жыл бұрын
This is some pretty great stuff 👌
@RendernStattGendern5 жыл бұрын
amazing :D
@warrenbuckley32675 жыл бұрын
Did C#8 get released with VS update 16.3?
@vxchin5 жыл бұрын
Yes, but only worked with .NET standard 2.1, and .NET Core 3.0, not .NET Framework.
@BrutusPalmeira4 жыл бұрын
The question is why? Why add so many things to make the code harder to read and maintain?
@ahmadkelany5 жыл бұрын
How can I take advantage of this in an existing winforms application?
@ZintomV14 жыл бұрын
.Net Core 3.1 enables lots of WinForms functionality, with the addition of C# 8 and the nullable annotation. I would suggest migrating your existing project to .Net Core 3.1, you're going to have to do it anyway with .Net 5(next month!) as the .Net Framework has been discontinued.
@holya695 жыл бұрын
My goodness compiler writers are NASA level smart. I
@FBender5 жыл бұрын
12:28 Starts to getting nice? No it does not.
@MovieMash5 жыл бұрын
Usually u think you do ahahaha Good Point!
@alexanderuddfeldt4775 жыл бұрын
Can we have a null-check assign operator? I would like that - anyone else? instead of: OldValue = NewValue ?? OldValue; we do: OldValue =? NewValue; // olny assign if nullable type is not null
@astaregod5 жыл бұрын
I think you're looking for the null-coalescing assignment operator (??=) available in C# 8.0. docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator
@reinterpret_cast4 жыл бұрын
This reminds of `const` in C++: doesn't really guarantee anything and therefore doesn't do what it's supposed to do. C# 7 and 8 are disappointing :(
@mastersaitama30705 жыл бұрын
15:06 🤣🤣🤣
@namelastname40774 жыл бұрын
return person?.MiddleName?.Length ?? 0;
@ZintomV14 жыл бұрын
For you that would return '0' xD
@lollo47115 жыл бұрын
@11:11 "is { } x" is nice! A "!?" as (NOT ??) would be nice too
@deltaskyhawk5 жыл бұрын
A Seinfeld episode.
@DataJuggler5 жыл бұрын
I guess I am paranoid, but I never write code without testing for null. Expecting developers to switch everything is pretty presumptuous on your part. You salary people don't realize how much trouble this is for open source projects.
@TheSpacecraftX5 жыл бұрын
var var everywhere
@logix89695 жыл бұрын
"I'm going to switch into Visual stu..." MY EYES! Dear lord have mercy, who in the right mind uses the light theme?! No but seriously, it's 00:57 at night and this is an LED monitor... so are you trying to kill us? I will find a way to invert the screen colours for now but this is less than ideal!
@niko06795 жыл бұрын
Just simple solution watch this video during day light 😊
@DataJuggler5 жыл бұрын
How do I convince the compiler to do the same thing with my NullHelper class as you do with is null test? I prefer my class because I can test for if (NullHelper.Exists(objects1, object2, etc.) instead of (object1 != null) && (object2 != null), etc. Thanks
@LeutnantJoker5 жыл бұрын
You should be able to mark the parameters of that method with the mentioned NotNullWhen attribute, telling the compiler that if your method returns true, all parameters are confirmed not null.
@ElliotCoil5 жыл бұрын
kotlin nullable syntax is better.
@dergeneralist71065 жыл бұрын
Unnecessary
@charles-y2z6c4 жыл бұрын
Just learned a lot of nothing. Thank you kindly
@gosnooky5 жыл бұрын
I can't use C# because method names with the first letter capitalized messes with my OCD.
@GladerDev5 жыл бұрын
Your loss.
@IsuruKusumal5 жыл бұрын
C# now only getting nullables.. cute
@CambleDCS5 жыл бұрын
C# has had nullables since 2.0. There is a difference between nullable value types and nullable reference types.
@alexm67625 жыл бұрын
too complicated. it would be more easier to just annotate variable to not allow the null, smth like void F(string! arg)
@iqrasafdar57595 жыл бұрын
Now u have to explicitly tell u want null. Its well thought design. Take example of sealed keyword in c#. Its explicitly seal class. Sealed classes are better for performance but few people use why ? Bcs its explicit.... So its good to be explicit.