James Crisp

Software dev, tech, mind hacks and the occasional personal bit

AntiPattern: BusinessObjects in the driving seat

When you have a rich domain model with a business object centric design, and a Windows forms GUI, it can be very tempting to start putting significant process logic in the business objects. After continuing along this path a little further, you may realise that the process needs some sort of user input, and you use events or some sort of notifier pattern to gain user input required by the process, while still maintaining layering in terms of referencing. Then additionally you may need to access some sort of external service.

Here is an example:

class Order : BusinessObject
{
  public void SendOrder(INotifier notifier)
  {
    if (ReadyForDelivery ||
        notifier.Confirm("Are you sure you want to send order lines? They are not ready for delivery."))
    {
      OrderLine[] orders = GetLinesToSend();
      foreach(OrderLine line in Lines)
      {
        SendLine(line); // send line using a web service?
      }

      Notify("Lines sent successfully.");
    }
  }
}

interface INotifier
{
  void Notify(string msg);
  bool Confirm(string msg);
  OrderLine[] GetLinesToSend();
}

I would like to suggest that this is an anti-pattern and a trap. Although there is no direct reference from the Business Layer to the GUI layer (INotifier is implemented in GUI and passed down), the Business Layer now requires the ability to stay instantiated, pause while waiting for responses from the notifier, and then continue execution. This will work for rich client applications, but not in a stateless web environment. The ideal of being able to swap in/out the GUI layers on top of the Business layer is now compromised.

Instead, it would be possible to drive form the GUI layer, and call a service to send the Order Lines. In pseudo code below:

void SendMenu_Click(...)
{
  if (Order.ReadyForDelivery ||
      MessageBox.Show(...) == DialogResult.Yes)
  {
    using (ChooseLineForm chooseLineForm = new ChooseLineForm(Order))
    {
      chooseLineForm.ShowDialog()
    }
    SendingSevice.SendLines(chooseLineForm.selectedLines);
    ...
  }
}

If the logic in the GUI layer became much more complex, it may be a good idea to pull it out into its own class (eg, LineSender). This class would be a type of GUI level controller, responsible for orchestrating the send process.

Using this approach, there are a number of benefits:

  • BusinessObjects have no reliance on GUI implementation, so can be used for Rich Client and Web Client indiscriminately.
  • Web developers are free to implement the user input process in stateless way more appropriate to their platform.
  • Functionality for sending Order lines (some sort of integration with a web service?) is pulled out into a service class which can be reused elsewhere (potentially sending other types of objects?) and unclutters the Order business object and removes its dependency on an external service.
  • Code is simpler and easier to follow.

In Defense of Simplicity AND Complexity

Simplicity and complexity seem to have become hot topics for some of my favourite technical bloggers of late. These fine people have taken the view that things should be either simple or complex. Right, seems logical, these are opposites. However, I would like to suggest that in a well designed appliance which addresses a complex process, it should have both a simple AND a complex interface.

A couple of years ago, I bought a LG “Fuzzy Logic” washing machine. It has lots of buttons and settings on the front and one big button that says something like “Start”. 97% of the time, I throw in my washing, some detergent and press the big start button, and the washing machine works out all the settings, displays them and then starts. In the 3% of the time when I want to do something different (eg, just a rinse), I use the more complex part of the interface to change the ‘cycle’ settings.

Recently, I bought an IXUS 65. It’s a lovely digital camera, and it provides both a complex and a simple interface. As soon as I put in the battery, I was able to take pretty nice pictures by just clicking the big button on the top. No problem, I was very happy. Over the next few days, I glanced through the manual and fiddled with more complex settings for ISO, colour etc. However, in 95% of shots, I simply want to click the one big button that takes a nice auto-everything picture. It’s only occasionally that I want to change the settings to achieve a particular effect or to override a mistake in the auto settings.

To conclude, I think that my talented fellow bloggers are all right. People like complex interfaces and simple interfaces, just at different times, for different tasks. The best gadgets and appliances offer both.

Pandora – Streaming music

I’d like to point my readers to Pandora, a streaming music service which lets you define multiple channels for the different types of music that you like. You start each channel with a seed, which is a song or artist that you like. The service chooses songs similar to this and you then mark them as thumbs up or thumbs down, thus refining the channel more towards your musical taste. It is Flash and browser based, no downloads necessary. Sign up is easy, and the service is free, though add supported. Highly recommended!

How to Win Friends and Influence People

“How to Win Friends and Influence People” by Dale Carnegie is a very interesting and practical book. Of the personal/professional development books that I have read, this one is probably the most valuable.

