13.07.2015 Views

C# in Depth

C# in Depth

C# in Depth

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

136 CHAPTER 4 Say<strong>in</strong>g noth<strong>in</strong>g with nullable typesdesired short-circuit<strong>in</strong>g functionality for Booleans. A method return<strong>in</strong>g a bool? can beused to obta<strong>in</strong> an <strong>in</strong>itial def<strong>in</strong>itely equal, def<strong>in</strong>itely not equal or unknown result based on thereferences, however. The complete code of PartialComparer on this book’s websiteconta<strong>in</strong>s the appropriate utility method and examples of its use.4.5 SummaryWhen faced with a problem, developers tend to take the easiest short-term solution,even if it’s not particularly elegant. That’s often exactly the right decision—we don’twant to be guilty of overeng<strong>in</strong>eer<strong>in</strong>g, after all. However, it’s always nice when a goodsolution is also the easiest solution.Nullable types solve a very specific problem that only had somewhat ugly solutionsbefore <strong>C#</strong> 2. The features provided are just a better-supported version of a solutionthat was feasible but time-consum<strong>in</strong>g <strong>in</strong> <strong>C#</strong> 1. The comb<strong>in</strong>ation of generics (to avoidcode duplication), CLR support (to provide suitable box<strong>in</strong>g and unbox<strong>in</strong>g behavior),and language support (to provide concise syntax along with convenient conversionsand operators) makes the solution far more compell<strong>in</strong>g than it was previously.It so happens that <strong>in</strong> provid<strong>in</strong>g nullable types, the <strong>C#</strong> and Framework designershave made some other patterns available that just weren’t worth the effort before.We’ve looked at some of them <strong>in</strong> this chapter, and I wouldn’t be at all surprised to seemore of them appear<strong>in</strong>g over time.So far our two new features (generics and nullable types) have addressed areaswhere <strong>in</strong> <strong>C#</strong> 1 we occasionally had to hold our noses due to unpleasant code smells.This pattern cont<strong>in</strong>ues <strong>in</strong> the next chapter, where we discuss the enhancements to delegates.These form an important part of the subtle change of direction of both the <strong>C#</strong>language and the .NET Framework, toward a slightly more functional viewpo<strong>in</strong>t. Thisemphasis is made even clearer <strong>in</strong> <strong>C#</strong> 3, so while we’re not look<strong>in</strong>g at those features quiteyet, the delegate enhancements <strong>in</strong> <strong>C#</strong> 2 act as a bridge between the familiarity of <strong>C#</strong> 1and the potentially revolutionary style of <strong>C#</strong> 3.Licensed to Rhona Hadida

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!