A must do

If you are a software developer, then you owe it to yourself to take a look at this screen cast

http://www.infoq.com/presentations/craftmanship-ethics

There are times in a persons life when a influence comes along with can turn them around, reading Clean Code, although I work primarily in c# and the book is all Java, this is one of those times, and Robert C Martin is one of those influences.  If you write software for a living, or are thinking of writing software, then do yourself a favour and watch the screen cast and read the book.

I don’t think I am quite ready for a green band quite yet, but I hope to be one day soon.

Posted in Software Ethics | Leave a comment

Kevin Hurwitz: Ready, Set, Panic!!!

 

Don’t ask how I found this little gem, I was browsing my feeds and followed a link, with a link etc, anyway you get the idea.   We have a few new developers where I am currently employed, and very good they are too, but having been there, I know the pain kevin is talking about, and his advice is great, and so simple, why didn’t I think of it!

Aiming for test coverage, and forcing yourself to break the code into smaller chunks is brilliant, now all I have to do is implement it!

 

Kevin Hurwitz: Ready, Set, Panic!!!

Posted in Uncategorized | Leave a comment

Test Deployment Items

 

I have been playing with the new Nhibernate bits, and working through the tutorial here, now he uses MbUnit, and NUnit which are great frameworks for testing, but I wanted to use the test framework supplied with visual studio.

The problem comes when the test is looking for the Hibernate configuration file, which the ms test framework cannot find, because the test runs in its own folder, and not in the debug bin folder as the other frameworks do, so we need to have a way of copying the file to this directory which could quite easily change!

Reading the MSDN help I discovered that the LocalTestRun.testrunconfig file has a deployment option, which can specify a file or directory, sadly the file can only be an executable or dll.  So I simply chose the debug bin directory of the project that contained the hibernate configuration file and ensured that the hibernate.cfg.xml file was set to copy if newer, or copy always.  and it all worked.

The only problem with this is that I am not only copying the hibernate file, but also ALL the dlls etc in the project bin folder, this makes the startup time for the tests slightly longer, but it does give me a chance to get a sip of tea before continuing with the refactoring 🙂

Posted in Programming | Leave a comment

Separation of Concerns

 

This looks like a good series to follow, I am going to be interested in how each of the dependencies is broken out and split out, its great to see an example that solves a problem with out tests, as a lot of us have to work with legacy code, and this is a fine example of dealing with a static method.

http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/06/19/separation-of-concerns-by-example-part-1.aspx

Have Fun

Posted in Programming | Leave a comment

Event Hookup Part Two

So what did I learn, that by creating a class that inherits EventArgs i can pass any information I need in an event, I did write a quick presenter and its test to ensure that the ITask interface worked as I expected, i.e. in exactly the same way as any other EventHandler interface definition that I have done.

The presenter Tests

   1: using Microsoft.VisualStudio.TestTools.UnitTesting;
   2: using Rhino.Mocks;
   3:  
   4: namespace ExamplePresenter.Tests
   5: {
   6:     [TestClass]
   7:     public class PresenterTests
   8:     {
   9:         private static MockRepository _mockery;
  10:         private ITask _mockTask;
  11:         private IView _mockView;
  12:         public TestContext TestContext { get; set; }
  13:  
  14:         [TestInitialize]
  15:         public void TestInitialize()
  16:         {
  17:             _mockery = new MockRepository();
  18:  
  19:             _mockView = _mockery.StrictMock<IView>();
  20:             _mockTask = _mockery.StrictMock<ITask>();
  21:         }
  22:  
  23:         [TestMethod]
  24:         public void Should_Hook_Up_Events_On_Creation()
  25:         {
  26:             using (_mockery.Record())
  27:             {
  28:                 _mockView.ButtonPressed += null;
  29:                 LastCall.IgnoreArguments();
  30:  
  31:                 _mockTask.ProgressMessage += null;
  32:                 LastCall.IgnoreArguments();
  33:             }
  34:  
  35:             using (_mockery.Playback())
  36:                 CreateSUT();
  37:         }
  38:  
  39:         private Presenter CreateSUT()
  40:         {
  41:             return new Presenter(_mockView, _mockTask);
  42:         }
  43:     }
  44: }

and the presenter code, all fairly standard

   1: using System;
   2:  
   3: namespace ExamplePresenter
   4: {
   5:     public class Presenter
   6:     {
   7:         private readonly ITask _task;
   8:         private readonly IView _view;
   9:  
  10:         public Presenter(IView view, ITask task)
  11:         {
  12:             _view = view;
  13:             _task = task;
  14:  
  15:             HookupEvents();
  16:         }
  17:  
  18:         private void HookupEvents()
  19:         {
  20:             _view.ButtonPressed += ButtonPressedEvent;
  21:             _task.ProgressMessage += ProgressMessageEvent;
  22:         }
  23:  
  24:         private void ButtonPressedEvent(object sender, EventArgs e)
  25:         {
  26:             throw new NotImplementedException();
  27:         }
  28:  
  29:         private void ProgressMessageEvent(object sender, MessageEventArgs args)
  30:         {
  31:             throw new NotImplementedException();
  32:         }
  33:     }
  34: }
  35:  
  36: using System;
  37:  
  38: namespace ExamplePresenter
  39: {
  40:     public interface IView
  41:     {
  42:         event EventHandler ButtonPressed;
  43:     }
  44: }

So why have I put all this here, just so I remember 🙂

Have Fun.

Posted in Programming | Leave a comment

Event Hookup Part One

 

Ever had one of those problems where you are coding outside your normal zone, but you know the answer is simple, and can’t get the syntax right on the day?

Friday was one of those days, here is the outline of my problem, I am refractoring one of my customer tests, its a windows form, and instead of having all the code within the form itself, I am moving it to a MVP layout, not a problem overall you may think, currently it has a bunch of controls, a couple of results text box’s and a process button.

So I created the view, and started creating the presenter, now the current form uses a background worker, so i wanted to move that to the tasks layer, where the actual work would be called, the presenter being responsible for pushing messages back to the view, and receiving the data and passing it on in the correct format to the task layer.

It was all going well, that tests pass until i got to the task layer, I create a background worker, an I want to hookup the progress and complete the events, now i don’t want the task interface to rely on the background worker, I may change it to a simple threading model so my ITask interface must have event, but this time I need to pass some data with the event and thats where i got suck, stupid i know but these things happen, so Sunday afternoon I decided to run up a quick spike to solve the interface event problem and see what the code will looklike.  here is my result.

first i wrote a simple task object that would implement an interface, I extracted the interface using ReSharper (one of those little used functions, but when you need it, its a real time saver)

   1: public interface ITask
   2:     {
   3:         event Task.MyEventHandler ProgressMessage;
   4:         bool LongRunningProcess();
   5:     }
   6:  
   7:     public class Task : ITask
   8:     {
   9:         public delegate void MyEventHandler(object sender, MessageEventArgs args);
  10:  
  11:         public event MyEventHandler ProgressMessage;
  12:  
  13:         public bool LongRunningProcess()
  14:         {
  15:             if (ProgressMessage != null)
  16:             {
  17:                 var args = new MessageEventArgs();
  18:                 args.Message = "hello world";
  19:                 args.MessageFlag = 1;
  20:  
  21:                 ProgressMessage.Invoke(this, args);
  22:             }
  23:             
  24:             return true;
  25:         }
  26:     }
  27:  
  28:     public class MessageEventArgs: EventArgs
  29:     {
  30:         public string Message { get; set; }
  31:         public int MessageFlag { get; set; }
  32:     }

I know its the wrong way around, but next I wrote some tests to play with the task to see if the message was passed up to my mock presenter as I wanted.

   1: using Microsoft.VisualStudio.TestTools.UnitTesting;
   2:  
   3: namespace ExamplePresenter.Tests
   4: {
   5:     [TestClass]
   6:     public class TaskTests
   7:     {
   8:         public TestContext TestContext { get; set; }
   9:  
  10:         [TestMethod]
  11:         public void Should_Raise_Event_During_Long_Running_Call()
  12:         {
  13:             mockPresenter process = CreateSUT();
  14:             process.Task.LongRunningProcess();
  15:  
  16:             Assert.IsTrue(process.ProgressEventRaised);
  17:             Assert.AreEqual("hello world", process.MessageReceived);
  18:             Assert.AreEqual(1, process.MessageFlag);
  19:         }
  20:  
  21:         private static mockPresenter CreateSUT()
  22:         {
  23:             var task = new Task();
  24:             var presenter = new mockPresenter(task);
  25:  
  26:             return presenter;
  27:         }
  28:     }
  29:  
  30:     public class mockPresenter
  31:     {
  32:         private readonly ITask _task;
  33:  
  34:         public mockPresenter(ITask task)
  35:         {
  36:             _task = task;
  37:  
  38:             _task.ProgressMessage += ProgressTaskMessage;
  39:         }
  40:  
  41:         public ITask Task
  42:         {
  43:             get { return _task; }
  44:         }
  45:  
  46:         public int MessageFlag { get; set; }
  47:  
  48:         public string MessageReceived { get; set; }
  49:  
  50:         public bool ProgressEventRaised { get; set; }
  51:  
  52:         private void ProgressTaskMessage(object sender, MessageEventArgs args)
  53:         {
  54:             MessageReceived = args.Message;
  55:             MessageFlag = args.MessageFlag;
  56:             ProgressEventRaised = true;
  57:         }
  58:     }
  59: }