Carnegie summaries each chapter in one sentence as a “principle”. Here they are:

  • Don’t criticise, condemn or complain.
  • Give honest and sincere appreciation.
  • Arouse in the other person an eager want.
  • Become genuinely interested in other people.
  • Smile.
  • Remember that a person’s name is to that person the sweetest and most important sound in any language.
  • Be a good listener. Encourage others to talk about themselves.
  • Talk in terms of the other person’s interests.
  • Make the other person feel important – and do it sincerely.
  • The only way to get the best of an argument is to avoid it.
  • Show respect for the other person’s opinions. Never say, “You’re wrong.”.
  • If you are wrong, admit it quickly and emphatically.
  • Begin in a friendly way.
  • Get the other person saying “yes, yes” immediately.
  • Let the other person do a great deal of the talking.
  • Let the other person feel that the idea is his or hers.
  • Try honestly to see things from the other person’s point of view.
  • Be sympathetic with the other person’s ideas and desires.
  • Appeal to the nobler motives.
  • Dramatise your ideas.
  • Throw down a challenge.
  • Begin with praise and honest appreciation.
  • Call attention to people’s mistakes indirectly.
  • Talk about your own mistakes before criticising the other person.
  • Ask questions instead of giving direct orders.
  • Let the other person save face.
  • Praise the slightest improvement and praise every improvement. Be “hearty in your approbation and lavish in your praise.”
  • Give the other person a fine reputation to live up to.
  • Use encouragement. Make the fault seem easy to correct.
  • Make the other person happy about doing the thing you suggest.

Although these points give a bit of an idea what Cargnegie is advocating, I’d highly recommend reading the book. Each chapter is filled with stories – they are the valuable part as they provide examples of speeches, letters and conversations.

People have criticised the book as coldly manipulative. From reading the table of contents and the title of the book, I would be inclined to agree. Personally, from the content of chapters themselves, I find that a different story emerges. My reading is that Carnegie suggests that most people are fundamentally nice, and if they enjoy your company and you make them feel good they will reciprocate by looking out for your interests. Similarly, people will feel guilty if they are in the wrong, and will resolve their mistakes, as long as they are not angry from hurt pride or similar. Carnegie paints people as highly emotional beings, driven by pride and ego, but with huge untapped potential and happy to help others.

If I had to choose the 3 most important points from the book, I’d say:

  • People desire a sense of importance. Anyone will be pleased to have their opinion sought, talk about something of interest to them or have their achievements recognised and praised.
  • Use a light and indirect touch when trying to change people. Rather than criticising directly, explain a how you made a similar mistake in the past and the consequences, or give the person a good reputation to live up to.
  • When you make a mistake, don’t hide it or argue. Instead, admit it straight out and blame yourself in the strongest terms.

I borrowed the book from the library, but am planning to buy my very own copy. It is worth having on the bookshelf and re-reading.

Windows Crash: multiple_irp_complete_requests Stop: 0x00000044

Thought I’d do a bit of a defrag on my old Windows 2000 box. A few minutes in, I got a blue screen:

multiple_irp_complete_requests
stop: 0x00000044 (0x852CCE68, 0x00000D39, 0x00000000, 0x00000000)

Tried a chkdsk but got the same error, even when running it on boot in console mode.

After some web trawling, found this google answer, which suggested that the problem was caused by ‘Intel Application Accelerator’ conflicting with recent service packs.

After uninstalling the ‘Intel Application Accelerator’ my chkdsk finished successfully and defrag seems to be going fine.

Thank goodness for the internet and its wealth of technical solutions!

Bye Bye EDI… Hello ThoughtWorks

