Professional Programmer Notes

or just call this my soapbox

Posts Tagged ‘c#

Gestalt = Low-Lying Awesome

leave a comment »

Microsoft appears to be betting big on Silverlight.  When the Silverlight 1.0 bits were released in 2007, my initial thoughts were, “Yay, Flash for .NET developers.”  As Microsoft pushed forward with version 2, version 3, and now version 4 of Silverlight, those sarcastic thoughts have subsided to make way for more genuine curiosity.  How did that happen?

Well, for starters, Microsoft delivered real features.  Initially, Silverlight demos were all about media (music and video).  In addition, Microsoft touted the interopability between dynamic languages like vbx, c#, python, ruby, and javascript.  Then, that interopability was sidelined and Silverlight applications started to emerge.  Which was interesting.  In fact, Silverlight 2 had enough features to stir up debates in the enterprise over which RIA technology was best suited for enterprise applications: Flash 8 with Flex or Silverlight 2.   Then, Microsoft played their wildcard.  They made Silverlight play nicely with … ugh … Mac OSX.  Out-of-browser Silverlight applications made me raise my eyebrows for a technology that I had quickly written off as a “fad”.

That might still be the case.  I won’t make a claim either way.  But, Silverlight and RIA are spaces where Microsoft continue to innovate.  Gestalt is a very good example of that last statement.  Gestalt is built atop a foundation consisting of XAML, Silverlight, and dynamic languages.  It enables web developers to script their way to rich internet applications in a way that both Flash and Silverlight seemingly missed. 

With that said, it is difficult to pinpoint exactly what value Gestalt adds, but you feel it when you’re molding some python, ruby, or javascript hackery into a magical Silverlight-powered application that just works.

The technology appears to still be more of a proof-of-concept than a supported product.  But, it makes a strong case for embracing XAML and Silverlight. 

Checkout the website and the samples at http://visitmix.com/labs/gestalt/.

Advertisement

Written by curtismitchell

February 11, 2010 at 9:59 pm

Posted in .net, CSharp, Javascript, web

Tagged with , , , , ,

Should IronRuby be called NSignificant?

with 2 comments

Update:  You’re more than welcome to read my angry rant below.  However, I felt it would be more responsible if I summed up a few points right here at the very beginning:

  1. Dynamic languages are awesome for things like web development, scripting, and embedded customization engines for bigger applications.
  2. IMO, Ruby is more sought after for its web frameworks, scripting/automation (think Rake), and unit testing frameworks than its potential as an embedded language (unlike Python and Lua).
  3. John Lam’s open source Ruby extension, RubyCLR, enabled CRuby to use .NET types pretty effectively.  In other words, I can have a Rails application using .NET code on the server-side if necessary.  Or, I could use rspec to unit test my .NET libraries.  Both could be done while leveraging the existing Ruby implementation and .NET Framework.
  4. When John Lam started work on IronRuby, RubyCLR was left to a community that let it fall by the wayside.  In the meantime, IronRuby has not been nearly as impressive as IronPython.  There, I said it.

Now, feel free to read the original rant below.

 

Harsh, right?  I think so.  But, it is time I voice my concerns about the Microsoft’s adaption of the Ruby language.  My intent is to put it all out there, and see how the community feels.  At the end of the day, my opinion is my own.  However, the voice of the community could cause change – of my opinion or otherwise.

What’s beef?

Let me start by saying that I am a .NET developer.  I have specialized in Microsoft technologies over my eleven year career thus far.  In addition to being a member of our local .NET user group, TriNUG, I am also a member of the local Ruby user group Raleigh.rb.  I do not speak for these organizations, but I wanted to point out my involvement with both technical communities.

In addition, my background is web-heavy with a few years of desktop development in there as well.  That is to say that Rails was my introduction to the Ruby language.  From the perspective of a web developer that dug Javascript before Prototype, JQuery and MooTools, Rails whet my appetite for more Ruby-like development in my paying job.  I was amongst the early .NET developers that thought, “Wow, it would be great if we could use a language like Ruby with the CLR!”

In my excitement, I went out and learned about great projects like RubyCLR, John Lam’s old Ruby/CLR bridge, and Ruby.NET, the ruby compiler started by Queensland University of Technology. 

Both projects had great merit.  The former allows a developer to call .NET assemblies and use .NET types from Ruby (and vice-versa though painful), while the latter aimed to be a full implementation of the Ruby language atop the CLR.

I think those two projects could have adequately fulfilled my dream.  More on that later.

