Wednesday, September 12, 2007

One of the disadvantages of using non-mainstream .NET languages, like Chrome, F# and IronPython is that the most of the popular and most useful VS.NET add-ins tend not to support them. I can live with this for most things (although its getting harder as these add-ins get better), however, one thing that I can't live without is not being able to run my unit tests without leaving Visual Studio.

I'm using Chrome in my current project, I also use JetBrains ReSharper. ReSharper currently supports C# and VB.NET (JetBrains say that they have no plans to support Chrome :-( ). Its a marvalous refactoring tool and it also comes with a built in unit test runner*. This built in test runner will allow you run or debug a test by clicking on an icon in the left-hand gutter of the editor. Or, you can run your tests via a dockable test browser window that lists all of your test fixtures and tests in the current solution. As you can imagine, this is really convenient; so much so, that with a little imagination you can almost use VS.NET like an interactive IDE similar to a Smalltalk workspace.

Unfortunately, ReSharper's unit test runner doesn't understand Chrome and this put me on a search to try and find a unit test runner that did. At the very least I was hoping for an add-in that would find the tests in a compiled assembly, like NUnit does, and let me run them all the tests by a key-stroke or mouse click, if not individually. 

I could only find two other in-IDE unit test runners for Visual Studio. Of the two I found I tried TestDriven.NET - nada; then I tried ExactMagic’s TestMatrix - zilch. I wasn't surprise by this and in a way I was sort of relieved, I was reluctant to install yet another VS.NET add-in just to run some tests when I already had a perfectly good add-in that could do just that.

At this point I had a brain wave – perhaps I could run my tests via C#.  To try this I added a C# project to my Solution and created a class in the new C# project. I then added the necessary NUnit assembly and using references to the new project and then marked the new C# class as a TestFixture.  Then I inherited the C# class from by Chrome test fixture class (see below).


using NUnit.Framework; 
namespace GeoMEM.NETandCF.Maths.Tests { 
   [TestFixture] 
   public class GMatrixTestWrapper : GMatrixTests { 
   }
}

The Chrome test fixture is declared as follows:


uses
  GeoMEM.NETandCF.Maths,
  Nunit.framework,
  NUnit.Framework.SyntaxHelpers;
  
type
  [TestFixture]
  GMatrixTests = public class( AssertionHelper )
  ...
  public
  ... Lots of tests ....
  end;

I built the new test wrapper project and then ran the tests via the gutter icon. Sure enough, all my Chrome tests duly appeared in ReSharpers unit test browser (and passed, of course). I can even run tests individually and debug them via the test browser. The only thing I don't get is the ability to run tests straight from the editor, but I can live without that. The other thing that I’ve noticed is that if make changes to either your test code or the code under test you have to make sure that you compile the code via C# test wrapper project. Otherwise the wrapper project doesn’t get recompiled and you end up running “stale” tests.

So, to summarise; if you practice TDD and work in a language other than C# or VB.NET then chances are you can use an in-IDE unit test runner if you create a C# project and derive a C# test fixture from each of other languages test fixtures. You will get virtually all the advantages of a in-IDE test runner with perhaps one or two minor niggles.

*JetBrains also do a freebie unit test runner called UnitRun, you can get from here: http://www.jetbrains.com/unitrun/ and what I’ve described here should also work with UnitRun too.

posted on Wednesday, September 12, 2007 5:25:15 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] Trackback
 Friday, June 08, 2007

I'll be giving a talk on Rail development using an Apple Mac this Wednesday (13th June 2007, 7-9pm) for eXtreme Tayside. We'll be in the Queen Mother building at Dundee University, more details can be found here.

And whilst we're on the subject of the Mac; I composed this posting using the blogging bundle that comes with TextMate. If you're interested then there is a tutorial screen-cast here (requires QuickTime). TextMate will feature predominately in my presentation.

See you on Wednesday.


posted on Friday, June 08, 2007 8:13:38 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
 Wednesday, March 14, 2007

Problem

You need to find the numeric code for a character (either ASCII or Unicode).

Solution

namespace Cookbook1_2;

interface

type
  ConsoleApp = class
  public
    class method Main;
  end;

implementation

class method ConsoleApp.Main;
begin
  var ch      : char    := 'A';
  var chAsInt : Integer := Integer(ch);
  Console.WriteLine( chAsInt );
end;

end.

The ASCII or Unicode value of character is obtained by casting the character to an Integer. Also note that I have forgo Chromes type inference and explicitly declared the type for each variable.

 

