Monday, July 16, 2007
Over the weekend I listened to the latest .NET Rocks episode with John Lam.  I'm very keen on seeing and hearing about where the IronRuby project is going, so I found the interview very informational.  Although I enjoyed the entire show, one particular exchange between Carl and John stood out.  About half way through, Carl asked John whether he thought developers who don't do test driven development (TDD) and unit testing should be working in dynamic languages.  John made the wonderful assertion that he doesn't believe programmers that are not writing "unit tests" should be writing code in any language, regardless of whether the language is dynamic or statically typed.   Following that statement, John went on to mention that whether or not the code is test driven isn't nearly as important as whether the code has unit tests since the "test driven" approach is "extreme" and "dogmatic".  While I agree that the key is unit tests, I don't agree that a test driven approach is extreme or dogmatic.  In my opinion its the most pragmatic approach to writing code that is well designed and well tested.  The fact is, writing unit tests after the fact sucks!  Especially if "after the fact" is days or weeks after the real code is written.

When I first got started with TDD I didn't really understand what it was all about.  Rather than figure out what this magical red-green-refactor thing was all about I decided I'd just write some unit tests once I had my code written.  After a couple projects using this approach I started to realize that I really hated writing unit tests after the fact.  It was because of this hatred that I got started with test driven development.

Rather than testing being a pain in the ass task that I had to do when I finished writing my "real" code, testing became an instrumental step within the process of writing the "real" code.  Since I was using tests to figure out what code needed to be written, it became a vehicle by which I could design the code I was writing, rather than an afterthought.  I'm sure there are people out there that write great tests after the fact, however, I'm not one of them.  For me writing tests first isn't something extreme or dogmatic, it simple the only way I can write high quality code with solid test coverage without going nuts.  For me, writing unit tests after the fact sucks.  For me, driving my code with tests is a joy. 

I wonder how writing tests first could be "extreme" and "dogmatic" for others, but for me its pragmatic?

   
 |  | 
Tuesday, July 17, 2007 3:58:39 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [17]  |  Trackback
 Wednesday, July 11, 2007
As I've stated before, my programming language for the year is Ruby.  I actually planned on learning Python or Ruby last year, but things didn't pan out.  Over the last 6-8 months I've been doing a pretty good job of getting myself on the way to learning Ruby.  As with any language the best way to learn it is to write something using it.  As we all know Rails has done a tremendous job of bringing people to Ruby.  I'm no different.  Over the last 6 months I've worked on two Rails projects and in the last week put one of them into production (well almost).  Since I'm half way through the year I wanted to put some thoughts down here, mostly for myself, but also for others who might be interested in a .NET dudes impressions of Ruby and Rails.

Before writing a book myself, I bought a good number of books on technical topics that I found interesting.  After experiencing what goes into writing a book, I find that I'm much quicker to pull the trigger on books that I think I might find interesting.  The amount of work required to get a book out the door is mind boggling to me.  As such I've purchased, and read, the following books to help me learn Ruby.
As you can see not all the books are strictly Ruby related.  Several are focused on Rails, one is focused on working with Google Maps with Rails, and one is to help me learn to work in my new favorite editor, Textmate.

In addition to reading the above, I've been checking out the source code for a couple of the more popular open source Rails applications as well as some of the more popular plugins.  While all of that has been very valuable, nothing is ever as good as actually writing code.  As such I've done several projects that I would have traditionally done in .NET in Rails instead.

The first application that I got started with (and which I'm still working on) is an application that helps geographically visualize key individuals within a social network.  The data for the individuals in the social network, as well as the data for the connections between individuals, is stored in flat files so I got my first chance to play around with the CSV parsing capabilities of Ruby.  I found the FasterCSV library very useful, and got off to a pretty good start with my first attempt at parsing the CSV files and getting them into my MySql database using my ActiveRecord model objects.  After the file parsing was done, I got a chance to build several administrative pages for the site using Rails, as well as the chance to experiment with some very useful plugins such as:
My second application involved setting up a site with paid membership.  The site has several administrative functions for the owner of the site, as well as a handful of features for those who sign up to be members such as exclusive downloads, advertising opportunities, and a members only forum.  In addition to be able to gain a lot more experience with the inner workings of Rails this project also led me to gain experience with:
So given all of the above, if your still reading, I'm guessing your wondering what I think.  In short, I'm becoming a pretty big fan of Ruby as well as Rails.  While Rails isn't perfect it does a lot of things very well.  Rails Migrations are the best solution that I've come across for migrating the schema of a database.  I can see why large teams run into some trouble with them, but for the projects I've been working on migrations have worked wonderfully.  While I'm a big fan of DDD, I also really like ActiveRecord in the right situations.  Being able to create a migration, run rake db:migrate, and have the column automatically available in my model without having to do anything makes developing with Rails and ActiveRecord very enjoyable.  Rather than dealing with the mundane tasks of writing scripts for adding columns, and then updating the associated data access and model classes, I can focus on the stuff that matters.  In addition to migrations and ActiveRecord I'm also fond of ActionMailer and the way that it allows you to create and send email, its far better than what's available in .NET land.  Next up, is the MVC structure that Rails uses for building the pages that make up the application/site.  I'm a huge fan of MVC/MVP for building UI's so it should be no surprise that I'm also a big fan of Rails implementation of MVC.  I really like having a single controller per model object, and having a nice organization to the views used by the controller.  I also really like the validation story for Rails.

As I learn new technologies I often times hack my way around until I get a good feel for what I'm doing and how things are supposed to work and be put together.  This led to me not writing as many unit tests for certain parts of the applications I was working on.  I did test drive most (if not all) of the logic I put into my model objects, but I slacked off a bit when it came to testing the controllers.  This is partly due to the fact that I was using scaffolding, and partly due to the fact that I was pushing almost everything into my model objects rather than allowing my controllers to get "fat".  As part of the test driving of my model objects I used the built in testing infrastructure, although I still want to checkout rspec.  On my latest project I also began experimenting with mocha which really helps with the testing of objects that have dependencies. 

So given all my recent exposure to Ruby and Rails one has to wonder how I rate it against my native "tongue", .NET.  I have to say I've had a lot of fun working with Ruby and Rails.  This is in part because its something unfamiliar and I really enjoy learning, but its also because both Ruby and Rails have a way of making developing with them very enjoyable.   I haven't enjoyed some of the deployments and such that I've had to deal with, but since I was learning a bit about how to deploy Rails applications on Linux it wasn't as bad as I expected.  I'm nowhere near hanging up my .NET toolbelt, but I am going to continue to do a lot of the work that I would have previously done in .NET in Ruby and/or Rails.

 |  | 
Thursday, July 12, 2007 3:11:07 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [3]  |  Trackback
 Monday, July 09, 2007
Glenn Vanderburg's "The Beauty of Ruby" JAOO presentation was recently published on InfoQ.com.  Glenn talks about some of "the subtle beauty that experienced Rubyists have come to know and love".  Over the last couple of months I've come across a lot of great content on InfoQ's Ruby section that has helped me to learn some of the subtle gems that exist within the Ruby programming language.  While reading books, and writing Ruby code are great ways to learn Ruby, its also tremendously valuable to hear experienced Rubyists talk about what they love about the language.  Below are a couple of my favorite Ruby presentations available on InfoQ.

 | 
Tuesday, July 10, 2007 12:46:49 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
The self proclaimed ninja's over at ActiveReload have unveiled Warehouse, a "web based subversion browser that doesn't suck".  Warehouse is a Rails app that allows you to view a subversion repository with a very slick web interface.  Rick and Justin spent the weekend when they weren't at RailsConf getting Warehouse started, and now a couple months later they've released it to the world. 

Tuesday, July 10, 2007 12:39:43 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Sunday, July 01, 2007
Over the last 2-3 weeks it seems as though 90% of the blogs that I'm subscribed to have been talking about the iPhone.  This is me succombing to peer pressure :) 

While I'm not *really* planning on getting one, I couldn't help but stop by the Apple store this evening on my way home from Sam's b-day party, afterall it was right on my way home.  As I strolled into the Apple store I was a little surprised that there wasn't more people inside, afterall this was the iPhone!....surely everyone in Marlton hadn't already gotten one....or had they?  Anyway, after strolling in and playing it cool, I mosied my way on over to the iPhone section of the store.  While the store wasn't crowded, maybe 10-15 people total, every one of them was playing with an iPhone.  In the 5-10 minutes I was in the store I heard at least 100 "wow", "oohhs", "ahhs", and "I want one"'s.  I'm not sure how many of them came from my mouth, but the that's beside the point.  In short, the iPhone is a very sweet device.  The screen is amazing, the experience is better than that offered by any other device I've probably ever gotten to play with.  In the short time I was in the Apple store, I browsed the web, checked out the calculator, did a google maps search, searched for videos on YouTube, browsed photos, looked at how you make calls, but more than anything I just admired the device that Apple has put together.  After leaving the store, I thought about what affect the iPhone might have on my life.  I can see a lot of people buying one, like a really lot.  I wonder how long it'll be before I'm one of those people.

Monday, July 02, 2007 1:25:24 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [3]  |  Trackback
 Friday, June 29, 2007
In reading blogs today I was extremely disappointed that I couldn't find any mention of new phones that are coming out soon.  In fact this entire week I haven't seen any mention of anything phone related.  What's a guy like me supposed to do? I need a new phone and nobody is talking about phones.  Whats the deal?

Friday, June 29, 2007 4:42:43 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Thursday, June 28, 2007
As Aaron mentions, one of our colleagues recently posted a "brain teaser" on the whiteboard at work.

A/BC + D/EF + G/HI = 1

All variables are unique digits from 1 - 9. Two variables next to each other is equivalent to 10 * var1 + var2. For example, if B = 2, C = 5 then the result is 10 * 2 + 5 which equals 25.

Since my language of this year is Ruby, I figured out the answer with the code below.  I had some of the code sketched out in my head, but I wrote it after seeing Aaron's post last night, so the way I went about implementing it pretty much matched the approach Aaron took.   I should also mention that I'm a Ruby newbie so there might be better ways to go about writing the below code.  If so, I'd love to here them since I'm still learning what idiomatic Ruby is :)

#!/usr/bin/env ruby
class FigureItOuter
  def run
    set = generate_set
    while (calculate(set)) != 1
      set = generate_set
    end
    puts format("%d/%d%d + %d/%d%d + %d/%d%d = 1", set[0], set[1], set[2], set[3], set[4], set[5], set[6], set[7],set[8])
  end 
 
  private
  def calculate(s)
    (s[0] / (10 * s[1] + s[2])) + (s[3] / (10 * s[4] + s[5])) + (s[6] / (10 * s[7] + s[8]))
  end
 
  def generate_set
    s = []
    while s.size != 9
      n = rand(9) + 1
      s <<  n.to_f unless s.include?(n)
    end
    s
  end
end

# a/bc + d/ef + g/hi = 1
f = FigureItOuter.new
f.run


Thursday, June 28, 2007 10:59:49 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Wednesday, June 20, 2007
I'm in the process of deploying a Rails app, and up until a few minutes ago I was having problems getting acts_as_attachement and attachment_fu to work.  I originally started development with acts_as_attachement since I was naive and didn't know there was something better.  After looking for a fix for the issue I was seeing, I came across attachment_fu and came to see that it was superior and would undoubtedly solve my issue.  It didn't....however, the upgrade process was painless and I got some extra goodies so all was good.  For those interested, the extra goodies include pluggable image processors (RMagick, MiniMagick, and ImageScience) as well as an option to store files with Amazon S3.

With attachment_fu installed, I was sure my problem would be resolved.  I suspected the issue I was having was related to RMagick image resizing since I'm deploying to a shared hosting account on TextDrive, and RMagick has quite a reputation for hogging up lots of memory and causing havoc on shared accounts.  After switching over to attachment_fu and to MiniMagick as my image processor I was still seeing my issue, so I realized it had to be something else.

Before going onto the solution, let me explain the problem that was occuring.  When I was submitting a form for an attachment_fu model I was immediately being redirected back to the index page.  Every once in a while the form would appear to be submitting, hang, and eventually hose the lighttpd process.  As I mentioned above, I first suspected the problem was related to image resizing being done by RMagick but I was able to reproduce the problem on a non image attachment_fu model object.  After digging around on the web and coming up empty, I ended up checking out the Rails log file to see if I could figure out what was going on.  Examining the production.log showed that I was going from the :new action, directly to the :index action.  Since I was submitting a form, I should have seen a hit on the :create action for my controller.  This led me to search google for a slightly better phrase which eventually landed me at this "Form doesn't trigger create in production" forum post, as well as this related post on Ruby Forum.

It turns out the problem is due to the way that attachment_fu stores the files uploaded on the file system.  attachment_fu stores the files in a folder with the same name as the model within the public folder.  This causes issues since the url for the controller, as well as the directory for storing files have the same URL.  Fortunately the fix is as simple as adding the following to your application.rb file.
def default_url_options(options)
{ :trailing_slash => true }
end

Deployment is such fun, isn't it! :)


 |  | 
Thursday, June 21, 2007 2:03:58 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Thursday, June 14, 2007
Over the last couple days a number of people on our team have been investigating why an operation marked as one way on one of our WCF services ends up blocking when it's called.  We looked at a number of things with our setup including:
  • Making sure our operation did in fact have IsOneWay=true defined
  • Ensuring none of the behaviors we have setup for exception sheilding and authorization were cuasing the call to block
  • Ensuring that it wasn't something within our client by creating a console app to replicate the problem
  • Validating the configuration on both the client and service side where both correct
  • and more...
Yesterday afternoon Sam and I began to dig into the problem a little deeper by turning on tracing and message logging for our services.  After spending a bit of time tracing through the logs with SvcTraceViewer we eventually spotted something in the client side log that didn't look right.  The entry looked something like this:

Close Secure Session       10s

What was mysterious about this line was that in order to replicate and debug the problem we had a service that looked like this:

[OperationContract(IsOneWay=true)]
public void MyOneWayOperation(ItemRequest request) {
    Thread.Sleep(10000);
}

So it appeared that the Close on channel was actually blocking until our one way operation completed.  We weren't totally convinced that this could really be the case, so we changed our operation like so:

[OperationContract(IsOneWay=true)]
public void MyOneWayOperation(ItemRequest request) {
    Thread.Sleep(20000);
}

which resulted in the following line in our log:

Close Secure Session       20s

This convinced both of us that it was defintely blocking when closing down the client proxy.  At one point in the past we had run one way messages and not seen this behavior though, so what had changed to all the sudden cause our operation with IsOneWay=true set to block?  It turns out that the "problem" was due to a change in the way we used the client proxies.  Previously we had code that looked like this:

MyServiceClient client = RetrieveClientProxy();
client.MyOneWayOperation(new ItemRequest("KLDF992"));

But due to some problems that we've had with secure sessions timing out, and other inconsisitencies we changed our code to:

using(MyServiceClient client = new MyServiceClient()) {
  client.MyOneWayOperation(new ItemRequest("KLDF992"));
} // FYI, Dispose on a ClientBase calls Close

Instead of re-using our client proxies we're now recreating our client proxy every time an operation is called.  This results in our performance not being as great as it could be since the client has to re-establish it's security context on every call, but, it's also resulted in our services being a lot more reliable.  We'd rather have things run slightly slower than have them not work. 

I still don't understand why closing the client proxy would block when calling a one way operation.  Since a one way operation immediately returns a 202 letting the client know that it was received I'm unsure of why the proxy needs to wait around for the operation to finish when you call Close on it.  It seems to defeat the whole purpose/nature of a one way operation.  I've explicitly said that I don't care about the return value so I don't see why it can't just close when I tell it to. 

 |  | 
Thursday, June 14, 2007 1:44:44 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [6]  |  Trackback
This post from John Lam has prompted me to download the latest beta of VMWare Fusion.  I've had a love hate relationship with Parallels ever since I installed it.  Back when I first got my MacBook Pro I was using BootCamp to run Windows, however, I found I often wanted to switch back and forth between OS X and Windows and rebooting took way too long.  When I heard about Parallels, I was instantly interested and proceeded to download the beta.  After using it for a while I decided to go ahead and purchase it.  Since Parallels supposedly supported booting from a BootCamp partition my plan was to continue using BootCamp so I could go directly into Windows and use it without suffering from the cost of virtualization, but also be able to run it from within OS X for those times when I wanted to use apps from both OS X and Windows at the same time.  Well Parallels ended up completely hosing my BootCamp setup so I needed to start fresh with a new image that wasn't based of BootCamp.  Ever since making this change I've been frustrated when trying to get things done in VS.NET (which is more of less the only Windows app I use anymore at home).  So, I'll be downloading VMWare Fusion in hopes that it resolves many of the issues that I have with Parallels.  It might mean shelling out a little extra cash but considering the "upgrade" for existing Parallels customers is $50 for version 3 it won't be that much of a difference.  I'll let you know how it goes. :)

 | 
Thursday, June 14, 2007 1:27:42 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback