DEV Community

Cover image for How C# 8 Helps Software Quality

How C# 8 Helps Software Quality

Matt Eland on October 09, 2019

.NET Core 3 is a major milestone in .NET and with it, brings some exciting new functionality - most notably with the arrival of C# 8. I want to of...
Collapse
 
jeremycmorgan profile image
Jeremy Morgan • Edited

Love this writeup, and I agree 100%. "Syntax sugar" on the surface appears to only benefit the creator of the software, but over time once it becomes status quo it makes for less code and greater readability for the next person working on it.

Remember we don't write code for compilers/runtimes we write code for humans. The more efficient, clean, and readable the code is the less chance for mistakes to creep in.

Nice article Matt.

Collapse
 
integerman profile image
Matt Eland

That's a huge part of why I'm learning F#. I believe the language's conciseness improves software quality significantly by reducing potential points of failure and increasing the amount of meaningful code that can be focused on (in addition to the other quality benefits it offers via null handling, preferring immutable objects, etc).

Collapse
 
cubiclebuddha profile image
Cubicle Buddha

Great article as usual! So have you tried using Entity Framework Core (EFCore) with the non-nullable references?

I’m wondering if that improves things.

For instance, in some ORMs a findById operation returns T but in reality, a findByIdoperation always has the potential to not find the item. So the correct return type is T | null.

It’s just another good example of communicating intent.

Collapse
 
psy_aviah profile image
Psy'Aviah

generics and nullable won't play nicely
I yet have to experiment, but bear in mind that this nullable feature when used on generics requires you to express whether the generic type is either a reference type or a value type (aka where T: class or where T: struct). And since you can't combine both constraints - well... :) It leaves me wondering ;)

Collapse
 
cubiclebuddha profile image
Cubicle Buddha

Interesting. I’d love to hear your findings after you experiment. If you write an article, please link it here. :)

Collapse
 
davjvo profile image
Davmi Jose Valdez Ogando

Damn this one hit me right when I needed it. Today at work I saw some vs suggestion to change how my switch worked and replaced it for the new sintax, I wrote a note to look it up later and found this post that gave much more than I was looking for. Great post

Collapse
 
integerman profile image
Matt Eland

Be sure to check out the link to the Microsoft What's New in C# 8 article, because it also includes tupled switch expressions, which are pretty cool too, but I didn't cover them in this article.

Collapse
 
psy_aviah profile image
Psy'Aviah

I love all the things introduced, and I agree, it promotes readibility.

However Nullable has my head scratching quite a bit.
C#8.0 introduces a way to deal with null, yet it also provides numerous escape roads. So I advise not to use it, explained in the article why not to do it...

Whilst I admire the efforts that have gone into making the world more null-safe, I fear that all the escape roads given make this feature not only useless but dangerous and confusing. Crucially this is where the feature fails massively in its goal to get rid of null reference exceptions. In fact, you could argue it makes it even worse as it masks, gives you exit-strategies (like goto).

Collapse
 
jefferson8motta profile image
Jefferson Motta

Microsoft has a history of killing old technologies like these recent technologies were killed in
.NET Core 3.0:

• ASP.NET Web Forms
• ASP.NET MVC
• WCF Server
• Windows Workflow
• AppDomains
• Code Access Security
 
(c-sharpcorner.com/article/future-o...
 
All community developed many codes with .NET Framework 4.x that is good and don't need to be upgraded to .NET Core x.x and why we need stop in time using .NET Framework if c# is opensource? The Visual Studio team must have some work to make c# 8.0 compatible.
 
We don't want to throw our code in the trash of time. We will design in .NET Core 3.x, 5, but our current code must not be forgotten.
 
Based on this I created today a Facebook page to POST protests against Microsoft and call the community to demand c# 8.0 works with .NET Framework 4.x.

Share, like, comment:

facebook.com/CSharp-8-to-Microsoft...

Collapse
 
yv989c profile image
yv989c

Great article, thanks. I do like the "nullable reference types" naming though. I think the implementation plays well with the existing "nullable value types" paradigm.

Collapse
 
integerman profile image
Matt Eland

I'm oddly picky on names. I'm okay with the term when saying that string? is what's new, as that is a nullable ref type. But the reality is we've been living with nullable ref types since the betas.

Just my own neuroses. Thanks for the feedback!

Collapse
 
atulverma84 profile image
atulverma84

Nice article Matt.

Collapse
 
integerman profile image
Matt Eland

Thanks! This one blew up today on Medium and I'm not sure why. Always nice to have writing benefit others.

Collapse
 
apriftis profile image
Alexandros Priftis

Thank you Matt. Your article is really great!

Collapse
 
pareshjoshi profile image
Paresh • Edited
Readonly Members

this looks similar to the old c++ way of marking method as const

int GetValue() const {return value;}

where value is a member field.