posted on Wednesday, March 14, 2007 8:58:53 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback

Problem

Quite a common task in programming is the need to find the ASCII value of a character. The code below demonstrates how to do this in D.

Solution

int main(char[][] args) {

    auto ch        = 'A';
    int  charAsInt = ch;
    printf( "%d", charAsInt );

    return 0;
}

In D, getting the ASCII value of a character a trivial task. Simply assign the character to an integer and D will “promote” the character to reveal its ASCII value.

Some other points to note about the above code are:

  • char values in D are UTF-8 by default; if you want UTF-16 or UTF-32 characters then use the wchar or dchar types respectively.
  • Also note the use of the auto keyword when I declared the character variable, ch. The auto keyword gives you access to D implicit type inference features.
Tags: ,
posted on Wednesday, March 14, 2007 8:02:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
 Monday, March 05, 2007

Problem

You want to break up a string into its individual tokens or words

Solution

I’ll present the solution in two forms; the first will use “traditional” Object Pascal idiom, the second will make the most of Chrome’s features where appropriate. Both solutions will use the FCL’s string.Split() method.

Object Pascal Version

namespace Cookbook1_1a;

interface

type
  ConsoleApp = class
  public
    class method Main;
  end;

implementation

class method ConsoleApp.Main;
const
  Space : char = ' ';
var
  userRec    : String;
  attributes : array of String;
begin
  userRec    := '01 Barry Carr 17/04/1964
barry@notarealdomain.com';
  attributes := userRec.Split( Space );
 
  for each token : String in attributes do
      Console.WriteLine( token );
end;

end.

Chrome Version

namespace Cookbook1_1b;

interface

type
  ConsoleApp = class
  public
    class method Main;
  end;

implementation

class method ConsoleApp.Main;
const
  Space : char = ' ';
begin
  var userRec    := '01 Barry Carr 17/04/1964
barry@notarealdomain.com';
  var attributes := userRec.Split( Space );
 
  for each token in attributes do
      Console.WriteLine( token );
end;

end.

Notice how the Chrome version doesn’t have any type declarations, Chrome’s type inference is doing all the work of figuring out what the types are at compile time. One other point to note is that Chrome allows the developer to declare their variables in-line, where they are needed and does not require all local variable to be declared at the top of the method, procedure or function as classic object pascal compilers do.

Finally, the loop at the bottom is there so that I can see that the string has been split as I’d expect. A unit test would be better, however.

posted on Monday, March 05, 2007 8:50:25 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback

The sample was compiled using the latest version of D, 1.007 at the time of writing. You can get the latest version of the D compiler here.

Problem

You want to break up a string into its individual tokens or words 

Solution

Use the split() function from std.string, like so:

import std.stdio;
import std.string;

void main(char[][] args)  {
     char[]   record     = "01 Barry Carr 17/04/1964 barry@notarealdomain.com";
     char[][] attributes = split(record);

     foreach( char[] attribute; attributes )
        writefln( attribute );
 }

There is on overloaded version of split() that allows you specify what characters are to be used as delimiters.

The foreach statement at the end of the code above is there so that the tokens can be displayed on the console.

Tags: ,
posted on Monday, March 05, 2007 7:02:39 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
 Sunday, March 04, 2007

Taking a leaf out of Gary Short’s (cook)book and blatantly stealing his idea, I’m going to follow his example and start some programming cookbooks of my own. Like Gary, my cookbooks will be based upon the items featured in the Python Cookbook. Gary is currently doing a cookbook for Smalltalk, one of my favourite programming languages, so I’ll do cookbooks for D, Chrome and possibly F# and OCaml. I’m interested in learning all of these languages so undertaking these cookbooks should help me to gain a wider understanding of them and also enable me to share my experiences with a wider audience.

The Languages

D is the creation of Walter Bright, the man that developed the worlds first C++ compiler (before Walter, all C++ “compilers” were C preprocessors). D’s aim is to overcome some of the short-coming of C++. D offers virtually all the features you’d expect from a modern language, including: Templates (generics), Delegates, Interfaces, Mixins, (optional) Garbage Collection, Type Inference, Design by Contract, Tail Recursion and much, much more. The D compiler is free to down load and use and is available for Win32 and Linux.

Chrome is an Object Pascal implementation targeted at the .NET and Mono platforms. It’s being developed by RemObjects. Chrome offers all the features of C# 2.0 as well as Design by Contract, Type Inference and Virtual Constructors. It also improves on “classic” Object Pascal implementations by improving the with statement and by adding the ability to declare variables in-line, like the C family of languages. Chrome is a commercial product but RemObjects do provide a free, command line compiler.

OCaml is an Object-oriented functional/imperative language hybrid developed and maintained by INRIA, France's national research institute for computer science. OCaml can be interpreted or compiled very efficiently into native code. Like all the languages mentioned so far, OCaml supports Type Inference, Garbage Collection and Generics. Also, as you would expect from a functional language, OCaml supports: Tail Recursion, Pattern-matching and Currying.

F# is an experimental functional language developed by Microsoft and, as you’d expect, F# is targeted at the .NET platform. F# is based on OCaml.

Tags: , , ,
posted on Sunday, March 04, 2007 8:06:44 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback

Procupine Tree - In Absentia, album cover"In Absentia" is Porcupine Tree's (PT) 12th album, it was released in Sept 2002. I only discovered PT about 12 months ago and I’ve snapping up all of their albums ever since.

PT are a British Progressive Rock band that formed in the ‘90s and it is the brain child of Steve Wilson. It’s said that PT are one of the principle bands that kept Prog-Rock alive in the UK.

I know Prog-Rock is a dirty word to a lot of people, but I can assure you that there are no 20 minute drum solos on this album, just excellent tracks with good lyrics played by talented musicians.  A lot of the tracks are quite dark, not as dark as, for instance, Nine Inch Nails, but certainly not the usual “boy meets girl” type of stuff. If you’re not into darker themes then PT probably isn’t for you, however, you’ll never know unless you give them a spin. I’d recommend this ablum or their latest album, Deadwing. There are some MP3 samples of Deadwing at PT’s website.

You can find out more about the band at http://www.porcupinetree.com. Or, you can have a look at their Wikipedia entry here: http://en.wikipedia.org/wiki/Porcupine_Tree. For the album lyrics of “In Absentia” go here: http://www.porcupinetree.com/discography.details.cfm?albumid=12.

Enjoy.

posted on Sunday, March 04, 2007 7:14:16 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
 Saturday, March 03, 2007

It seems that the WordPress team have been having problems, again: http://wordpress.org/development/2007/03/upgrade-212/

posted on Saturday, March 03, 2007 12:19:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
 Thursday, February 22, 2007

I can't believe that the people that brought us Delphi, JBuilder and C++Builder have gone and done this: http://www.codegear.com/Products/Delphi/DelphiforPHP/tabid/237/Default.aspx

A PHP IDE!

It's no wonder that Delphi and the BDS is lagging behind the likes of Chrome and Visual Studio when they are frittering their time away on nonsense like this. Why didn't they expend their effort on something up-and-coming like Rails and not on a spent force like PHP?  A decent Rails IDE would have flown off the shelves.

It seems that my evil plan to eradicate PHP has taken a step back - curses

posted on Thursday, February 22, 2007 4:25:04 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
 Tuesday, February 20, 2007

You may have noticed that this blog has changed. For a start, it looks different and there are no postings on it. Thats because I've has some problems with WordPress, my original blogging system, and was forced to get rid of it. A pain, but there you go.

I used this imposed change as an excuse to find a non-PHP based system. As a developer, I really don't like PHP, I think its a fetid heap of parrot droppings - not so much as a considered reaction, more of a viseral dislike. 

Ideally, I would have liked to have found a Rails based solution, but sadly, my host doesn't yet support Rails hosting. So, being as I develop it .NET most of the time and as ASP.NET is supported by my provider, I thought I'd hunt out an ASP.NET based system blogging instead. And here it is, dasBlog, an open-source ASP.NET blogging system.

Admittedly, its not quite as easy to set up as WordPress, you may need to get your hosting provider to set some permission for you, and you may also need to make some changes to your sites web.config file, but once thats been done then you're good to go. So far, dasBlog seems to be OK, time will tell.

As there now seems to be a whole new generation of more grown-up web development systems appearing on the scene we should hopefully start to see a sharp decline in the use of PHP. And not a moment too soon in my view.  Bias aside, PHP is an insecure, sloppy and inconsistent language that just encourages laziness (OK, that was biased). Hopefully, the newer, more rational, better designed and enlightened frameworks like: Ruby on Rails; Django; TurboGears; Grails and even ASP.NET will give PHP the kicking it so well and truly deserves and punt into computing obscurity.

I hope I have contributed in a very small way to the demise of PHP by drawing my own, faint, line in the sand. Remember people: PHP, together we can fight it.

posted on Tuesday, February 20, 2007 3:03:20 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback