Sunday, March 14, 2010

Awaiting .NET 4

The .NET Framework version 4.0 is slated for release in April 2010 and everyone seems to be excited about it (everyone by definition includes everyone, so me too). Being the next big release of the framework, there exists number of enhancements and fusion of several new ways of writing old and new smart applications.
I sat down searching for what’s in it for me, the conventional (it’s the most reputable word I could afford for myself, corollary to calling bugs as exceptions) .NET developer for whom writing .NET code is not only about developing cool new smart applications (hardly get to do it thanks to the huge number of legacy and combo apps we need to upgrade day-in day-out) but also write that enlightening code quickly and smartly.
I have made an honest (as if honesty still exists?) attempt to compile what I felt was just so super cool changes to the framework or language in general. Let me #warn you not to expect the entire v4 enhancements from the lines that follow. That won’t ever happen (if I could do that MSDN would be hosted at my local desktop, right?).

1. StringBuilder.Clear(): I was surprised to see this as an addition to the v4 version, as all this time I had expected this member function to be omnipresent in the StringBuilder class (going by the superior and smart design of the .NET framework). Just recently while using it for dynamic html generation (I was using VB9 and still didn’t use VB XML Literals for some bizarre reason, which is indeed classified), I found the absence of this method. The workaround was setting the Length property to 0 which would then clear the contents of the StringBuilder object.
2. String.IsNullOrWhiteSpace(): As is eminent from the name of the method, it checks not only the Null or Empty content of the string object but also helps avoid the use of the Trim() method to make certain we don’t end up with a string of precious whitespaces. An authentic admittance though, I already had added my own extension method in my v3.5 extension methods repository that did verify the absence of both Null and Whitespaces before performing any further string operations and was aptly named String.HasValue(). I am indeed smart (I always knew this, but formally broadcasting it on this DateTime.Now).
3. ServiceProcessInstaller.DelayedAutoStart: While developing Smart Client applications it is a very common requirement to register the application to launch on Windows startup. However, as is eminent, too many applications loading on startup will upsurge the boot time significantly deteriorating the end user experience. This feature comes to the rescue by delaying the start of the application until all other auto-start services have already started.
4. SMTP Client enhancements: Some of the enhancements include enabling SSL mode in application configuration files, specifying heading encoding and most importantly, multiple replying to addresses through MailMessage.ReplyToList().
5. Guid.TryParse(): The TryParse method has now been added to the Guid, Version and Enum types and behaves exactly as its counterparts in other types.
6. 64Bit enhancements: Recognising the mainstream adoption of 64 bit systems the Environment class has been decorated with: Environment.Is64BitProcess and Environment.Is64BitOperatingSystem.
7. IEnumerable<T> everywhere: New overloads of String.Concat() and String.Join() now support IEnumerable elements so that you don’t have to convert them to strings prior to performing Join or Concat operations on them. Also enhanced are several System.IO members like the new File.ReadLines() which returns an IEnumerable<String> rather than a string array. This in turn gives superior performance benefits as its always (read mostly) desirable to read a file one line at time rather than loading the entire content in memory as in File.ReadAllLines().
8. Corrupted State Exceptions: How many times have I written the following?
// Something that should fail, or else why did i incur this try cost, right?
catch(Exception ex)
// Never do anything here. Let them come back to me for fixes (guarantees job security)
In .NET 4.0, corrupted state exceptions will never be caught even if you specify a try… catch block. Even though this is a huge obstacle (a setback or even a crisis) on my attempts towards my job security, yet I welcome it as it encourages writing more stable (in theory) code. Before you start depreciating your intentions to upgrade to .NET 4 for this particular reason, there is a switch that allows you to get the old behavior back by setting the following attribute LegacyCorruptedStateExceptionsPolicy=true in the config file.
This behavior can also be enabled on individual methods with the following attribute:
9. System.Data.OracleClient: Before you plunge into thinking why MS shelled it’s resources to enhance OracleClient, instead of their own franchise SQL Server, there is a surprise awaiting you. OracleClient is available in .NET 4 but marked as deprecated. Don’t believe me? No need to, just help yourself by visiting .
10. VB Auto Implemented Properties and C# Named and Optional Parameters: These are some of the language specific enhancements essentially following Microsoft’s strategy of co-evolving the two languages.
VB now has auto implemented properties thereby reducing the amount of code generated significantly (I hated VB Dev Center for not introducing it in VB9).
C# developers now stand equal by having named and optional parameters (which to me should have been there at least since v2 of the language).  

The list above was never meant to be exhaustive, it does not even attempt to touch the Parallel computing extensions and dynamic (or functional) enhancements to the framework, but it surely addresses most of us, the conventional .NET developers, writing managed code that manages our company, our clients and primarily us!

Happy Coding!

No comments:

Post a Comment