Thursday, May 08, 2008
In preparation for my upcoming Code Camp session on IronRuby I've been hacking around on the IronRuby source, as well as on Ruby programs that can run on IronRuby.  One of the core areas of interest for me concerning IronRuby is in writing specifications for my .NET applications using Ruby.  While I've been learning Ruby (the real kind) I've become very fond of the testing libraries they have available, most notably RSpec and mocha

Over the last two nights I've been writing some ruby code to test .NET classes written in C#.  With a few of the hacks I have locally, I've had some pretty good success.  The following set of specifications verify the behavior of an Account class I've written.

require "../../trunk/tests/ironruby/Util/simple_test.rb"
require "IronRubySamples"
include IronRubySamples

describe "Account" do
    describe "When depositing money into my account" do
        it "should increase my balance by the amount deposited" do
            account = Account.new(10)
            account.Deposit(10)
            account.Balance.should == 20
        end
    end
                               
    describe "When withdrawing money from my account" do
        it "should decrease my balance by the amount withdrawn" do
            account = Account.new(100)
            account.Withdraw(50)
            account.Balance.should == 50
        end
    end
                   
    describe "When withdrawing money from an account with insufficient funds" do
        it "should tell me I have insufficient funds" do
            account = Account.new(30)
            should_raise(InsufficentFundsException) { account.Withdraw(50) }
        end
    end
   
    describe "When making a withdraw that drops my balance below the minimum" do
        it "should reduce my account by the amount withdrawn + the low funds charge amount" do
            account = Account.new(55)
            account.Withdraw(50)
            account.Balance.should == 4
        end
    end
end

The next step in my quest to test .NET code with IronRuby required me to figure out how to mock out dependent objects.  I considered several different options.  My first thought was to try and use "simple mock", however, I quickly realized via Scott Bellware that while it worked well on IronRuby libraries it wouldn't fit my needs.  My next thought was to give Moq a try.  After downloading Moq, I attempted to run a spec that referenced Moq and created a Mock<T> instance as shown below:

require "../../trunk/tests/ironruby/Util/simple_test.rb"
require "IronRubySamples"
require "Moq"
include Moq
include IronRubySamples

describe "LoginController" do
    describe "When a user logs in" do
        it "should vallidate credentials with login service" do
            mock = Mock.of(ILoginService).new
            #do expects
           
            controller = LoginController.new(mock.Object)
            controller.Login("steve", "****")
        end
    end
end

When running this via ir.exe I got an error that "Moq.Mock is not a generic type".  After poking around a bit I discovered this was due to a bug in IronRuby.  Currently IronRuby has problems when there is a generic and non generic type of the same name within a referenced assembly.  In order to work around this, I first tried to figure out what needed to be modified in IronRuby, however, that wasn't very fruitful so I decided to modify the source for Moq to get around my problem.  After renaming the static Mock class in Moq to MockRetriever, and hacking around another bug in IronRuby related to creating generic types where the type argument is an interface, I was finally able to get IronRuby to create the Mock<ILoginService> type:

mock = Mock.of(ILoginService).new

Unfortunately, this led to me to another roadblock.  When setting up expectations in Moq you do so with lambda expressions such as:

// C#
var mock = new Mock<ILoginService>();
mock.Expect(s => s.Login("steve", "****"));

While IronRuby has blocks and lambda's it doesn't have a way to express the above (at least that I know).  I'm going to dig around in the IronRuby source a bit to see if any ideas pop into my head, but at this point I'm not very hopeful. 

Friday, May 09, 2008 1:09:46 AM (Eastern Daylight Time, UTC-04:00) | Comments [3] |  |  | #
Wednesday, March 26, 2008
We've been using Rhino Mocks as our mocking framework for the last year and have had some good success with it.  Previously, we were writing our mocks by hand, which was a major pain in the ass.  While Rhino Mocks offers a lot of great features and has aided our testing efforts in many ways, it has also caused us some pain.  I've recently been hearing a lot of "buzz" about Moq, a new mocking framework developed by kzu.  This morning I read Daniel's "Why do we need another .NET mocking framework" post and I'm convinced that I need to give Moq a try.  A lot of the points in his article ring true to me, and make me wonder if I would prefer Moq over Rhino Mocks.  The interesting thing with trying a new mocking framework when you're involved in a large project that has already made a considerable investment in another mocking framework (Rhino Mocks) is how you go about trying it, and what you do if you prefer it to what we're currently using.  Ah the joys of software development.

I found the following links on the Moq google code homepage interesting:

Wednesday, March 26, 2008 12:58:54 PM (Eastern Daylight Time, UTC-04:00) | Comments [2] |  | #
Tuesday, March 18, 2008
Tonight I was chatting a bit with a co-worker about IronPython and IronRuby and decided to have a look at IronRuby.  Getting started is supposed to be pretty easy.

1. Checkout the IronRuby source from RubyForge

svn co svn://rubyforge.org/var/svn/ironruby

2. Install Ruby via the Ruby 1-click installer: http://rubyforge.org/projects/rubyinstaller/
3. Open a Visual Studio Command Prompt
4. Install the pathname2 gem by running the following from the command line:

gem install pathname2

5. Compile IronRuby by running:

rake compile

Unfortunately when running "rake compile" I get the following errors.

C:\Development\ironruby\trunk>rake compile
(in C:/Development/ironruby/trunk)
Read in 17 resources from "C:\Development\ironruby\trunk\src\microsoft.scripting
\Math\MathResources.resx"
Writing resource file...  Done.
Read in 49 resources from "C:\Development\ironruby\trunk\src\microsoft.scripting
\Resources.resx"
Writing resource file...  Done.
rake aborted!
Command failed with status (0): [csc /nologo /noconfig /nowarn:1591,1701,17...]
C:/Development/ironruby/trunk/rakefile:197:in `exec'
(See full trace by running task with --trace)

I did a little digging around to see if I could find out what was causing the above problem but didn't uncover anything.  In hopes of making some progress and seeing ruby running on top of the CLR, I decided to try and compile using the IronRuby VS.NET solution file. Compiling IronRuby using the VS.NET solution file built everything into the \bin\debug folder.  Once that was done I was able to run rbx.exe and do a little experimentation.  rbx didn't behave like I expected and seemed to be acting pretty flaky but I was able to put in some simple Ruby expressions and see the results I expected.  Now that I have the source downloaded and compiled I'm going to dig into things a bit more to see where things stand. 

Some resources that I came across that might be useful to others include:

Wednesday, March 19, 2008 2:44:25 AM (Eastern Daylight Time, UTC-04:00) | Comments [2] |  |  | #
Sunday, March 16, 2008
Tonight I decided that it was time that I checkout the Silverlight 2 beta release.  There are a number of things that I want to try with Silverlight, unfortunately, a bunch of other work has been keeping me.

I decided that the best way to get started would be with a real simple client.  Creating a simple silverlight control for showing recent tweets from Twitter seemed like it would be a fun experiment.  To get started I wanted to download some tweets from Twitter and show them in a ListBox.  Since LINQ to XML can be used with Silverlight 2, I figured the process would be pretty painless.  Of course I forgot about the fact that everyone had to go and try and make everything on the web secure.  From what I can tell, the fact that Twitter doesn't have, or has recently botched, their cross domain policy file is preventing me from being able to make any progress on my little silverlight project. 

Hopefully I'll figure out what the deal is with Twitters cross domain policy file.  It might be that I have something botched since when I run ScottGu's Digg sample I get the same "Download failure" that I get when attempting to download XML from Twitter.

UPDATE: Well it looks like the problem is that Twitter's cross domain policy file only allows *.twitter.com and *.discoveringradiance.com.  That sucks.  I guess accessing the XML directly from Twitter is out of the question.

Monday, March 17, 2008 2:40:30 AM (Eastern Daylight Time, UTC-04:00) | Comments [3] |  |  | #
Monday, January 21, 2008
After many, many, many long months of work, LINQ in Action is finally done!  Fabrice, Jim, and I are very proud of the final product and really hope you enjoy it.  We've already heard a lot of positive feedback from those who purchased the Early Access Preview from Manning, and are hopefull that LINQ in Action will be a valuable resource for everyone who is trying to add LINQ to their development toolbox.  My favorite quote thus far is from Ben Hayat on the LINQ in Action forums where he said "I had gotten other books on Linq, and this book is simply the BEST!".  Now for those of you who don't know Ben, it should be very clear that he's extremely smart and intelligent and you should believe everything he says, especially when it comes to what the best LINQ book is! :D 

Since the book is on the printers as we speak, it isn't yet available on Amazon for immediate shipping, however, I've been told it should make it's way over there in the next couple of weeks.  Given that, now is a great time to head over and pre-order it!  If you want the book sooner rather than later the best way to get it is directly via Manning's website.

To keep updated on the status of the book, including errata, code samples, or to ask Fabrice, Jim, or I any questions about our LINQ book you should drop by the LINQ in Action website or the author forums on the Manning website.

Monday, January 21, 2008 2:32:52 PM (Eastern Standard Time, UTC-05:00) | Comments [3] |  |  |  |  |  |  | #
Friday, September 28, 2007
Sam recently clued me in to a series of posts by his co-worker David Pallmann's that include a ton of great tips for using WCF.  I went through all David's tips on my train ride home a few days ago and was inspired to go through our code to confirm and/or change our services to use many of the recommendations that David put together.  If you're working with WCF, I definitely recommend that you check out David's tips and while your at it subscribe to his blog in case he drops any more tips the blogosphere's way.
Friday, September 28, 2007 2:20:02 PM (Eastern Daylight Time, UTC-04:00) | Comments [0] |  |  | #
Saturday, July 28, 2007
James Avery poses an interesting question in his "How long before ALT.NET becomes NOT.NET?" post.  I'm not really sure what it takes to get into the ALT.NET club, but from what I know I'm guessing I'd fit into the general "demographic".  Like James, I've also been wondering if and when more of the ALT.NET'ters will turn to Ruby on Rails (or alternates like Django).  I've thought about this a bit more lately since I've been spending a lot more time in Ruby and Rails.  In addition to wondering about other ALT.NET peeps, I've also thought a bit about where I want to go with my development efforts and whether I want to continue to focus on .NET as my primary means of making a living. At this point I don't see myself doing anything drastic.  Considering I only have 2 Rails projects under my belt and a heck of a lot more to learn about Ruby as well as Rails I think that's a pretty wise course to take.  I am going to continue on my path to learning Ruby as best I can, afterall it is my language for 2007.  I'm also going to continue to do projects with Rails, try and write a lot more Ruby and Rails related code from scratch (plugins make life way too easy), and evaluate if there is anything I've learned from Ruby and Rails that I can bring over into my .NET related work.  I'm also going to be keeping a close eye on IronRuby, and anxiously awaiting the day when they announce they can run Rails on top of it! 

At the end of the day, I believe learning Ruby, Rails, as well as many of the other things I'm looking into, will make me a better developer.  Whether or not I end up building the software I work on in .NET, Ruby, or Erlang doesn't matter much.  I think we all owe it to ourselves, as well as our customers, to question whether what we're using today is the best tool for the job.  We also owe it to ourselves to question whether we'd find more enjoyment in working with other languages and tools.  After all those questions are raised and answered we still need to make a decision based on where we are in life, what we have control over, and where we want to go in the future.

Perhaps before the migration to Rails starts, Microsoft will change its ways and learn a thing or two about what it takes to make ALT.NET developers happy.  Perhaps they'll realize that designers, wizards, and other magic isn't what where it's at.  Perhaps they'll realize that baking best practices into the platform is a good thing.  Perhaps they'll have a look at TextMate and realize it doesn't have any designers, yet Rails developers love it?!?!?  Perhaps they'll learn a thing or two from the success of Rails and stop the floodgates from opening.  What do you think?


Sunday, July 29, 2007 2:45:36 AM (Eastern Daylight Time, UTC-04:00) | Comments [4] |  |  |  | #
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) | Comments [7] |  |  | #
Monday, June 04, 2007
Although I'm not finished the application that I'm building with Ruby on Rails, I've decided that next up on my plate for new'ish technology is MonoRail.  Afterall, all the cool kids who aren't quite cool enough to be doing Rails seem to be going crazy for MonoRail.  As a former web guy I've done a lot of WebForms development, so its time that I see what all the hype is surrounding MonoRail.  I was originally going to build the business/data layer with LINQ to SQL, but I think I'm instead going to go all Castle and use ActiveRecord along with Ayende's NHibernate Query Generator

Unfortunately, I'm not smart enough to be able to figure out how the heck to get the MonoRail project templates to show up in VS.NET.  I'm guessing they're not necessary, but for a MonoRail newbie they seem like they'd be useful.  I'm planning on building things from the trunk, as such I tried following these instructions on Using the Trunk.  Can anyone offer any advice on how I might get the project templates working?  Should I give up and just go with the very old MSI that's available?

UPDATE: It helps if you actually read the documentation.  Running the RC2 installer and then following the necessary steps in Using the Trunk worked perfectly.

Tuesday, June 05, 2007 2:59:02 AM (Eastern Daylight Time, UTC-04:00) | Comments [4] |  |  | #
Tuesday, May 15, 2007
Back in February I posted about when the right time for a new technology is.  As some likely guessed after seeing my review of Everyday Scripting with Ruby and the list of books that were on my next up list I decided to go with Rails as my new technology for one of the projects.  In a future post I'll detail how I've found the experience, and how it compares to .NET land but that's for another day.  Today, I'd like to point out the fact that nobody writes anything cool in .NET.  At least nobody writes any of the cool stuff that I need in .NET.  Ok, perhaps I'm exagerating a bit....in actuality the fact is that nobody writes social network visualization libraries in .NET. :)  The project that I'm working on that's using Rails involves social networks.  One of the things that I'll be getting to shortly is the actual visualization part of the project.  What I'd really love is if someone would write something as cool as this, in Silverlight.   That way I could have my Rails application call .NET code.  What could be better to piss off the Rails purists?  Afterall, I'm supposed to have given up all things .NET by now and truelly converted to Rails, right?  Ok, moving on....who wants to write prefuse in Silverlight?  It'd be a killer demo application to show off the capabilities of Silverlight and would undoubtedly make it so the only RIA platform anyone chooses is Silverlight.  Flash who?  Java FX what?  Flex...I think not.  With prefuse.NET, Silverlight is guaranteed instant mass approval.  Or maybe it'll just make me happy that I get to write .NET code that will access a RESTful Rails service for data that lives inside a rhtml page.  Either way you win, right?

In all seriousness I think Silverlight would be a great technology for building web based network visualization software.  While there's no way I'll have time to write something as fully functional as I'll need, I think I'll apply the learn a new technology even if it will take longer rule and give getting a basic network visualization demo in Silverlight working.  Luckily, I think some of the Silverlight samples (such as this one) might get me moving in the right direction.  If anyone cares to lend a hand, give me a shout!  Instance fame and fortune is within your grasp!


Wednesday, May 16, 2007 3:14:53 AM (Eastern Daylight Time, UTC-04:00) | Comments [0] |  |  |  |  | #
Wednesday, March 07, 2007
I'm going to document the things I run into as I transition from the May 2006 CTP of LINQ to the full March 2007 CTP of Orcas. Tonight after sorting out my data source issue I ran into a compile error with my Visual Basic code samples that are using XML Axis properties. The error is "XML Axis properties do not support late binding". Hopefully I'll be able to post back here shortly with an answer to why I'm getting this....

UPDATE:  Thanks to a comment from Avner I figured out that this is due to a regression in the capability of VB9 to infer types.  Previously things worked swimmingly with the following code:

    Dim rss = XElement.Load("rss.xml")
    Dim items = rss...<item>

With the March CTP the type of "rss" needs to be explicitly defined like so:

    Dim rss As XElement = XElement.Load("rss.xml")
    Dim items = rss...<item>

I like the old way better :)


Thursday, March 08, 2007 3:00:27 AM (Eastern Standard Time, UTC-05:00) | Comments [4] |  |  |  | #
Tuesday, March 06, 2007
Yesterday I mentioned I was having some trouble adding a Data Source in Orcas. I'm happy to report that following the instructions in the Orcas March CTP on Vista Database Connections Problem Solved post resolved my issue. Once I commented out the SQL Server CE Data Provider in the machine.config everything was back to normal.
Wednesday, March 07, 2007 2:08:35 AM (Eastern Standard Time, UTC-05:00) | Comments [0] |  |  | #
Monday, March 05, 2007
I had a jolly good fun time tonight updating my code samples to the March CTP of Orcas.  Well, actually, I'm not quite finished as of yet because of the wonderful error in the title of this post.  It appears VS.NET Orcas doesn't want to let me recreate my data connection for my database that I'm using for some LINQ to SQL examples. Woot!  Hopefully I'll figure out what the dealy is shortly because I've got chapters I need to finish. :)

Tuesday, March 06, 2007 3:20:47 AM (Eastern Standard Time, UTC-05:00) | Comments [1] |  |  |  | #
Tuesday, February 20, 2007
I've been thinking recently that I need to learn something new. Whether it be a new technology on the .NET side of the house, or a new language, or a new web framework. I'm not sure what, but, I definitely feel like I need something new that will cause me to stretch my mind a bit.

I've had the itch to dive into WPF for a while, but don't have a whole lot of time at the moment to do anything on that front.  While I do have several ideas for little WPF apps I'd like to see built for myself I have concerns it'd be a wasted effort since my design/UI skills have diminished over the years, and what sense is building a WPF app if you can make it look slick as all get out? 

I've also been thinking a bit about trying my hand with a new language.  The top contenders would be Ruby, via Rails, or Python (with IronPython).  I'm leaning more towards the Ruby/Rails track since it would involve me stepping almost completely out of my comfort zone. 

I have a few things on my plate that I could choose to do using non .NET technologies.  Of course the problem is that I could undoubtedly do them much faster using my bread and butter technologies.  The benefit of the .NET appraoch would be that I could get more things done and perhaps have extra spending money due to being able to do more of the little projects I've been asked by peeps to lend a hand on.  The downside is that I'd still feel like I need to learn something new, and stretch my brain a bit.  I've run into this same scenario many many times in the past, and always went with the approach that would get things done the fastest since I never seem to have enough time available for anything else.  The problem, of course, is one of the main reasons for doing little side projects outside of work is to stretch yourself in ways that you might not be able to otherwise.

When confronted with such dilema's how do you choose?  Do you go safe, and stick with what you know, or do go with the more difficult, and potentially more rewarding path of trying something completely new?

Wednesday, February 21, 2007 3:52:49 AM (Eastern Standard Time, UTC-05:00) | Comments [9] |  | #
I'm sure Linux users across the world are going crazy about the fact that they can now run Visual Basic .NET, courtesy of Mono!  Or not.

In all seriousness, it is pretty cool that the folks on the Mono project have added support for Visual Basic.  I wonder how good the WinForms story is these days on Linux.  I know the last time I checked it out for the Mac, it wasn't a pretty picture.

Wednesday, February 21, 2007 3:34:47 AM (Eastern Standard Time, UTC-05:00) | Comments [1] | #
Friday, February 16, 2007
Let's face it, .NET is meant to rule the world. :)  With that out of the way let's get onto business.  Will someone from Apple please talk to the folks that run the engineering team and get them to dedicate some peeps to work on Cocoa#, or perhaps something completely Apple'ish such as iDotNet.  While Mono has made some great strides on the Linux and Windows sides of the world, it's still severely lacking when it comes to the Mac.  More specifically, Mac GUI's.  As Uncle Mac points out, running GUI applications on the Mac simply doesn't feel right.  Everything is very polished on a Mac, and X11 apps just aren't cutting it.  Since I'm asking for things I want that I have more or less no shot of getting, I might as well add this onto my list right?

Friday, February 16, 2007 6:03:18 PM (Eastern Standard Time, UTC-05:00) | Comments [1] |  | #
Friday, February 02, 2007

Boooooooooooooo! :)  I'd really like to get a new release that includes everything LINQ related that we saw in the May 2006 CTP so I can start updating all my code samples and use all the new wizz bang features that I'm sure they've added.

Update: I think I misread the post above.  The next Orcas CTP isn't being pushed to March, it's just a bunch of LINQ to SQL stuff that isn't making it into February that will show it's face in March.

Friday, February 02, 2007 2:14:43 PM (Eastern Standard Time, UTC-05:00) | Comments [0] |  | #

John Rusk left a comment on my Developers ditching Microsoft for Rails post and brought to light the fact that developers might not be leaving because of what Rails is doing right, but instead because of what .NET is doing wrong.  I definitely agree that many of the reasons people leave the .NET world for technologies like Rails is because working in .NET isn't as smooth as it should be.  One of the things that makes Rails so successful is its focus, and the embracing of constraints.  Rather then trying to be everything to everybody, Rails is focused on a specific vision.  As I've said in the past, Rails is opinionated software.

For those looking for Rails-ish frameworks in the .NET world you might want to checkout SubSonic and Castle's ActiveRecord and MonoRail projects.  I just had De-ja-vu.

Friday, February 02, 2007 2:05:07 PM (Eastern Standard Time, UTC-05:00) | Comments [0] |  | #
Thursday, February 01, 2007
I've been reading a lot of stories lately about developers leaving the friendly confines of .NET Land for Rails and other non-Microsoft technologies.  Perhaps the most notable being Mike Gunderloy of  The Daily Grind fame.  You can read more about Mike's journey over on his A Fresh Cup - Notes from a recovering Microsoft addict blog.  Also of interest is the Forums on the softiesonrails.com site. 

I actually thought about switching my blog engine over to Mephisto to get a little taste of Rails, however, since I'm hosting this on a Windows box the thought was short lived.

Friday, February 02, 2007 4:26:46 AM (Eastern Standard Time, UTC-05:00) | Comments [4] |  | #
Search
Archive
Links
Categories
Admin Login
Sign In
Blogroll
Themes
Pick a theme: