Ayende @ Rahien

It's a girl

Book Reivew: Sanctuary

Product image for ASIN: 0756402468 Sanctuary by non else but Mercedes Lackey

The first thing to note about this book is that it's short, and it's not as packed with action as I hoped it would. The target audiance are young adults, and for them I think that the book would do very well. I found that I want it to be longer, and with bigger scope.

However, the book is entertaining, and there was more than one point in which I had to point it down to laugh it out*. The book ends much faster than I expected, and the ending was the usual good beating evil, but it was very nicely executed and overall a good read.

* There is a point where the hero says that dragons do not have magical ability to travel through time, a clear reference to Pern.


Published at

Databinding snafu

A few hours ago I thought that I was going crazy, I'd had a form that wouldn't save changes unless I closed it without saving first. I debugged it long and hard, and I couldn't find any reason whatsoever for this. Saving and then closing wouldn't work, but closing and saying yes to the unsaved message would.

The call stack from each was the same, and for the life of me I couldn't find what is wrong. I was ready to get NHibernate's code and start debugging that (I'm pleased to say that so far I didn't get to find any bugs in it :-) ). However, I turned on logging first and realized that NHibernate wasn't issuing an update statement at all. The only case where NHibernate doesn't execute an update statement when you tell it to is when you don't have any updates to your object.

That was the answer, I was using databinding in the form, and the field I was changing wouldn't update the datasource until it lost focus (which is reasonable, I guess), but it cause me no end of grief. When I moved the focus to another control, it worked.

Just goes to say that you really needs to know what you are doing before you do it*.

*This is my first serious attempt of using databinding.


Published at

Digital Camera Woe

I just discovered that my digital camera was set to taking pictures at the lowest resolution. Argh!

Took me a while to fix it, first time that I'd to actually do something beyond turn it on, point and click.

More Multi Threading

Well, I improved on my multi threading code, but I was still not satisfied about the way it work, it created threads unnececarily, so I decided to improve it. Again, I'm using Udi Dahan's ThreadSafeQueue for multi threading.

The idea is based on what Udi Dahan had to say on the comments for my post, and is actually very simple, the queue host intellegent commands, and the working thread simply has to pull them out of the queue and execute them, one at a time.

Here is the working thread implementation:

public class ThreadedCommandExecutioner
 ILog logger = LogManager.GetLogger(typeof (ThreadedCommandExecutioner));
 private readonly IQueue queue;
 bool runThread;
 public ThreadedCommandExecutioner(IQueue queue)
  this.queue = queue;
  runThread = true;
 public void Run()
  ICommand cmd;
   cmd = (ICommand)queue.Dequeue();
   if (logger.IsDebugEnabled) logger.Debug("Running command: "+cmd.Name+". Command Info: "+cmd.Info);
 public bool RunThread
  get { return runThread;}
  set { runThread = value; }