Well, after almost four years at EDI (now called CargoWise edi) I am leaving. I finish in the middle of January next year. It has been an interesting time, and I have learnt a lot working with very talented people and from building the framework for a big solution suite (around 4 million lines of C# code). I’ve also had the opportunity to experience the very different joys and pitfalls of product management.

I will be starting at ThoughtWorks (of NUnit, Jim Webber and Martin Fowler fame) in the middle of February in the new year. I’m expecting that there will be a lot of new exciting stuff to learn, and a lot of variety in terms of clients and technologies. ThoughtWorks are strongly XP, do a lot of development on client sites and even have some Rails projects. The people I have met from ThoughtWorks have all been very friendly and I look forward to starting there soon 🙂

Our Christmas Party ’06


Last Saturday, we had a Christmas party at our place. It went really well. Many thanks to Anh and Neeraj for doing such an excellent job with the BBQ.

Chark Jong – The Calm in the Eye of the Storm

Doing Chark Jong (breaking of the guard) today, my instructor pointed out that I was tensing up too much, and comitting myself to a big forward rush, when I should have been simply walking forward in my correct stance. After this and some more demonstation, I had an ephinany and things suddenly clicked. Here is my summary of how to do the technique more correctly:

  1. Put on a correct stance.
  2. Imagine yourself being sucked up towards the ceiling head first, or that your body is suspended from a thread going from the top of your head to the ceiling. This will straighten your back and neck and relax your spine.
  3. Mirror your oponent’s guard with your guard.
  4. Imagine your arms are very heavy, and relax all the muscles in your arms and shoulders. Your arms should be rotated up and forward by your shoulder ball joint, holding the ultimate angle, but otherwise completely relaxed. Your elbows should feel as though they are pointing towards the floor.
  5. Step forward naturally from your waist.
  6. As you close with your opponent’s guard (preferably a bit above it), allow your arms to drop down under their own weight, while focusing strongly on a point (eg, on the centre of your oponent’s chest). Don’t stop walking as your do this. The combined forward movement of your body and downward fall of your arms will mean that you collapse your oponents guard and hit through to their chest.
  7. Pull back both hands with a circular movement driven from your elbow, like in the form. This will catch the remains of your oponent’s guard and further disrupt their stance. If this move isn’t working for you, don’t overdo it – be careful not to come out of your stance.
  8. Finish by stepping foward from the waist (imagine your belly button is leading the way) and drive your arms forward in a double palm strike.

When it clicks, it feels like the calmness in the eye of a storm. You are relaxed, in control and uncomitted, with time respond to any counters your oponent may choose to do.

Thai Ordering and Development Mode vs Production Mode for Rails Apps

A while back, I wrote a little rails app for Thai food ordering at my work. My colleagues place orders using the system and then bring money to the nominated orderer of the week. Once all orders are in and paid for (this is also tracked in the app), the orderer rings up our favourite Thai restaurant (Laddas) and places the order.

I have the app running from fairly cheap shared hosting. At peak times during the ordering, I guess that they’d be 15 or so people simultaneously using the app. We’ve used it many times without problems. Thus, I was quite surprised and displeased (as were my colleagues), when my hosting account was suspended and we couldn’t see what had been ordered this morning. A hasty email to my hosting provider revealed that my account had been suspended due to high load and “ruby flooding”. They were kind enough to un-suspend my account and we completed the ordering process.

I remembered seeing something about production mode in ‘environment.rb‘. Some googling confirmed my hunch – in development mode, rails apps are much more resource intensive. Caching is not used, and every single file needs to be reloaded every time it is required. After changing my app to production mode, it seemed to run noticeably faster. Michael and I ran ‘top’ and it looked like each request used less CPU.

So, should you be in a similar situation, this is how to change your app to production mode on fast-cgi Apache shared hosting:

  1. Confirm that ‘database.yml‘ in your app’sconfig‘ directory has a section for production mode, and that it has up to date database connection details.
  2. Edit ‘environment.rb‘ in your app’sconfig‘ directory.
  3. Add this line:
         ENV['RAILS_ENV'] ||= 'production'
  4. Run ‘ps -u [your_user_name]’ to find if you have any ‘dispatch.fgi‘ processes running.
  5. If so, kill all of them (they’ll restart and use your new config settings).
  6. Browse to your app, it should now run faster.

Neuro Linguistic Programming – Part 2

This is the second part of my post on NLP. Part 1 is available here.

Building Rapport
To build rapport, the book recommends that you pay careful attention to the person you are speaking with and match their physical posture, expressions, breathing, movements, voice and language patterns. Whole body listening is important – this means you are curious and focused on the person you are speaking with and your language is ‘you’ focused, rather than ‘I/me’ centered.

Perceptual Positions
Perceptual positions are a way of appreciating situations from different standpoints and gaining different perspectives. 1st position is when you are in your own body – this position is good for concentrating on what you want and being assertive. 2nd position is when you imagine yourself in somebody else’s shoes – good for trying to understand their perspective/actions. 3rd position is when you imagine yourself as a fly on the wall looking at the scene – good for detaching yourself emotionally and considering things logically.

Setting Anchors
Anchors are particular stimuli (eg, a touch, smell or taste) that automatically trigger a linked memory or emotion. Everyone has unconscious anchors – eg, smell of food makes you feel hungry and think of eating. However, you can set anchors for yourself which you can then call up at will to change your emotional state:

  1. Choose a state/feeling that you have experienced in your life that you want to be able to access whenever you choose.
  2. Choose an anchor – eg, touching index finger to thumb on your left hand.
  3. Recall the time when the feeling was it its strongest for you. Make sure you are seeing the memory out of your own eyes (1st position). Think about the time – what colours do you see, what do you hear, what do you feel etc.
  4. Just before your emotions peak, set the anchor and then remove it at the peak of your emotions.
  5. Shake yourself to break state, and then repeat the process several times.
  6. Test the anchor – think of something else and trigger the anchor. You should feel the emotions/state you associated with the anchor.

I had a little bit of a play with anchoring emotions. The technique seems to work at least to some extent for me. I intend to play around with it a bit more.

Page 18 of 21

Powered by WordPress & Theme by Anders Norén