Back to my beef.  My beef is that Microsoft killed at least one of these projects.

First, they brilliantly (sans sarcasm) hired John Lam, the developer of RubyCLR.  That was an excellent decision on Microsoft’s behalf.  Initially, I hoped John Lam would continue his work on RubyCLR or a RubyCLR-like project with Microsoft’s resources.  Unfortunately, that was not in their plans.  Instead, IronRuby was started and RubyCLR died.

Secondly, the Ruby.NET project went seemingly inactive (though Open Source) after IronRuby started gaining steam.  It now seems to be stuck at version 0.9 which was working with Ruby 1.8.2.

My beef is that these are two projects the .NET community needs.  IronRuby will become more necessary as Microsoft convince us of such.  But, IronRuby is seemingly being developed at the expense of two very good projects.

Why RubyCLR and Ruby.NET over IronRuby?

Let’s talk web.  As a web developer, my opinion is that dynamic languages are better suited for the web than static languages.  In fact, I may be alone in this, I assert Classic ASP with ActiveScripting fits the web development paradigm better than ASP.NET (not including MVC).  My assertion is based on the ability to make a change and instantly review it by refreshing the page.  This rapid feedback cycle is key to making web development most productive.

Fans of ASP.NET and static languages could make a strong argument for performance.  Simply put, dynamic languages do not perform as well as static languages.  However, this point is less poignant when talking about the web.  Dynamic languages are “good enough” for web development.  In fact, bottlenecks in web applications are usually discovered at the point of disk i/o or data access. 

Wouldn’t it be great if we could optimize our disk i/o and data access code with a static language, but use a dynamic language like Ruby for the bulk of our web applications?  Well, RubyCLR enabled that!  If we focus on unidirectional communication be Ruby and .NET – that is Ruby code calling .NET assemblies, we’ll see that RubyCLR is the bees knees!  Imagine doing your web development in Rails while being able to call .NET assemblies for things like disk i/o (I can’t imagine replacing Ruby’s ActiveRecord with a .NET ORM).

On the flipside, Ruby.NET was in the process of enabling developers that know and love Ruby to use the .NET Framework and all its libraries in a statically typed manner.  This means, not only can I call .NET assemblies from Ruby, but I could write .NET assemblies in Ruby.  How awesome is that? (don’t answer)

I believe Microsoft’s most underestimated contribution to developing in Ruby will be easing Rails deployment on IIS.  That is the key piece to the puzzle and the metaphoric “milkshake that would bring all the boys to the yard.”

If you don’t have something nice to say…

I’ll end by saying a few good things about IronRuby and Microsoft.  As a developer that uses Microsoft’s technologies, I continue to believe that Microsoft will (a) make mistakes and adjust to correct them or (b) continue to be an agent of change that brings the rest of us into the light.

With that said, IronRuby, IronPython, and the DLR are bringing capabilities to .NET development that either didn’t exist before or were a pain in the neck to implement.  I haven’t really wrapped my head around doing web development with IronRuby, yet.  I hope the experience will be as pleasant as doing web development with Ruby.  But, the ability to add scripting to a desktop application utilizing IronPython or IronRuby is very nice.

Now, it’s your turn

I can go on and on about this topic.  Those that have had this conversation with me in-person can attest to that.  But, I’m really interested in how the community feels.  What’s up?

Written by curtismitchell

December 9, 2009 at 12:06 pm

Posted in .net, Ruby

Tagged with , , , , , ,

Richmond Code Camp 2009.2

with 2 comments

Wow! What an event!

This weekend, I joined ~400 others for the Richmond Code Camp and a good time was had. As others have noted, the hardest part of the day was choosing which talks to attend due to a schedule full of excellent topics and speakers.

I started off with Justin Etheredge’s talk on Linq Expressions. This was 75 minutes of great slides and polished demos of basic to advanced Linq concepts. I left that talk more educated and less scared of the power of Linq Expressions. Justin has an unbelievable understanding of how Linq works and an amazing ability to convey that to the layman with nothing more than a stock photo of a cat and a VM with Win 7 and VS 2010.

Second, I attended a talk that was missed from Raleigh’s Code Camp two weeks earlier. I went to John Feminella’s talk on Ruby for C# developers. John gave .NET developers a great introduction to the Ruby language using IronRuby (I thought that was brave at this point). To my surprise, John held up his end with great content and examples, and IronRuby held up its end with stability and support for most of the features of Matz Ruby (the original implementation of Ruby).

