13.07.2015 Views

C# in Depth

C# in Depth

C# in Depth

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The chang<strong>in</strong>g nature of language preferences353more than we might have dreamed about ten years ago, and tools that hold our handsthroughout the development processes… and yet we know that a large proportion ofsoftware projects fail. Often this is due to management failures or even customer failures,but sometimes developers need to take at least some of the blame.Many, many books have been written about why this is the case, and I won’t pretendto be an expert, but I believe that ultimately it comes down to human nature.The vast majority of us are sloppy—and I certa<strong>in</strong>ly <strong>in</strong>clude myself <strong>in</strong> that category.Even when we know that best practices such as unit test<strong>in</strong>g and layered designs willhelp us <strong>in</strong> the long run, we sometimes go for quick fixes that eventually come back tohaunt us.There’s only so much a language or a platform can do to counter this. The onlyway to appeal to laz<strong>in</strong>ess is to make the right th<strong>in</strong>g to do also the easiest one. Someareas make that difficult—it will always seem easier <strong>in</strong> some ways to not write unit teststhan to write them. Quite often break<strong>in</strong>g our design layers (“just for this one littleth<strong>in</strong>g, honest”) really is easier than do<strong>in</strong>g the job properly—temporarily.On the bright side, <strong>C#</strong> 3 and LINQ allow many ideas and goals to be expressedmuch more easily than before, improv<strong>in</strong>g readability while simultaneously speed<strong>in</strong>gup development. If you have the opportunity to use <strong>C#</strong> 3 for pleasure before putt<strong>in</strong>g it<strong>in</strong> a bus<strong>in</strong>ess context, you may well f<strong>in</strong>d yourself be<strong>in</strong>g frustrated at the shacklesimposed when you have to go back to <strong>C#</strong> 2 (or, heaven forbid, <strong>C#</strong> 1). There are somany shortcuts that you may often f<strong>in</strong>d yourself surprised at just how easy it is toachieve what might previously have been a time-consum<strong>in</strong>g goal.Some of the improvements are simply obvious: automatic properties replace severall<strong>in</strong>es of code with a s<strong>in</strong>gle one, at no cost. There’s no need to change the way youth<strong>in</strong>k or how you approach design and development—it’s just a common scenariothat is now more streaml<strong>in</strong>ed.What I f<strong>in</strong>d more <strong>in</strong>terest<strong>in</strong>g are the features that do ask us to take a step back. Theysuggest to us that while we haven’t been do<strong>in</strong>g th<strong>in</strong>gs “wrong,” there may be a better wayof look<strong>in</strong>g at the world. In a few years’ time, we may look back at old code and be amazedat the way we used to develop. Whenever a language evolves, it’s worth ask<strong>in</strong>g what thechanges mean <strong>in</strong> this larger sense. I’ll try to answer that question now, for <strong>C#</strong> 3.13.1 The chang<strong>in</strong>g nature of language preferencesThe changes <strong>in</strong> <strong>C#</strong> 3 haven’t just added more features. They’ve altered the idiom ofthe language, the natural way of express<strong>in</strong>g certa<strong>in</strong> ideas and implement<strong>in</strong>g behavior.These shifts <strong>in</strong> emphasis aren’t limited to <strong>C#</strong>, however—they’re part of what’s happen<strong>in</strong>gwith<strong>in</strong> our <strong>in</strong>dustry as a whole.13.1.1 A more functional emphasisIt would be hard to deny that <strong>C#</strong> has become more functional <strong>in</strong> the move from version2 to version 3. Delegates have been part of <strong>C#</strong> 1 s<strong>in</strong>ce the first version, but theyhave become <strong>in</strong>creas<strong>in</strong>gly convenient to specify and <strong>in</strong>creas<strong>in</strong>gly widely used <strong>in</strong> theframework libraries.Licensed to Rhona Hadida

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

Saved successfully!

Ooh no, something went wrong!