Page 23 - MSDN Magazine, February 2018
P. 23

multicolor
hit-
highlighting
easy
options
®
Wrapping Up
The introduction of the nullability modifier for reference types doesn’t introduce a new type. Reference types are still nullable and compiling string? results in IL that’s still just System.String. The difference at the IL level is the decoration of nullable modi- fied types with an attribute of:
System.Runtime.CompilerServices.NullableAttribute
In so doing, downstream compiles can continue to leverage the declared intent. Furthermore, assuming the attribute is avail- able, earlier versions of C# can still reference C# 8.0-compiled libraries—albeit without any nullability improvements. Most important, this means that existing APIs (such as the .NET API) can be updated with nullable metadata without breaking the API. In addition, it means there’s no support for overloading based on the nullability modifier.
The transition of traditionally nullable declarations to non- nullable will initially introduce a significant number of warnings.
There’s one unfortunate consequence to enhancing null handling in C# 8.0. The transition of traditionally nullable declarations to non-nullable will initially introduce a significant number of warn- ings. While this is unfortunate, I believe that a reasonable balance has been maintained between irritation and improving one’s code:
• Warning you to remove a null assignment to a non-nullable type potentially eliminates a bug because a value is no longer null when it shouldn’t be.
• Alternatively, adding a nullable modifier improves your code by being more explicit about your intent.
• Over time the impedance mismatch between nullable updated code and older code will dissolve, decreasing the NullReferenceException bugs that used to occur.
• The nullability feature is off by default on existing projects so you can delay dealing with it until a time of your choosing. In the end you have more robust code. For cases where you know better than the compiler, you can use the ! operator (declaring,“Trustme,I’maprogrammer.”)likeacast. n
Mark Michaelis is founder of IntelliTect, where he serves as its chief technical ar- chitect and trainer. For nearly two decades he has been a Microsoft MVP, and a Microsoft Regional Director since 2007. Michaelis serves on several Microsoft software design review teams, including C#, Microsoft Azure, SharePoint and Visual Studio ALM. He speaks at developer conferences and has written numerous books, including his most recent, “Essential C# 7.0 (6th Edition)” (itl.tc/EssentialCSharp). Contact him on Facebook at facebook.com/ Mark.Michaelis, on his blog at IntelliTect.com/Mark, on Twitter: @markmichaelis or via e-mail at mark@IntelliTect.com.
Thanks to the following Microsoft technical experts for reviewing this article: Kevin Bost, Grant Ericson, Tom Faust, Mads Torgersen
msdnmagazine.com
Instantly Search Terabytes of Data
across a desktop, network, Internet or Intranet site with dtSearch enterprise and developer products
Over 25 search features, with
dtSearch’s document filters support popular file types, emails with multilevel attachments, databases, web data
Developers:
• APIs for .NET, Java and C++
• SDKs for Windows, UWP, Linux, Mac and Android
• See dtSearch.com for articles on faceted search, advanced data classification, working with SQL, NoSQL & other DBs, MS Azure, etc.
Visit dtSearch.com for
• hundreds of reviews and case studies • fully-functional evaluations
The Smart Choice for Text Retrieval® since 1991
dtSearch.com 1-800-IT-FINDS


































































































   21   22   23   24   25