Now the only thing that I need to do when I want to run a job in the working thread is to add a command to the queue. [Currently I've BuildProjectCommand & ExecuteQueryCommand]

The nice thing about this is that I can expand this to more threads without having to do much beyond spun those threads (or better, just use ThreadPool).

Testing this is a little bit tricky, because I'm not really interested in starting threads in my tests, I managed to get around it by using the  DelegatingConstraintWithArgs I'm not sure that this is a good thing, though. Suggestions?

By the way, I really do need to start using NCover again, I've done an extensive modification, and I didn't get nearly enough breaking tests. (It's all because of the UI, I swear :-)).

Great Hackers

Apperantly I'm not one, I like Windows :-)

[Listening to: Great Hackers - Paul Graham - OSCON 2004(30:50)]

Replacing notepad with notepad2 On Windows XP Service Pack 2

I really like Notepad2, but the post about Replacing notepad with notepad2 wouldn't work on XP SP2, here is one that works, apperantly the only change is from %systemroot%\system32\dllcache to %systemroot%\ServicePackFiles\i386

@echo Replacing NOTEPAD.EXE with notepad2.EXE ...
REM 1. Prevent the protected file system from doing its thing.
attrib -r -h -s %systemroot%\system32\dllcache
del %systemroot%\system32\dllcache\notepad.bak.exe
ren %systemroot%\system32\dllcache\notepad.exe notepad.bak.exe
attrib +r +h +s %systemroot%\system32\dllcache
attrib -r -h -s %systemroot%\ServicePackFiles\i386
del %systemroot%\ServicePackFiles\i386\notepad.bak.exe
ren %systemroot%\ServicePackFiles\i386\notepad.exe notepad.bak.exe
attrib +r +h +s %systemroot%\ServicePackFiles\i386

REM 2. Make backup copies of Notepad in the Windows and System32 folders.
del %systemroot%\system32\notepad.bak.exe
copy %systemroot%\system32\notepad.exe %systemroot%\system32\notepad.bak.exe
copy %systemroot%\notepad.exe %systemroot%\notepad.bak.exe
REM 3. Copy notepad2 to Notepad in  the Windows and System32 folders.
del %systemroot%\notepad.exe
copy notepad2.exe %systemroot%\notepad.exe
copy notepad2.exe %systemroot%\system32\notepad.exe
@echo Succeeded.
@echo NOTE: When the Windows file protection message pops up,
@echo click Cancel, then click Yes to confirm your intentions.


Published at

My Library

Some of my friends call me a book worm, but I don't think the title do me justice.


I just couldn't get enough distance from the library to get all the books in one picture, even those three aren't all of it.

Book Reviews: Burning Brightly & To Light A Candle

Let me state it againMercedes Lackey is awesome. And by that I mean that she is a really good.

Product image for ASIN: 0886779898 Brightly Burning is another story in Mercedes Lackey's Valdemar books, the book is about Lavan Firestorm (an important figure in Valdemar's history) and his story. And his end, the book is (like all the other Mercedes Lackey's books I've read) captivating and hard to put down. Unlike the rest of her books, this does not have a happy ending. In fact, it's not a very happy book, from the start to the end, Lavan is in... unusual situations (tortured, in love with a talking horse*, losing friends, feared, misunderstood, forced to kill a lot of strangers,losing his Companion, dying). The ending seems to be the only way out of a very bad situation, I cannot help but think that if the hero would've been allows to grow up, there would have been... problems. Either with the hero, or with the people around him. As it is, the story makes for a great legend, is told in a really convincing way and made me wish so much that it would go some other way. I wouldn't recommend it unless you already read about Valdemar, as it's not very good introduction for . If you have read Valdemar's novels before, than it's a very good read.

Product image for ASIN: 0765302209 To Light A Candle is the second book in  The Obsidian Trilogy, following Product image for ASIN: 0765341417 The Outstretched Shadow. Those books talks about a world where most of the humans are walled in a single city, and magic is something of a science, and a boring one at that. From there the story gets complicated, and involves elves, Wildmagic, Knight-mages, demon and a really good story. The world is real and very consistent; magic is something that has limits and bounds, and is explained very well (at least as well as you can explain magic :-) ). The plot is interesting to watch, and the characters are excellent. Highly recommended.

Product image for ASIN: 0756402468 Sanctuary is the next one on my reading list, it's the first trilogy by Mercedes Lackey that I'm ending, so I'm really interested in how she would finish the book. So far the The Dragon Jousters books were very good, so I've high hopes, I'll blog about it when I'm done.

Some more interesting books can be found here, I really like Hienlien, and I put some of those on my reading list (which is already bigger than I can manage).

*Yes, that is not an accurate description, so sue me :-)


Published at

Automating Your Application

I just found this: Adding JScript.NET Macro Support to Your Application [via CraigBlog]

This is a very cool (and simple, and elegant) idea. What I like even more is taking this idea further, and using this to do the last layer glue for the application. Considerring the level of seperation that we usually have, we (hopefully) write an application by creating small parts that are independant of each other, and only at the end we bring them together, this allows to create an application that would be far easier for the user to modify.

For example, let's say that I would do that for NQA, here is how you would translate an HQL statement from an existing project [Uncompiled code]:

var dataMgr = AppDataManager.DefaultAppManager;
var myPrj = dataMgr.GetProjectByName("My NQA Project");
MessageBox.Show(myPrj.TranslateHql("from Customer cst where cst.PayementRecieved = true"));

I might get to that, if/when I'll get NQA to the state that I want it.


Published at

Test Performance: Resolution

I've one test class that takes over a minute to execute(!), that is unacceptable. Taking a look inside, I can see why this is so, it construct the database and creates an AppDomain on each and every test. Moving those to the TestFixtureSetup made it run in 1.6 seconds, which I consider far better.

The second offender took only 22 seconds to run, also for the same reason, moving to TestFixtureSetup can it down to 1.5, which is much better. The other main offender was 10 seconds (down to 0.67).

It took me 30 minutes, and I cut the time to run my test suite from over 140 seconds to 27 seconds, but that is still not enough.

One class is testing the AppDomain load/unload, so there isn't much that can be done about it, but I still managed to move it from 10 seconds to 5.

The next thing to tackle was 14.5 seconds spent on UI testing. I've commented before, databases and networking may be slow, but until you look at the timing for UI tests, you won't believe how slow the UI is.

Considerring my previous diffculities with testing the UI, I removed those tests all together, and removed the reference to MbUnitForms.

Total time to run the tests before "optimization"*: 140+ Secodns.
Total time to run the test after "optimization"*: 11.45 seconds.

Now I no longer have to look for something else to do while I'm running the tests. :-)

Mutli Threading Tests

Anyone can suggest a pattern to do that? I'm currently trying to test some of my multi threaded code, and I get into a whole lot of trouble.

The problem is that I'm trying to test that things happen in two threads at the same time, and I'm not sure I'm doing it properly. Per Udi's suggestion I changed my code to use notifications, rather than busy waiting.

Because of the need to syncronized between the threads, I created the following method:

public void ExecuteInUIThread(Delegate d, params object[] parameters)

The problem is how to test that the method called from the class I'm testing is the right one, I'm not so sure about how to do this properly. But before I get to the solution, here is the problem:

I've a class which is called from the UI thread to do work, it spun off a thread which does it works, and when done, it call the ExecuteInUIThread method with a delegate to an OnSuccess or OnFailure method. My problem is with the tests, how do I make sure that I get the correct response from the class. Take into account that I'm mocking the class which contains the ExecuteInUIThread method, and that is a complex issue.

I solved it this way, using a custom constraint in the mock object, which allows me to run my own test method when the mock is called, here is what I've, it's an extention of the idea I'd with DelegatingConstraint:

public class DelegatingConstraintWithArgs : BaseConstraint


            private readonly string message;

            private readonly int numberOfParams;

            private Delegate d;

            private int currentParam = 0;

            private object[] args;

            private bool delegateCalled = false;


            public DelegatingConstraintWithArgs(Delegate d, int numberOfParams, string message)


                  this.message = message;

                  this.d = d;

                  this.numberOfParams = numberOfParams;

                  this.args = new object[numberOfParams];




            public override bool Eval(object val)


                  args[currentParam] = val;

                  currentParam += 1;

                  if (currentParam == numberOfParams)


                      bool ret= (bool) d.DynamicInvoke(args);

                      delegateCalled = true;

                      return ret;


                  return true;



            public override string Message


                  get { return message; }



            public bool DelegateCalled


                  get { return delegateCalled; }



This class will gather the paramters of the method, and when it will reach the final number, will execute the delegate on them. This allows me to invoke the delegate that I get from the class under test*. I can execute it and then observe the effects.

On a more general level, this allows you to execute your own code from the mocked object, without writing much code. It's nice, but very much open to abuse, and more over, I'm not so sure that I'm not abusing it myself right now.

For instance, here is my current test, I setup quite a bit of expectations that it needs, and then run the tests, waiting until after the method is called. Verify()ing the mock is done on the TearDown() method.


