Posts Tagged ‘corgibytes’

Throwing tests away before they pass

Monday, December 19th, 2005

I do my best to follow the ideals of Test Driven Development in all of the code that I write. My favorite part about TDD is throwing away tests before they even pass. Here is what happens.

I write a test and try to compile the code. Usually the test fails because I am trying to call a class or a method that does not exist yet. I then write only enough code to make the everything compile. Whenever I add a class this way, it starts out without any methods. Any methods that I add will either be empty or throw an exception. It depends on my mood really. Ideally, I should only write the empty methods, because the test should be robust enough to detect that it does not do its job. But I feel safer if I throw an exception, because that will guarantee that the any test that calls it will fail.

That leads me to my next step, I make sure that the test fails by running the test framework and clicking the test button. If the test does not fail at this point, then it is broken, fix it.

Now is when I sit back and decide what I need to do to make the test pass. This means that I have to study what the test is testing. This often makes me notice an issue that I missed when I was writing the test. Many of these issues completely invalidate my approach, and I delete the test and the minimal code that I wrote to make everything compile.

So what will happen in this case if I don’t adhere to TDD? Typically, I start with the class or the method that needs to be added. I take a lot of time trying to figure out how the method is going to be used, but the entire time I am only staring at the contents of the method or class. When I think I am done, I wire up a call to the class or method, and then check to see if it works by executing my application. This means that I have to get the application into a certain state. In the worst case, it will take me a few moments to get the application to execute the code. If the code does not work, then I fire up my debugger, start the application in the debugger, place a breakpoint in the new code, set up the application again, and then get the application to execute the new code. When the debugger reaches my breakpoint it lets me inspect the contents of a the variables that are in use. I can execute the code a line at a time and watch them change. This is usually the point when I realize my mistake, and I have start all over again. This leads to much cursing and caffeine consumption, because I am on a deadline; it is going to be a long night.

Wow. That was a lot of work to type, and believe me, in reality it is a lot of work to do. If there was a chance that what you working on might not work, which process would you rather follow? And believe me, there is always a chance that it won’t work. I don’t care how much experience you have or how much you know. In my experience, those are the times that you make the most assumptions. And the more assumptions that you make, the more of them that can turn out wrong.

So, now I hope you understand why I really like to throw away a test before I ever made it pass. It means that TDD just saved me a lot of time and frustration.

Microsoft’s take on Test-Driven Development

Monday, December 19th, 2005

Scott Bellware [MVP] : Microsoft Takes it on the Chin Over Test-Driven Development

I have been wanting to comment on this for a while, but this guy has said all that I wanted to say and more. I bet he has done a better job than I would have, too.

Ruby on Rails

Thursday, December 15th, 2005

Ruby on Rails released version 1.0 yesterday, so I headed over to their site to check it out. I downloaded the 3 screencasts that they have available, and I am seriously impressed. There is a short disclaimer at the top of the page that going back to work after watching the demos would be hard.

They were not kidding. Every aspect of what was being presented was impressive. I have never been exposed to the Ruby language syntax before, but I found it very easy to understand. It seems to have some Python roots. The model view controller pattern that is used by Rails is very impressive and very easy to take advantage of.

I think that the migration demo impressed me the most though. Data migration is something that was sorely missed on the last project that I worked on. If we would of had a system in place with only half of the functionality that I saw in that demo, then we would have been much better off. I have a feeling that the basic design will influence work that I do in the future.

All of these demos have me wondering how much of what I saw was Ruby and how much was Rails. I would love to have the model view controller features and the migration feature for a client application that I am working on. I need to look into what GUI toolkits Ruby supports as well.

Either way, I am kind of upset with myself for ignoring this language for so long. I knew that it was out there, but I never took the time to learn anything about it. I think that future months are going to change that. I will keep those of you that care posted. :)

Run the ASP.NET 2.0 Development Server From Any Folder

Tuesday, December 6th, 2005

Run the ASP.NET 2.0 Development Server From Any Folder

This is a really cool utility. I had read an article about how to do this with XSP, but I have not been able to find it.

How To Write Unmaintainable Code

Tuesday, November 22nd, 2005

How To Write Unmaintainable Code

This is great. I am just affraid that the author might not be joking.

No setup project (.vdproj) support in MSBuild

Friday, November 11th, 2005

Channel9 Wiki: BuildingAVdprojProject

Now that sucks. I guess it is time to start looking into porting to WiX. There is an MSBuild task for it. Not to mention that I think it is a better tool for the job.

Visual Studio .NET 2005 first impressions

Monday, November 7th, 2005

I have been using the RTM build of Visual Studio 2005 at work for a couple days now, so I thought that I would give my first impressions. Because I want to end a positive note, I will start with what I don’t like.

The Bad

  • The new error list. The error list in the previous version would allow you to sort on the type of item in the list (Error, Warning, etc…). This one does too, but it does not remember the sort like the old one did. Luckily they added some quick buttons to hide by type, or this would drive me insane. I always want to fix my errors before I fix my warnings.
  • Intellisense on steroids. When I was learning to type Dvorak, one of the things that I started doing was ignoring Intellisense. That way I would build more muscle memory. It was not really all that hard, there were only a few ways to invoke Intellisense in the previous version. Basically, I really got used to only using it only when I felt that I needed it. Now it is very obtrusive; It comes up with almost everything that I type. I think that I am going to go adjust the settings so that it only shows up if I type a control key sequence.
  • Still no “Add Interface” in context menu. I spent a few minutes trying to figure out how to add this manually, but I was not successful. I may have to read some documentation on writing an add-in, so that I can stop bitching about this.
  • New search box. This will probably be in both categories. The close button was removed. Since it has a toolbox style window frame, the close “X” is really tiny and harder to hit. Typing “ESC” still works, but I have to use the mouse to give it focus to use that. It would be easier if it had a normal sized window frame, if there was a close button.

That is really a shorter list than I thought that it would be when I started writing.

The Good

  • New syntax highlighting. I really like all of the additional syntax highlighting. I would always change the syntax highlighting for strings as soon as I installed the previous version. Now I don’t have to. I like all of the default color choices, too.
  • Solution Items are displayed on top. In the previous version, all solution level items in a solution were displayed after all of the projects. It was easy to forget that they were all the way down there. Now they are on the top.
  • New Error List. I really like the word wrap within the cells in the error list.
  • New Search Box. Wow, it is really a lot smaller. This is great. It is easier to see the code that is hiding behind it. It would have been cooler if it was semitransparent to boot, but hey, it is a drastic improvement.
  • Crazy code formatting options. I noticed this in Beta 1 as well, but all of the code formatting options are great. A lot of thought and work went into this. The only complaint I have is that the preview does not incorporate all of the options, only the one that is selected. But, hey, there is a preview, at least.
  • Faster compilation. It might be my imagination, but the build performance seems to be much better. I am not sure where the boost is at, but my instincts suggest that it is due to MSBuild.
  • Refactoring. The refactorings have improved significantly since Beta 1, but it is still a pretty short list.

That is all that I can come up with off the top of my head. If I come across anything that is either really good or really bad, then I will do another post.

In all, I do not see a lot different on the surface. It really feels like the same IDE. More importantly, I really don’t miss most of the features when I use MonoDevelop at home on Linux. Not even enough to pay for a $50 Express Edition. I will take advantage of the free for a year express version, but I doubt that I will pay for it after that. There is still a little bit of Windows targeted development that I do at home.

ASP.NET ListBox Bug

Tuesday, October 4th, 2005

I found a bug with the ASP.NET ListBox control today. Well, at least I consider this to be a bug; for all I know this behavior is by design.

When using a ListBox control in multiselect mode, each ListItem object stored in the ListBox must have a unique Value property value or the values in the Selected property will not survive a roundtrip to view state. If there is more than one ListItem object in the ListBox with the same Value property vaule and those ListItem objects have a Selected property value of true before a post back, then after a post back, only the first ListItem object in the ListBox with that particular Value property value will have a Selected property value of true.

Hmm… that description does not read very well. The use of the word “value” as ListItem.Value and also as a value makes it a little confusing. So if you are still confused, then you can download an aspx page that demonstrates the problem.

Update: I just realized I should have mentiond that I found this behavior in .NET Framework version 1.1.

