Jon Shute's Weblog : Ramblings on .NET and writing debuggers
Updated: 08/05/2004; 13:38:42.

 

Subscribe to "Jon Shute's Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

24 November 2002

I've been thinking about Microsoft's proposed new language features for C# and I'm a little uncomfortable with anonymous methods. They're something that I always thought C++ needed when you were dealing with the STL's algorithm classes but they're not as needed in C#. You save a grand total of one line of code and make your code a bit easier to understand, but at a cost to testability. How do you unit test an anonymous method? You're committing yourself to a much larger testing effort. Consider an event that triggers when something happens in your code that is hard to trigger, or isn't a good idea to trigger such as shutting down Windows. If you don't use anonymous methods your unit test can just call this function to test the event being triggered, if you do use them then you can't and have to actually trigger the event.

I'm not saying that they're a bad idea, they're going to get a lot of use, but they are going to have to be used carefully if you're unit testing your code.

On the other hand generics are a great help to unit tests because they allow you to use mock objects in a new way. This makes testing UI code a lot easier as long as you can get around the constraints system they're adding. C++ lets you drop any class you want as the type and it'll only complain if you try and call a member that isn't available on that type. This means you can drop in a mock object that implements the members that you need and it'll not complain. It seems that constraints will enforce interfaces and so if you want to drop in a mock ListBox then you'll have to do a bit more in order to pull this off. If you can derive from the class then you can do it that way, but if not then you’re going to have a problem.


What other blogs are saying about this post.
11:01:58 PM    comment []  trackback []

I've spent some time today cleaning up my debugger code. Only one class is now in real need of work, but there's not much point doing that now as it can be done as development continues. I still can't put it back into CVS until I get my home net access though, so hopefully that'll be tomorrow night.
What other blogs are saying about this post.
3:26:09 PM    comment []  trackback []

© Copyright 2004 Jon Shute.



Click here to visit the Radio UserLand website.   Listed on BlogShares

 


November 2002
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Oct   Dec