Have Fun

Posted in Programming | Leave a comment

Why do home projects get so tricky

 

Well is been a while, but I thought I would just ask the question having stalled again on a home programming project, I wanted a simple program that would do some simple accounting, and after a MONTH I have got no further than a basic background domain that doesn’t really cut it.

Now at work where I program all day this sort of thing would have taken maybe a day to complete including the user interface  here at home I get sidetracked by the technology this time its WPF and how to data bind and design stuff, it looks great but its sucking my time away.

does anyone else suffer from this, other programmers I talk to say its the lack of a real customer, and that they get stuck with the same sorts of things, either games or an new "way" gets them.

So am I doomed to never actually write stuff that’s only for me?

Posted in Programming | Leave a comment

Humanized Enso

Enso the user interface launcher and spell checker, well actually it does a whole lot more than simply that, have a look, as its now been updated so its available at last on vista,

get it here

Humanized Enso

there is a fee trial for 30 days give it a try.

Posted in Computers and Internet | 1 Comment

Another one of those silly surveys

 

oh heck why can’t I resist them, give me a what type of xyz are you questionnaire and I am off, hopeless, well here is another one, this time "What sort of Programmer are you"

it turns out that I am a

DHTB

You’re a Doer.
You are very quick at getting tasks done. You believe the outcome is the most important part of a task and the faster you can reach that outcome the better. After all, time is money.
You like coding at a High level.
The world is made up of objects and components, you should create your programs in the same way.
You work best in a Team.
A good group is better than the sum of it’s parts. The only thing better than a genius programmer is a cohesive group of genius programmers.
You are a liBeral programmer.
Programming is a complex task and you should use white space and comments as freely as possible to help simplify the task. We’re not writing on paper anymore so we can take up as much room as we need.

now what was I doing?

Posted in Code | Leave a comment

Hooking an Event in Silverlight v1.0

Today I started to play around with silverlight 1.0, now I don’t usually code in anything like Java Script, but coding in c# meant it wasn’t too bigger leap, and the small bit of hacking I have done for websites put me in good stead, so I thought it couldn’t be too difficult.

I created a small animation in blend and wanted a button that changed the background color when the user clicked on it, a simple play application that would allow me to see what was involved in the coding.  All went well until I tried to hook up the click event, I added the attribute ‘MouseLeftButtonDown’ to the canvas element of my control setting its value to TestClickDown, and created a simple function within the java script which put up a dialog box, but I could just not get it to work, the function was never called, I googled the web, and looked at the silverlight help, but it talked about putting the two items that I had done, but nothing else, then I looked in the code supplied by blend as part of the project and saw this line

rootElement.addEventListener("MouseLeftButtonDown", Sys.Silverlight.createDelegate(this, this.handleMouseDown));

and the penny dropped, I hadn’t hooked up the event on the xaml to the function in the java script! Sounds simple but I had totally forgotten about it, and not being used to the script I was looking at hadn’t noticed the line, notice how this line hooks the root element, in Silverlight that is the controls canvas, (in my case just about the whole page!), not quite what I wanted, so I had to adjust the statement so it hooked only the canvas I wanted,

// set the event hookup for the specific canvas 
var canvas = this.control.content.findName("Click_TestBlock");
canvas.addEventListener("MouseLeftButtonDown", Sys.Silverlight.createDelegate(this, this.TestClickDown));
this searches the control for a canvers called Click_TestBlock, and then I set the event on that canvas, and as 
they say in the story books all was well.
I am off to do some data binding next to text blocks and see how that works, calling a web service from script
is a new experience for me, and should be interesting.
Posted in Silverlight | Leave a comment