Fringe CLI Languages

Tuesday, September 27th, 2005

I don’t know if it is fair to call them fringe languages or not, but given that I don’t hear about them every day, I am not sure what else to call them. For those of you wondering what the hell I am talking about, this post is a very brief introduction to Boo and Nemerle, two .NET Framework languages that provide many features that should make them worth considering when you sit down to start your next project.

There has been a lot of talk floating around about C# 3.0. I think that one of the nicest things that C# 3.0 will bring with it is type inference. This does not mean that the language will stop being strongly typed, it just means that the compiler will not need as much information from the source code to determine what the programmer is up to.

For instance, when I use NMock2(see previous posts), all of the casting that I have to do to create a mock object annoys me. This is of no fault of NMock2, but of C#. It would be nice to be able to write this

  IShoppingCart cart = (IShoppingCart) mockery.NewMock(typeof(IShoppingCart));

as this

  IShoppingCart cart = mockery.NewMock(typeof(IShoppingCart));

or even this

  def cart = mockery.NewMock(typeof(IShoppingCart));

That would save me a little bit of typing without losing any clarity. Saving me a little bit of typing would save me a little bit of time. Saving time translates into many useful things. Mainly getting things done just a little bit faster. Because hey, the 2 seconds it takes me to type that casting syntax could be spent typing other things, like foreach (Item in cart) { ...

The point of this post is that if you want type inference in a CLI language, there is no need to wait for C# 3.0. You can get these features now.

I will start the discussion Nemerle. It is a CLI language that provides object oriented, functional, and imperative language constructs, and is statically typed. Since Nemerle’s syntax is based on C#, it should be very easy for existing C# users to pick up. Just glance over some of Nemerle’s language features, and decide if this cool language is right for you. And since I did not mention it yet, Nemerle performs type inference quite nicely.

The next language on today’s list is Boo. Boo has a python-like syntax, and mainly provides object oriented features in a type safe manner. The main drive behind Boo appears to be saving time. There are many ways that the language and the compiler can be extended. Combine this with type inference, and you have a language that is a time saving power house. But don’t take my word for it, check out the Boo Manifesto. It is an amazing read, and it gives a wonderful overview of the language features.

The Boo Manifesto really impressed me. The features and extensibility that this language provides were enough to persuade me to start using it, but I was thoroughly impressed with the Boo Addin for MonoDevelop. I am most likely going to start using it on some personal projects.

I hope that you enjoyed reading this post as much as I enjoyed writing it. If you have any other “fringe” CLI languages that you think should get more attention, leave me a comment.

Web Developer Toolbars

Monday, September 19th, 2005

Microsoft has released a web developer toolbar, DevToolBar, that works on both IE6 and IE7. I just downloaded it and gave it a shot. It looks pretty handy at first glance; I like the ruler. That is a pretty handy little tool. However, I really feel that it is lacking in a lot of areas.

The area that I feel it is lacking the most is CSS support. I have been spoiled by the CSS support that is part of Web Developer Extension for Firefox. You can edit the CSS for the current page and see how your changes work in real-time. The IE toolbar has a DOM explorer that lets you see all of the style information, but you are unable to change any of it. This has saved me an estimated hours upon hours of work, and has really helped increase my understanding of CSS. It is amazing how helpful quick turn-around times are when you are working with CSS.

The ability to completely disable the CSS styles has also been helpful. It is nice to see how your markup is going to be viewed by a user agent that does not have support for CSS. And, finally the ability to use the mouse to hover over an element and see the CSS path to the element. This is great for determining how to reference a certain element in a stylesheet.

I have really only talked about a few of the features in Web Developer extension and DevToolBar, but should be clear which one I consider to be the more powerful tool. However, I don’t want to downplay DevToolBar’s utility; what it does provide is useful, it just does not provide all that much.

My keyboard works!

Friday, September 9th, 2005

Today is a great day! I found out from a doctor this morning that I do indeed have carpal tunnel syndrome in my right hand. This is a condition that has only been made worse by using a normal keyboard and mouse the last few days.

But this is all okay, well sort of, because the ribbon cable that I ordered came in today. The repair job is complete and I am typing this entry on my TouchStream. I really missed using this thing. It has really helped keep my carpal tunnel symptoms at bay. And hopefully it will continue to do so.

I am going to try and find a container to put my TouchStream in so that I can transport it to and from work a little safer. This should reduce this risk of the ribbon cable breaking again in the future. However, I am going to stock up on replacement ribbon cables in case they do not last forever.

TouchStream repair progress

Tuesday, September 6th, 2005

I took apart the left hand side of the keyboard and reset the ribbon cable. It was no use. The diagnostics still report the same problem.

I just ordered a replacement ribbon cable from DigiKey. Hopefully that will do the trick.

My TouchStream needs repair

Tuesday, September 6th, 2005

Today when I got into the office, my the left side of my FingerWorks TouchStream was not working. The diagnostics reported that the entire left side of the keyboard was not working. I suspect the small ribbon cable that runs between the two sides of the keyboard my be the culprit. I played with the cable a little bit and somewho managed to get the keyboard working again.

However, around lunch time, the left hand side stopped responding. I flipped the keyboard over and noticed that the ribbon cable was not completly seated on the left side. I tried to get it to go in all the way, and only managed to take it all the way out in the process. I am hoping that I am going to be able to re-attach it the evening.

It may be that the ribbon cable that is there is damaged. If that is the case, I know the part number of the replacement, and I plan on buying more than one. Either way, I should be able to get the keyboard working again soon. If not, I may get to go back to using a normal keyboard and mouse at work again, yuck.

Wish me luck.

NMock2 is a welcome surprise

Thursday, June 9th, 2005

I have been using NMock in my daily test driven development for over a year now. In that time, not much development has taken place. I mentioned in a previous entry that NMock lacks support for events. It also has a few other bugs that have been stacking up over the years. Yet the mailing list has had very little traffic.

Since I found NMock, several other .Net or C#mock object libraries have popped up. I have taken a good look at all of the free ones, and even though NMock has some problems, none of them really impressed me enough to switch away from NMock.

Earlier this week, I ran into a bug with NMock that without a fix, would have caused me to alter one of my designs in order to use it. NMock was unable to mock items in an interface’s parent interface. Traffic on the mailing list suggested that the bug had been fixed or worked around, yet no one had posted any details.

This discussion brought up the mention of a replacement for NMock that the developers had developed based on experiences with jMock. This replacement was checked into the NMock source tree at the end of June under the name NMock2.

When I hit this bug, I was experiencing crunch time here at work. I made request to the list for an NMock fix for the problem, but I really did not have time to wait arround for an answer. So I checked out NMock2 from the SourceForge CVS repository, and started reading the acceptance tests to see how to use it.

What I read really, really impressed me. The mock code that is produced when you use NMock2 reads very well.

I wrote a quick addition to the acceptance tests to see if my bug was there, and I was presented with the Glorious Green Bar of Success. I then added the binary to my project and used for the spots that that NMock did not work with.

Turns out that NMock2 had a different bug related to what I was doing, but this only took me a few minutes to fix. First, I wrote up a quick test that demonstrated the problem, and then I got to work. After a few minutes of tracing and debugging, I found the problem. NMock2 uses Type.GetMethod to get the methods that belong to a type. Even though the documentation suggests otherwise, Type.GetMethod does not get methods from an interface’s parent interfaces. Hmm… this sounds like the bug in NMock as well. My first test must have just sucked. I added a call to Type.GetInterfaces and then recursively called them to look for methods. This worked really well.

I never really dove into the NMock code all that much, but the code for NMock2 is really easy to follow. Furthermore, because of the test driven way that it was developed, I have a pretty high confidence that I did not break any existing functionality.

To make this entry even longer, I am going to share some snippets for code from both implementations that do the same thing. For both of these the following interface will be used to test the ComputeTotal method on a ShoppingCart object. (+10 points if you can figure out what that method does :))


public interface Item {
  double Price { get; }
}

First is the old NMock way of doing things.


[Test]
public void ComputeTotal() {
  // Create the mock object for item1 and have it return a price of 100
  DynamicMock item1Mock = new DynamicMock(typeof(Item));
  item1Mock.Strict = true;
  item1Mock.ExpectAndReturn("Price", 100);
  Item item1 = (Item) item1Mock.MockInstance;

  // Create the mock object for item2 and have it return a price of 50
  DynamicMock item2Mock = new DynamicMock(typeof(Item));
  item2Mock.Strict = true;
  item2Mock.ExpectAndReturn("Price", 50);
  Item item2 = (Item) item2Mock.MockInstance;

  // Add the items to the cart
  ShoppingCart cart = new ShoppingCart();
  cart.Add(item1);
  cart.Add(item2);

  // Get the total and make sure it is 150 (100 + 50)
  int total = cart.ComputeTotal();
  Assert.AreEqual(150, total);

  // Verify that all the expects have been met
  item1Mock.Verify();
  item2Mock.Verify();

}

And now here is the NMock2 way.


[Test]
public void ComputeTotal() {
  Mockery mock = new Mockery();
  // Create the mock object for item1 and have it return a price of 100
  Item item1 = (Item) mock.NewMock(typeof(Item));
  Expect.Once.On(item1).GetProperty("Price").Will(Return.Value(100));

  // Create the mock object for item2 and have it return a price of 50
  Item item2 = (Item) mock.NewMock(typeof(Item));
  Expect.Once.On(item2).GetProperty("Price").Will(Return.Value(50));

  // Add the items to the cart
  ShoppingCart cart = new ShoppingCart();
  cart.Add(item1);
  cart.Add(item2);

  // Get the total and make sure it is 150 (100 + 50)
  int total = cart.ComputeTotal();
  Assert.AreEqual(150, total);

  // Verify that all the expects have been met
  mock.VerifyAllExpectationsHaveBeenMet();

}

Not only is the code shorter, but because of the way that it reads, the comments that I have added for clarity have almost become irrelevant.

I encourage you to go grab NMock2 and give it a shot. I think that it works really well, and I am in the process of replacing NMock with NMock2. It just reads too well not to. There are other pluses about NMock2 that I have not mentioned in this post, like support for events, but I will save that for another time.

I hope that you enjoyed this post, and that you learned something. For you non developers that read this, Wow. Kudos to you for reading this far! If you want, I will give you a special prize. :)

Is this a bug in ArrayList.ToArray() ?

Tuesday, June 7th, 2005

I think I may have found a bug in System.Collections.ArrayList.ToArray(). The following code throws a System.InvalidCastException with the following message:
“At least one element in the source array could not be cast down to the destination array type.”



using System;
using System.Collections;

namespace InterfaceToArrayTest
{
  public interface Parent
  {
    string ParentProperty { get; }
  }

  public interface Child: Parent
  {
    string ChildProperty { get; }
  }

  public class Implements: Child
  {
    #region Child Members

    public string ChildProperty
    {
      get
      {
        return "child";
      }
    }

    #endregion

    #region Parent Members

    public string ParentProperty
    {
      get
      {
        return "parent";
      }
    }

    #endregion
  }

  class ArrayListToArrayTest
  {
    [STAThread]
    static void Main(string[] args)
    {
      ArrayList list = new ArrayList();

      for (int x = 0; x < 10; x++)
      {
        list.Add(new Implements());
      }

      Child[] children = (Child[]) list.ToArray(typeof(Child[]));
    }
  }
}

Mac OS X on Intel

Monday, June 6th, 2005

Wow. That is all that I can really say. I can remember waiting to get food with a friend of mine not long after OS X.1 was release. Among many of the topics that came up, one that we were really pasionate about was the prospect of running Mac OS X on Intel. I have consistently said that I thought it would be amazing if Intel users could switch to Mac OS X.

Now, while it may not exactly turn out that way, given the way that Apple likes to control hardware configurations, but I am pretty confident that people will be able to build their own Mac boxes using approved hardware.

What is really cool is that Mac OS X is available for Intel right now. A quick $999 over at developer.apple.com will get you a copy of Mac OS X.4.1 and the Intel hardware to run it on.

You can get all of the details from WWDC Tags:
Posted in | 4 Comments »

Cool technique for displaying dynmaic web content

Friday, June 3rd, 2005

Okay, so this may not be a surprise to developers that have been targeting the web longer than I have, but I saw a really cool technique last night.

Did that opening grab your attention? Good now you get to read through my boring back story! Ha!

Last night the Roanoke Valley .NET User’s Group held a DataGrid marathon. All the presenentations were almost completely devoted to the web version of the WinForms DataGrid control.

Since I am still new the web development sphere, I learned a lot, but I learned the most from the final presentation. The final presenter was, among other things, showing how to pull images out of a database and display them in the grid. To do this he created a template column in the grid with the ItemTemplate containing a Image control. He then set the image source of the image contol to another aspx page that took the id of the image to display.

This other page changed its response content type to “image/jpeg” and then, using the System.Drawing.Bitmap class, wrote a jpeg version of the binary image date to the response stream. That really blew me away.

When I see a new technique like that, my brain starts spining with ways that it could be used. Another member of the group mentioned that this is how some of the dynamic charting web controls get their job done. Someone else mentioned that there is a site that does this to create dynamic buttons.

That is really cool. It is too bad that with the project that I am working on now I will not be able to put it to use. Perhaps with the next one.

Although, I am sure that technique will work equally well with PHP with ImageMagick doing the image work. I might be able to create some dynamically generated buttons for my own site. Or maybe even dynamically generate the header image. See what I meant about the ideas? Now if I could only get paid to work on some of them. <smile />

Mono on Mac OS X

Wednesday, May 25th, 2005

After working on it for the last several hours, I now have a pretty decent Mono development environment setup on my Powerbook.

I installed a Mac binary version of subversion, and got svnserve running on my Linux laptop. I created a repository for the project that I have been working on, and performed and initial check-in. Now I can keep the sources in sync regardless of whether or not I am working on my Mac or my Linux laptops.

I installed Mono using the Mac installer that they have available. I toyed with the notion of grabing the latest out of the repository, but frankly, I don’t have the time to wait for it to compile. I was going to try and get MonoDevelop running, but I gave up because there is no binary version. I guess it is time to become more acquainted with vi.

I also got NUnit and NAnt installed and configured so that I can run them without having to directly invoke mono. Shell scripts are fun. :)

Well that is enough for one night. I am up later than I wanted to be anyway. Perhaps on my next stay up late binge, I might actually write some code.

Is FingerWorks dead?

Friday, April 22nd, 2005

Eek! It appears that FingerWorks might be dead.

I visited the site today to check for updates. When I realized that there was nothing new, I jumped into the user forums to see if there was anything interesting on the horizon. I am always excited to see if they will have any new product offerings.

The first thing that I noticed in the forums was a post, fingerworks apparently bought out, where the author makes reference to a quote on this page.

Jeffrey White was most recently the CEO and Chairman of FingerWorks, Inc. a privately held producer of Computer Software and Hardware targeted at the input systems market. In this capacity, he successfully transformed a fledging startup into a leading edge provider of input technologies, which was ultimately acquired by a multi-billion dollar supplier of IT software and hardware for a price equal to 25 times revenue.

Eek!! The rest of the post is devoted to speculation about who might have bought them, and what will happen to the product line.

This is pretty troubling, I noticed some posts on the forum where people are complaining that they cannot buy any FingerWorks products anywhere. One forum member noted that he had emailed 20 resellers and only recieved a response from one, and the response he received was not promising.

There are a bunch of dead links all over the site, so I downloaded all of the lastest software and documentation that I saw posted. Looks like I am typing this post on a product that is no longer supported.

Roanoke Valley .NET User’s Group Meeting

Friday, April 8th, 2005

Last night’s user’s group meeting was pretty good. G. Andrew Duthie was supposed to do a presentation on the MapPoint web service. However, after spending about 35 minutes trying to get Internet connectivity (it is a web service after all), he gave up and just showed us some the cool features that are going to be in Whidbey. I guess I should start using the official name, Visual Studio 2005.

Even with the technical snags, it was a fun meeting. At the first meeting that I went to, I won a signend copy of Andrew’s book in a raffle. Now I can finally say that I have met the person that signed it. ;)

I won another book last night, too; Application Interoperability: Microsoft .NET and J2EE. Looks like it might be a good read.