Partilhar via


Best V2.0 feature in the .NET Framework: A BCL Poll [Kit George]

OK, in response to Jeff Atwood’s questions:

“If you had to pick one, what is the single most important feature in 2.0 that developers should be experimenting with and exploiting as soon as they get their hands on it?

What features in 2.0 *directly* address specific problems you've see in average developer code written in 1.0? In other words, how is 2.0 going to keep me from making the same stupid mistakes? (or at least encourage me not to..)”

Instead of answering just on my own, I took a poll for answers. You’ll notice a couple of themes (and Ravi Krishnaswamy gave such an indepth response with his answer of ‘SafeHandle’ that it deserved it’s own entry). You’ll also notice that we’re not biased at all, and we didn’t ever respond with either a BCL, or CLR answer.

Kit George (Program Manager)

Single most important V2.0 feature: I’ve gotta say it’s generics. Working on the BCL I’m mostly focused on coding style I guess, and I see generics changing the landscape of how we program moving forward. Any design meeting I go into nowadays, as soon as we start discussing a problem, invariably, we start thinking of generics-oriented solutions. It’s in our mindset, and in our souls. My guess (and note, this is a guess) is that 50+% of new features post-Whidbey (I’d actually guess around 80%), will have generics in them, either as a method, or as a generic type itself. It turns out that Whidbey doesn’t have THAT much generics stuff. But I think that’s a combination of stability of the offering (in other words, the feature wasn’t complete, so relying on it seemed scary), and simply a matter of time for internal buyoff of the coolness of the feature from a person to person basis. Weak-typing will be a thing of the past pretty soon since what the heck don’t you want to strong-type with generics?

The hurdle we still have to overcome is ensuring that we make this feature truly accessible to everyone. Frankly, I can imagine myself as a less-advanced user not wanting to use generics because it adds just that little more complexity that I don’t know why I have to put up with. And furthermore, if I see a generic member on a class, I could imagine my enthusiasm sagging a little. We’ve gotta do a great job in really nailing both the description of the feature, and the description of it’s benefits: if we get these wrong, it could kill adoption for less advanced users, and that would be a bad loss in terms of the viability of the feature.

Feature addressing specific problems: If I had to pick one feature, I would say the changes we’ve made on string to enable you to more easily build culturally unaware code are fundamentally good (again, I’ll admit I’m biased). The amount of code I’ve seen that forgets that parsing and ToString logic on basetypes is culture-aware, is phenomenal. It’s something people get wrong again and again. And while I know that for this audience, the comeback is ‘fxcop fixes that’, you’ve gotta realize that heaps of people either don’t use fxcop, or run it and ignore the results. By making APIs which invite you to use the culture invariant option, we’re putting it in your face that there’s an alternative you need to bone up on, and consider using instead. I think it’s great that we’ve made the pattern fo culture invariance a lot more accessible and in your face, and I’m seeing it pay off already.

Brad Abrams (Lead Program Manager)

Single most important V2.0 feature: While I love generics, edit and continue, and SqlClr, it is the raft of little treasures I think which will help developers the most. How many times have you struggled finding a substring with in a string? We have certainly seen developers waste time on this and even found bugs where developers got it wrong… there are just more moving parts than their needs to be. (KitG comment: I’ll second Brad on this issue, ‘incremental improvement’ is one of the most misunderstood phrases that I use at conferences and talking to customers, since it seems to be taken to imply ‘baby-steps of not much value’. Baby-steps is probably accurate because we generally don’t want to offer an entirely different coding style. But these steps are the ones which make the key and lock line up just right until everything ‘just fits’, and you have a way better coding model).

string s = "Brad Abrams";

if (s.IndexOf("Abrams") != 0) //Or is it <= 0, or > -1? Or != -1??

{

      Console.WriteLine("An Abrams!");

}

 

With 2.0, it is simple and intuitive:

if (s.Contains("Abrams"))

{

      Console.WriteLine("An Abrams!");

}

David Fetterman (Developer)

The System.IO.Ports.SerialPort component is a really solid, RAD addition spanning the needs of all three .NET developer personas.

While this feature itself isn’t broad enough to be crowned “the most useful feature in 2.0”, the fact that the BCL was willing to respond to solely community demand for the component speaks a great deal about Microsoft’s commitments to keep its VB and RAD customers happy.   

Might I also note the original author was very handsome.

(KitG comment: okay, this is a bit cryptic and might need a little explanation. David originally joined the BCL team as an intern, with the task of writing SerialPort. We’ve recently had the opportunity to rehire David from another Microsoft team)

Anthony Moore (Lead Developer)

Most Important Feature: SerialPort

Best Feature to Experiment With: Generic Collections.

Most Underrated Feature: Compression.

Features Correcting Specific Problems:

(a) The ability to correctly serialize or UTC or date-only date in XMLConvert, Web Sercices and DataSet.

(b) The ability to round-trip a DateTime to local time and back to UTC with out losing information during daylight savings time transitions.

(c) SortedDictionary<TKey, Value>. This is a tree-based sorted dictionary that has O(logN) insertion and deletion. It corrects the problem that SortList was the only sorted data structure, but it had O(N) insertion and deletion.

Ryan Byington (Test)

I think all of the work we have done in V2.0 is what adds up to make this a great product and no single feature could do that. However if I had to pick I would probably choose Generics and the work we have done in Collections. We spent an enormous amount of time designing the interfaces, the concrete collections and we have incorporated a lot of the feedback we got from the Power Collections project. I think all of this work makes the generic collections easier to use and more versatile.

 

One of the interesting thing that came out of this was that there is no synchronized wrappers for generic collections. We did this because we felt people assumed that since they were using a synchronized wrapper of a collection that they no longer had to think about threading issues when using the collection. Even the docs say “Returns a synchronized (thread-safe) wrapper for the Stack.” This lead people to write code like the following:

 

if(0 < mySynchronizedStack.Count)

            mySynchronizedStack.Pop();

                                 

However in a multi threaded scenario this Pop could throw an exception since the Count could have become zero after the if check. This is true even with the synchronized wrapper since the wrappers only synchronize each API on the collection and not a composition of API calls on the collection like this.

 

David Gutierrez (Developer)

One feature people should experiment with - generics.

 

Features addressing specific problems - the new string comparison apis and enums. We had such a problem with the Turkish I bug that pretty much everyone in the Framework got it wrong in v1.0 and we needed a massive cleanup effort. The new apis should make it easier to write correct code. (KitG comment: it’s interesting that David and I had the same answer to both questions. Great minds think alike I guess)

Shawn Steele (Developer)

I pick custom cultures. https://blogs.msdn.com/shawnste/category/9761.aspx Developers should respect user’s culture choices and custom cultures provide an easy way to do that.

Comments

  • Anonymous
    March 16, 2005
    No doubt, the best are generics.
  • Anonymous
    March 16, 2005
    Question for Anthony Moore:
    "Most Underrated Feature: Compression"
    What is this? Where is it described?
  • Anonymous
    March 16, 2005
    Without doubt the List<T>.ForEach() method.
  • Anonymous
    March 16, 2005
    Generics, definitely...Nullable Types - a very close 2nd!
  • Anonymous
    March 16, 2005
    We've been using VS 2005 beta at work, and while I was going into the beta thinking generics would be #1, I've found anonymous methods to top even generics as my favorite feature. Generics are great! But anonymous methods I've found even more uses for.
  • Anonymous
    March 17, 2005
    Tips
  • Anonymous
    March 17, 2005
    #1. Generics
    #2. SerialPort
    #3. Partial classes
  • Anonymous
    March 17, 2005
    Wow, great responses! Can I vote on my own question? I think DateTime has some serious problems in practical use (nullable being the least of those) and I am very glad that's being addressed in .NET 2.0.

    Also the Serial Port control is greatly appreciated. I happen to be working on a class for the BetaBrite LED sign, which is controlled through a RS-232 port, so this is actually quite near and dear to my heart currently...

    http://www.codinghorror.com/blog/archives/000238.html
  • Anonymous
    March 18, 2005
    Someone asked about my "most underrated feature" Compression. We have some type that will compress and decompress a stream of data to save space. This is useful if sending data accross the internet, for example, and our own System.Net code uses this new feature.

    Take a look at the System.IO.Compression namespace. DeflateStream and GZipStream are streams that take another stream as input and can compress or decompress the data using standard compression algorithms.
  • Anonymous
    March 21, 2005
    Tips
  • Anonymous
    March 25, 2005
    #1. Generics
    #2. Partial classes
    #3. IO Compression
  • Anonymous
    June 09, 2009
    PingBack from http://insomniacuresite.info/story.php?id=8793