public void ExecuteQuery_NoParameters()



      DelegatingConstraintWithArgs cs = new DelegatingConstraintWithArgs(new ExecuteInUIThreadDeleagate(ExecuteInUIThread),



      mockIQueryView.SetupResult("Parameters",new Hashtable());





            new And(new IsTypeOf(typeof(DataSet)),dataSetConstraint));


      mockIQueryView.Expect("EndWait", new IsTypeOf(typeof(string)));






* As a side note, I've here two or three layers of delegates, spooky.


Published at

TiddlyWiki Tiny Improvement

The single bad thing that I've found in TiddlyWiki is that it doesn't warns you about unsaved changes when you leave the page, with a potential to lose those changes.

Here is the fix* Change the:

  1. <body> tag to:
    <body onload="main()" onunload="askSaveChanges()">
  2. Add the following function to the <script type="text/javascript">
    function askSaveChanges()
    var save = confirm("Save wiki's changes?");

Now it will ask you at any unloading if you want to save. Pretty good solution in my book for this problem.

* This will ask for any unloading, whatever there are changes or not, so it's not ideal.

ethical Design Guidelines

“It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure.  Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter.”

 -- Nathaniel S. Borenstein


[Via The Agile Developer]


Published at

I love Amazon

I just got a bunch of books from Amazon.com, I ordered them at  May 12, 2005 and they arrived at my local post office on the  May 19, 2005 , what is so impressive about that is that this is an international order, which means that the books waited as much time in the post office before I could pick them up as it took to deliver them.

The estimate of Amazon says that they should be here from June 6 to June 15, but the reality is much faster, and that is in the slow shipping method.

I got another order that shipped on the May 19, I believe that it will be here in another day or two.

I mostly got Mercedes Lackey's Heralds books, and some computer books (actually, I didn't finish the books from the last order, so that goes on my to do list under the category, Just Do It).

Here are the computer books that I ordered:

Product image for ASIN: 0131177052 Working Effectively with Legacy Code

I don't get to work with legacy code (woopee) [yet], but I most defiantly would at some point or another. I also heard great review of this one.

Product image for ASIN: 078214361X Developer to Designer: GUI Design for the Busy Developer

I read the previous book and it was both fun and inspiring, I expect no less than this one, especially as I seem to be dealing with a lot of UI issues lately.

Product image for ASIN: 0321278658 Extreme Programming Explained : Embrace Change (2nd Edition)

I hope I don't need to explain this one :-D, it's a slim book, but I've great hopes for the contents.

Update: Sorry about the lousy formatting, I copy & pasted from Amazon, and it looked good when I posted it, apperantly some <td> managed to go through and ruin the post.


Published at

How to make decisions?

When you got two (or more options) and you can't decide, flip a coin, and see what the result.

Now, here comes the hard part: See how you feel about the result. If it's OK, go with it, if your disappointed, go with the other one.

Michael's Child

I just saw this, Michael's baby is in intensive care with burst intestine. I wish her happy, full and speedy recovery,

Some of what Michael is telling is hard for me to understand, what is this about buying blood? It sound like a supermarket for vampires. I all the hospitals that I know, they have blood stored inside the hospital, and the patient's family certainly have nothing to do with that.


Published at

Graph Control

I forgot to say, the graph control on the previous post is my development of the Lithium control, I ripped most of the innards out and added the ability to host controls in the control, that was the first interesting UI work I'd done. Verra interesting.*

I'll release my modifications to Lithium with the next NHibernate Query Analyzer, but if you really wants them, you can get them from the subversion server, they are already there: svn://svn.berlios.de/nqa

Or, if you want to browse the source, just go to: http://svn.berlios.de/viewcvs/nqa/Vendor/Src/Lithium/

P.S: Tell me if you like this.

* I'm reading a book about Scotland now :-)

New Version Of NHibernate Query Analyzer

I'm getting close to the old functionality (only much better, of course ;-) ), I have the projects and queries working, now I need to add the documents editing (which is ready on the background, only need UI).

I've just checked in a bunch of changes that allows to run queries (and get an object graph from the NHibernate).

Just to whet your appetite, here is a screen shot: