March 7th, 2008 Scott
I finally get it. I have used TDD on a few of my past projects, but I have always struggled with determining which tests I should write. In my head I could see the code for the feature I was working on, but I could not see the code for the tests for that feature. That brings me to some code I was working on last night. In my quest to become an open source developer, I was spending some quality time playing around with the RSpec testing framework for Ruby. I was working through a tutorial from IBM developerWorks.While technically RSpec is a BDD framework, it still follows the TDD idea of writing tests before writing code and letting the tests guide the design. Unlike most testing frameworks, RSpec lets you write tests in a form that resembles how you would write the requirements in English. That is what finally made the pieces fall into place for me. I now understand that the tests are supposed to define the details of the requirements in code. As you write more tests and then write the code the makes those tests pass, you uncover more things that you need to write tests for. It makes for a really nice feedback loop.
Using my newly-discovered knowledge, I built a small class up using RSpec and following the loop. I have included that code here with the hope it may help somebody else out there better understand how all this works.
First, I have the RSpec test suite:
require 'warehouse'
describe Warehouse do
before :each do
@warehouse = Warehouse.new
end
it "should be empty before items are stored in it" do
@warehouse.should be_empty()
end
it "initial item count should be zero" do
@warehouse.item_count("item number").should == 0
end
it "should receive items for inventory" do
@warehouse.receive_item("item number", 10)
@warehouse.item_count("item number").should == 10
end
it "should add items to count if they already exist" do
@warehouse.receive_item("item number", 10)
@warehouse.receive_item("item number", 40)
@warehouse.item_count("item number").should == 50
end
end
And here is the code for the class under test:
class Warehouse
attr_accessor :items
def initialize
@items = Hash.new
end
def empty?()
@items.length
end
def item_count(item_number)
@items[item_number] == nil ? 0 : @items[item_number]
end
def receive_item(item_number, count)
if (@items[item_number])
@items[item_number] += count
else
@items[item_number] = count
end
end
end
So now I am basking in my moment of enlightenment. I only wish I would have figured all of this out sooner
Posted in Development, Ruby, Technology | Comments Off
October 10th, 2006 Scott
The Steve Yegge post on Agile development I posted last week has caused some controversy. Jeff Atwood and Phil Haack have posted rebuttals to the original article. If that wasn’t enough, Steve has posted a response to those who disagree with his view. Lots of good reading on both sides of the arguement. If I can find some time, maybe I will write up my view on Agile software development.
Posted in Development, Technology | Comments Off
September 28th, 2006 Scott
I saw this over on Joel’s blog. Steve Yegge has written a long rant about Agile Development. He makes some interesting points regarding the practices of methodologies like XP and Scrumm.
“You know. Chumps. That’s the word I’m looking for. My bad-cholesterol view was that Agile Methodologies are for chumps.
But I’ve had a lot of opportunity to observe various flavors of Agile-ism in action lately, and I now think I was only about 90% right. It turns out there’s a good kind of Agile, although it’s taken me a long time to be able to see it clearly amidst all the hype and kowtowing and moaning feverishly about scrums and whatnot. I have a pretty clear picture of it now.”
Click here to read the entire essay.
For the record, I do like using index cards.
Posted in Development, Technology | 1 Comment »
June 19th, 2006 Scott
As a part of my new job I’ve been learning how to work with Microsoft BizTalk 2006. While I see some interesting possibilities for using this program, at times the way it works absolutely baffles me.
In a clear violation of the Principle of Least Astonishment, in order to deploy a BizTalk application to a BizTalk server, one must have already deployed the application to a BizTalk server. Yes, you read that correctly. To further explain, Visual Studio 2005 is the tool used to create BizTalk applications. It is also used to deploy an application to a locally installed copy of BizTalk. From there, you can use the BizTalk utilities to create a .msi package which you can install on a production server.
In other words, I have to install BizTalk on my developer workstation in order to deploy and test my applications. There does not seem to be a way to deploy to a remote development server. Am I the only person who finds this to be strange? I would much rather install BizTalk on a virtual machine, and only have it running when I am actively working on project that requires it.
Posted in Development, Windows | Comments Off
March 28th, 2006 Scott
I’ve been following a discussion thread between Tim Bray, Don Box, and Dare Obasanjo concerning the future of web services. (see here, here and here) There seems to be a developer backlash against the WS-EverythingButTheKitchenSink platform being touted by Microsoft, IBM and Sun. (among others) Most developers seem to be using REST instead of the WS-* stack to create public web services. I’ve been dabbling with REST with .NET in my (extremely limited) spare time, and I totally agree with both Dare and Don. We definitely need better tool support for REST. I’ll be interested to see how this all plays out.
Technorati Tags: Web Services, XML, REST
Posted in Development, Technology | Comments Off
March 28th, 2006 Scott
This is my first attempt at creating a web service using REST and .NET. The easiest thing I could come up with was to implement the IHttpHandler interface and add my custom processing logic to the ProcessRequest method. The ItemManager class contains my XML data that I am returning to the client.
public class ItemHttpHandler : IHttpHandler
{
public ItemHttpHandler()
{
}
#region IHttpHandler Members
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
HttpRequest request = context.Request;
HttpResponse response = context.Response;
string command = ParseCommand(request.Url.Segments);
string result = ProcessCommand(command);
response.ContentType = “text/xml”;
response.Write(result);
}
private string ParseCommand(string [] path)
{
string command = path[path.Length - 1];
return command.Remove(command.Length – 5);
}
private string ProcessCommand(string command)
{
ItemManager gm = new ItemManager();
string result;
if (command == “list”)
{
result = gm.GetItemList();
}
else
{
int id = Int32.Parse(command);
result = gm.GetItemById(id);
}
return result;
}
#endregion
}
Here is how I registered my custom handler with ASP.NET.
<httphandlers>
<add verb=”*” path=”items/*.rest” type=”ItemHttpHandler”>
</add>
I still need to work out a couple of kinks. In order for a request to be processed by my custom handler, the URI needs to end with “.rest”. I haven’t been able to have an extensionless URI processed by a custom handler. I also haven’t experimented with using an HTTP POST to submit data to my web service. Currently it only returns data. As I figure these things out, I’ll try and post my solutions.
Posted in .NET, Development, Technology | 1 Comment »
July 22nd, 2005 Scott
Jeremy D. Miller has posted a series of articles on things you should know before working with test-driven development. I wish I would have known some of this stuff before I started working on TDD projects.
From Robin Curry
Tags: Programming TDD
Posted in Development, Technology | Comments Off
January 21st, 2005 Scott
Lately I’ve been trying to learn how to use aspects in .NET. So far, I haven’t had much success. Most of the AOP tools that are available for .NET are either incomplete, or extremely complicated. To date, I’ve looked at Aspect#, and AspectDNG. I can’t get Aspect# to actually work, and AspectDNG has me totally confused. I’m not real sure where to begin.
Recently, I discovered that there is a port of the Java Spring framework called Spring.NET. (shocking!) It also has an AOP component that might be worth checking into.
Posted in Development, Technology | Comments Off