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?
try{
// 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:
[HandleProcessCorruptedStateExceptions]
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 http://blogs.msdn.com/adonet/archive/2009/06/15/system-data-oracleclient-update.aspx .
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!
Showing posts with label coders developers competence. Show all posts
Showing posts with label coders developers competence. Show all posts
Sunday, March 14, 2010
Sunday, November 15, 2009
The Criminal Coder
Mr. Reader, in case you have read my previous posts (in case, is the key phrase here), you might be by now thinking me to have lost my psyche. How can I, the ubiquitous attorney of coders on this planet (and Mars) call them evil? Well, to clear out doubts, they are criminals when compared to their superiors (read developers).
How can anyone deglamorise the developer by comparing him with a coder? To me coders are beginners, not absolute beginners, but people who know stuffs, but simply skip to do them, the way it is meant to be done, for laziness or for reasons I fail to understand. It’s not the lack of intellectual capacity that causes them to commit mistakes (read crime), its rather their sluggishness, that makes them do what they want to do, even if that brings about compromise in terms of the code they inject to dilute (read pollute) the system.
The following are some snippets from production code(basic changes made to trim the demo) that I have encountered, in this short span of life (read professional life), and when debugging performance problems in applications, stumbled upon them, and literally felt like giving digital life imprisonment to those who had the audacity to commit these bits!
- Object declarations inside loops: For simple objects I sometimes feel it’s unavoidable to declare objects of types inside a loop, but for complex types, it’s simply a crime. The following code was intended to improve the performance of the application by spawning new threads. Don’t find the need to say more, the code is self explanatory (and yes, gives a boost to performance):
public void UploadXML()
Guess what will be the first problem that your app may run into? An OutOfMemoryException.
{
DataTable dt = GetDataTableFromXML();
for(int i=0; i<dt.Rows.Count; i++)
{
Thread th = new Thread(…);
th.Start();
}
} - Unacceptable usage of If construct: The code is overly expressive of my intent.
for(int i=0; i<1000; i++)
{
if(IsPostBack==false)
{
//Do something here
}
} - Overly expressive logic: I didn’t have the courage to congratulate this guy and kept shut even after seeing this. There were 10 checkboxes in the page and all of them had this. All of them!
//As if Checked return a float
And I have seen even experienced guys do a
bool b = (checkBox.Checked==true? true: false);.ToString()
on a string. What more do you expect from visual studio? Auto-detect these overly expressive conversions? Surely, it would do so, may be in VS 2014! - Global declarations in methods: Why not lazy declare and initialize at the point of usage? We are not in the C age any more (or are we?).
public void Foo()
{
int a, b, c, d;
//50 LOC before using c and d
c=c+1;
} - Avoiding short circuits: Short circuits were provided in the language for some reasons, why not use them to decrease the number of characters typed and let the compiler expand them?
//Enjoy...
Why is the following so uncommon to write amongst few geniuses (strict pun intended)?
bool a = false;
bool b = true;
//do something with b here
if(a ==false)
{
//this is left blank (and yes, intentionally)
}
else
{
if(b == true)
{
//Some code to execute
}
else
{
//Again left blank (intentionally ofcourse)
}
}if(a == true && b==true)
{
//Some code to execute
}
I know you might be thinking who on earth will follow the above pattern and dilute the code, but I have seen it far too many places to avoid mentioning it. Fact is, some coders simply forget the fact that an if can stay without an else. There are innumerable examples and I will certainly update this post to show some really valid places for short circuits, which were completely skipped (and did i mention, knowingly?).
The following is a beautiful extract about the types of competence (or incompetence) that we encounter:
- Unconscious incompetence: You don’t know what you don’t know.
- Conscious incompetence: You know what you don’t know.
- Conscious competence: You know how to do it, but you have to think your way through it.
- Unconscious competence: You can do it without thinking. You just know what to do.
By the way, the reason I termed the above as crime, was because all those coders had live code at their disposal while adding these bits. They simply ignored the style of existing code used in the application and were arrogant enough to not tilt from their style of coding.
To me, that is simply unacceptable and unforgivable crime!
Hail Visual Studio! Save us from the criminal coders!
Subscribe to:
Posts (Atom)