Next, I decided to checkout Open Spaces. The evening before, I jokingly suggested that the audience would convince Kevin Hazzard to present something on the DLR at Open Spaces since he was not officially presenting. Well, I guess they did! Kevin led a discussion on IronPython and the DLR that included some very nice demos. He also discussed C# 4.0’s new “Dynamic” type and how it actually works. I gained a lot of insight on when and where the DLR and Dynamic Languages on .NET are useful. And, while I love Ruby, IronPython is making the Python language very attractive to me.

Another talk that I was able to attend was by Chris Love. He talked about building quality ASP.NET applications faster. I know Chris to be a very experienced developer. He just completed an updated version of a book I found to be very practical when I was getting into more advanced ASP.NET concepts, ASP.NET 3.5 Website Programming: Problem – Design – Solution. His talk drew off of his experiences building applications and sites for his clients. He talked about architecture as well as development practices. I recommend his talk to anyone doing ASP.NET development that is looking for practical advice on how to manage it all from start to finish.

In the last time slot of the day, I presented Spark, an ASP.NET MVC View Engine, to a great audience. This was essentially the same talk that I gave a couple of weeks earlier at Raleigh’s Code Camp, but I made some modifications for the Richmond crowd. Here are the slides from that talk:

Enjoy!

Written by curtismitchell

October 5, 2009 at 3:04 pm

Posted in .net, CSharp

Tagged with , , , , ,

Ruby-like Times method for Ints in C#

leave a comment »

Yesterday, @mccartsc did a presentation on Linq for a group of us at work. As part of his presentation, he demonstrated an extension method he threw together to give .NET Integers the Times method that Ruby programmers have enjoyed for years.

Basically, the n.Times methods is passed a block that it will execute n number of times. In Ruby, you could do something like this:

5.times {|x| puts x }

That trivial line of code would output integers 0 through 4.

With such a trivial use case, you may be wondering “Why would anyone want to do that?” Well, @mccartsc and I had a discussion about coding without traditional For Loops. Foreach Loops are great for enumerating IEnumerable objects, but it is not a replacement for the traditional For Loop. We thought, “Wouldn’t it be great if you could use a Ruby-like Time method to execute a block of code an arbitrary number of times?” So, @mccartsc built it as part of his Linq demonstration.

Here’s how he did it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqDemo
{
    static class Extensions
    {
        public static void Each<T>(this IEnumerable<T> collection, Action<T> action)
        {
            foreach (var item in collection)
                action(item);
        }

        public static IEnumerable<int> Range(this int max)
        {
            for (int i = 0; i < max; i++)
                yield return i;
        }

        public static void Times(this int i, Action<int> action)
        {
            i.Range().Each(action);
        }
    }
}

@mccartsc created three extension methods to implement the Times method. “Each” is an extension method for IEnumerable types. It passes each member of a collection into an Action delegate.

“Range” is an extension method for Int types. It creates a zero-based IEnumerable collection out of an integer. For instance, 5.Range();, would return a collection consisting of integers 0,1,2,3,4.

Finally, “Times” is another extension method for Int types that allows a user to execute an action an arbitrary number of times by using the aforementioned Range and Each methods. Once I have these extension methods in my C# project, I can execute code like this:

5.Times(i => Console.WriteLine(i.ToString()));

The above would output:
0
1
2
3
4

I think that’s pretty cool.
Thanks @mccartsc for the code and the demonstration.

Update: @mccartsc got a blog! Check him out at http://scmccart.wordpress.com/.

Written by curtismitchell

May 1, 2009 at 9:13 pm

Posted in Uncategorized

Tagged with , ,

Improve page load performance in your ASP.NET MVC site

with 3 comments

As ASP.NET MVC become more popular in the enterprise and behind high-traffic commercial web sites (like Dimecasts.net), developers will look for ways to increase performance.

One well known way to increase performance of any website is to combine files to minimize HTTP requests (see Yahoo! Performance Rules). The reason is that most modern browsers use two threads to load a given page and all of its assets (css, js, images, etc.). This post will give a quick walk-through of an ASP.NET MVC implementation of a CSS consolidator.

In typical MVC fashion, I will give a quick breakdown of the model, the view, and the controller.

Let’s start with the controller.

My controller has one need: it provides a pretty url for me to point my tag to retrieve passed-in stylesheets. I implemented a controller called StaticController and gave it an action called CSS. Here is a snapshot of the action:

        public ActionResult CSS(string id)
        {
            if (String.IsNullOrEmpty(id)) return View();

            string[] filenames = id.Split(',');
            string path = HttpContext.Request.ServerVariables["APPL_PHYSICAL_PATH"];
            path = String.Concat(path, @"Content\"); // path to css files

            string cssData = Models.StaticCSS.GetContent(filenames, path);
            ViewData["css"] = cssData;

            return View();
        }

Quick explanation of the above code:
The action uses the default MVC routes (for simplicity). So, the id parameter is used to pass a comma-delimited string of stylesheet names. The path to the Content directory (the default folder for stylesheets) is derived, combined with each file name in the id parameter and passed to the model.

Let’s see how our model works.

The model is named StaticCSS and here are the methods:

        public static string GetContent(string[] filenames, string cssDir)
        {
            StringBuilder sb = new StringBuilder();
            if (filenames.Length == 0 || String.IsNullOrEmpty(cssDir))
return String.Empty;

            foreach (string f in filenames)
            {
                string filepath = (f.EndsWith(".css")) ?
String.Concat(cssDir, f) : String.Concat(cssDir, f, ".css");
                sb.Append(@"/* Start CSS file */");
                sb.Append(Environment.NewLine);
                sb.Append(GetFileContents(filepath));
                sb.Append(@"/* End CSS file */");
                sb.Append(Environment.NewLine);
            }

            return sb.ToString();
        }

        public static string GetFileContents(string file)
        {
            try
            {
                using (TextReader textReader = new StreamReader(file))
                {
                    return textReader.ReadToEnd();
                }
            }
            catch(FileNotFoundException)
            {

            }

            return String.Empty;
        }

Quick explanation:
The public static method, GetContent loops through a list of files, combines their contents into a string, and return the string. The GetFileContents method opens the file and returns the contents.

If we look back at the remaining code in our action:

            ViewData["css"] = cssData;

            return View();

We are adding the css file contents to the ViewData hash and calling the view.

Here are the important parts of the view:

<%
    Response.ContentType = "text/css";
    Response.ContentEncoding = Encoding.UTF8;
    Response.Write( Server.HtmlDecode(ViewData["css"].ToString()) );
%>

We are setting the content-type to “text/css”, which is important in standard-compliant browsers (not IE). We’re setting the encoding dumping the content to the page. These three lines essentially turn the view into a standard css file.

Finally, to use this code I would simply add the following line to any view requiring css files:

<link href="/Static/CSS/cssfile1,cssfile2,cssfile3" rel="stylesheet" />

This would download cssfile1, cssfile2, and cssfile3 in one HTTP request instead of three.

This is a simplistic approach that doesn’t care (yet) about the amount of memory used to load very large css files. But, if you choose to follow this model, I would love to hear how it performs for you.

Written by curtismitchell

March 17, 2009 at 10:42 pm

Posted in .net, CSharp

Tagged with , , ,

Not really a Fan, but still kind of Groovy

with 2 comments

Fan is a very young programming language with some promise.  The features of the language are more pragmatic than theoretical.  This means, Fan, like Python and Ruby, should allow you to be productive in a concise manner.  The syntax of Fan left a lot to be desired.  It is not the prettiest language, but hopefully, syntactic sugar will be added in the future to facilitate Fan’s adoption.The killer feature that Fan promises to deliver is the interoperability with both the Java Virtual Machine and the .NET Runtime.  Currently, one or the other are required to compile Fan source code.  However, Fan currently does not offer much in terms of interoperability with Java and/or any of the CLR languages.  That is disappointing for now, but the language is extremely young.  Powerful features like that take time.

While a more developed Fan will find its niche audience of developers, I wonder about the true utility of such a language.  The JVM already has the well-known scriptingly awesome language known as Groovy.  I do not qualify as a Java developer, but I hold Groovy in high regard because of its performance, language features, and *gulp* use of the JVM.  Java reservations aside, Groovy is a language I look forward to learning.

.NET is not absent of nice scripting languages either.  Boo is one such language, noted for its Python-like syntax. Oh, and did I mention IronPython?  It is also noted for its Python-like syntax, but .NET-like performance.  Perhaps, the most awaited .NET language is IronRuby, a dynamic language with the features of ruby and the power of the .NET Framework.  It is going to be great.

There is one other .NET language that I think deserves mention.  It is called Nemerle.  Nemerle is a static language, much like C#.  However, Nemerle implemented features like type inference long before the release of C# 3.0.  Since the latest release of C#, Nemerles advantages have become less pronounced.  But, it still differentiates itself from C# with features like Macros that allow you to customize the syntax of Nemerle (think domain specific language).

Nemerle is a pretty mature language.  It has some integration with Visual Studio 2005.  Also, the Nemerle compiler is written in Nemerle.  That could be a sign of a pretty usable language.

Nemerle is open-source.  I don’t know if it is actively developed today.  However, I recently came across a blog post that sums up some of the features of Nemerle.  That post was the inspiration for this post actually.  Onur went as far as to call Nemerle “C# glorified.”  I’m not sure I agree with that.

However, I believe Groovy is definitely “Java glorified.”   Maybe Nemerle is a little Groovy.

Written by curtismitchell

August 3, 2008 at 4:14 pm

SnippetCompiler is great, but…

with 2 comments

…we don’t have to use it for quick compilable chunks of .NET goodness.  As detailed on marlongrech.wordpress.com, we can use TestDriven.Net to run small parts of code in the Visual Studio.NET debugger.

The code is not required to be a test case for use in a unit testing framework.  It can be an arbitrary method that just does some processing.  The key to using this technique, is to make sure you set a breakpoint.  That way you can manipulate parameters and actually get feedback about what the method is doing when it executes.

This is yet another reason we should buy TestDriven.Net.  It can pay for itself within a day or two.

In addition to SnippetCompiler and TestDriven.Net, Powershell is very useful for this kind of snippet testing as well.  But I’ll have to defer that post for another time.

Written by curtismitchell

July 2, 2008 at 6:04 pm

Fix Visual Style of Tab Control in .NET

with one comment

I was having an issue with my tab contols looking very ugly:

Ugly Tab

These controls did not look anything like other fancy tab controls that I have seen recently in XP and Vista.    My tab control sucked.  Looking at it took away my desire to use my application.

I made several attempts at remedying the issue.  I tried one combination of property changes after another to no avail.  I was on the verge of creating a new owner-drawn tab control ( I had created a new project in Visual C# Express and everything) when I stumbled upon a CodeProject article.

I didn’t follow the article all the way through because it seemed to be written for an older version of the Framework and IDE.  But, it reminded me that there is an Application.EnableVisualStyles() method*.

I swiftly made sure I called that method before any controls were drawn, saved my hard work, and clicked the VS “Play” button with the excitement and anticipation of a child in line at Chuck E. Cheese.  That all died quickly when I received a screen containing the same ugly tabs staring back at me.

I checked the return value of the Application.RenderWithVisualStyles property and discovered my application was not using visual styles.  Thanks to the MSDN documentation, I quickly found the problem.  I had XP’s Appearance set to Windows Classic style.  Doh!!!

After changing XP’s Appearance back to Windows XP style, I had beautiful tabs:

Beautiful Tabs

To recap the solution:

  1. Call Application.EnableVisualStyles() before any controls get rendered.  In Program.cs just before Application.Run is a good place.
  2. Make sure you are allowing your OS to use visual styles.
  3. Don’t judge me for being absent-minded most of the time.  I’m trying to get it out of the way so that I won’t be absent-minded when I’m older.

* I probably saved over that memory with a Mitch Hedberg joke or my wedding anniversary date.

Written by curtismitchell

May 17, 2008 at 9:38 am

Posted in .net, CSharp, vb.net

Tagged with , , , ,

BDD in .NET the way the big kids are doing it

leave a comment »

This is an introductory article about using test/unit and test/spec for behavior driven development (BDD) in .NET.

Target audience:

This article is for you if:
1. You are a programmer/developer that uses Microsoft’s .NET Framework
2. You are interested in doing behavior driven development
3. You realize that while .NET has some nice up and coming BDD Frameworks, they still lag behind test/spec and rspec in features and usability.

Assumptions:

This article assumes that the target platform is Windows XP or greater (or lesser, depending on your experiences with Vista). These steps were not tested on Mono (by me), nor did I test on any OS not previously mentioned. I also assume that you are familiar with Ruby and gems. Also, I assume that you are comfortable with changing environment variables within Windows, which may require elevated privileges.

Required software/tools:

1. Ruby programming language
2. DiffUtils
3. RubyCLR (gem)
4. test/spec (gem)
5. zentest (gem)

Installation:

Download the One-Click Installer for Ruby from here. Double-click the executable and follow the wizard. Installation is a breeze with the One-Click Installer.

Second, download the DiffUtils from here. I suggest you download the installer instead of the zipped binaries. I tried the binaries initially, but found a missing dependency (try figuring that out). After downloading the installer, run it and remember the installation path for later use.

To complete the installation, we need to add the installation path to the PATH environment variable. We can do this by hitting the Left Windows key + Page Break. Select the “Advance” tab and click on the “Environment Variables” button. Select the variable named Path in the System Variables list. Click the “Edit” button under the list to bring up the edit dialog. Append a semi-colon and the installation path to the end of the “Variable Value” text box. BEFORE you exit out of the dialogs, click the “New…” button under the User Variables list. Create a variable named “HOME” and set its value to your user directory that has your “My Documents” folder e.g. “C:\Documents And Settings\Curtis”. Press the “Ok” buttons to exit all of the dialogs, and reboot your computer. The last step is very important, so try not to skip it.

Now that we have Ruby and DiffUtils installed, we can install the requisite ruby gems. Installation of the gems is straight-forward. At the command prompt, use a variation of the following command to install each gem:

gem install [gem name] --include-dependencies

I suggest you add the –include-dependencies flag to the gem commands in order to save a few prompts. Once the gems are installed, you’re all set. You don’t need me.

Usage:

I’ll add a few notes about how to use your new setup. This is where all your hard work pays off.

First, create a new C# Class Library solution in Visual Studio. I suggest you change the output directory to “../bin” in order to have MSBuild output your assembly to a “bin” directory in the root path of the solution.

Open your text editor and create a new file called “.autotest” in the root path of your solution. Note: This may be difficult to accomplish in Notepad since the filename is essentially an extension in Windows. I suggest using Notepad++ or Scite (installed with the one-click Ruby installer) instead.

This file is really just a Ruby source file used by the ZenTest gem. Copy the following code into the file and save it:

class Autotest
  #This method tells autotest to run all of the Ruby source files in the 'test'
  #directory whenever a file changes; namely a test file.
  def tests_for_file(filename)
    return Dir["/test/**/*.rb"]
  end
end

#This block tells autotest to run any file in the 'test' folder that starts with
#'test_' and ends with 'rb' whenever a 'dll' file changes in the 'bin' directory
Autotest.add_hook :initialize do |at|
  at.add_mapping(/^bin.*\/.*dll$/) do |filename, _|
    puts "This file changed: " + filename
    at.files_matching(/^test.*\/test_.*rb$/)
  end
end

This assumes the only .rb files in the solution’s path will be files intended to test the .NET assembly that is being created.

Next, create a new file in your text editor. Call it “test_mydotnetlib.rb” or something cheesier. But, be sure to prefix it with “test_” and save it into a folder called “test” under your solution’s path. The following steps will detail how to actually create a file to test your code.

All test files will require a few standard declarations in order to work properly:

require 'rubyclr'
require 'test/unit'
require 'test/spec'

include Test::Unit

#includes the .NET assembly intended for testing
reference_file 'C:\Dotnet\src\MySolution\bin\MyCustomLibrary.dll'

There are two points to note about the above line: First, the whole path to the output of your class library project should be specified. Secondly, this line points to a ‘bin’ directory located under the Solution’s path. This isn’t the default path of output for Visual Studio, so if you skipped the step above where I suggested you change the output path of your class library project, now is the time to correct that.

Now, we can begin writing our actual tests. Add the following to your test file and save it:

describe "MyCustomLibrary" do
  before(:each) do
    @speaker = MyCustomLibrary::Speaker.new
  end

  it "should say hello" do
    @speaker.sayHello.should.equal 'hello'
  end
end

At this point, we can start up Autotest. Open a command window and change directories to the root of your Visual Studio solution. Type “.autotest” and hit enter. Autotest will run the test that you just saved. It should show that you have 1 failed test. That’s great!

Create a Speaker class in your .NET project. Implement the sayHello method so that it returns the string “hello”. Build your project, and watch Autotest re-test your code again. This time the test should pass.

Sweet! This is just the tip of the iceberg of what can be done with RubyCLR.

This solution works because of the creativity and hard work of some great developers. I’m going to run the credits before the end, just to make sure you stick around to acknowledge their efforts:

Credits:
John Lam (RubyCLR) and the person or people continuing to develop it
Christian Neukirchen (test/spec)
Nathaniel Talbott (test/unit) and the person or people that continue to develop it
ZenSpider (ZenTest)
Paul Eggert (DiffUtils)
Venkat Subramaniam (for his inspiring presentation on DNRTV.com)
And, of course, Matz and the rest of the Ruby team

I also appreciate the efforts of all others involved whether directly or indirectly.

Now, back to the code…

Written by curtismitchell

May 5, 2008 at 7:37 pm

Posted in CSharp, Ruby, Testing

Tagged with , , , , , ,