James Crisp

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

Using floating point variables to represent money => not a good idea!

I was reading through some code the other day and was surprised to find that it was using doubles to represent dollar amounts. Reason for the alarm bells is that doubles and floats cannot accurately represent many decimal fractions (eg, 0.1), since doubles and floats internally work with powers of 2 rather than powers of 10. These inaccuracies are likely to lead to significant errors, especially when performing arithmetic (eg, adding up a table of dollar amounts). See this IBM article for a more in depth explanation and examples. The solution is to use types that work with powers of ten internally. In C#, you can use ‘decimal’ and in Java or Ruby, ‘BigDecimal‘, to avoid these problems.

Holiday 2007 – Provence & Cote D’Azure in the South of France

France supposedly is the number 1 tourist destination in the world, and certainly it is one of my personal favourites! Besides the pleasure of speaking French, we had the opportunity to eat a lot of good food, and visit really pretty coastal areas, medieval towns, castles and ancient Roman remains.

Our itinerary looked roughly like this:
Marseilles -> Aix En Provence -> Avignon -> Nimes -> Arles -> Tarascon -> (Italy) -> Nice -> Antibes -> (Monaco)

In terms of hotels, it was very much ‘get what you pay for’. We tended to stay in two star places around 40-50 euros per night. Our first hotel in Marseilles was only 37E per night, and it convinced us that the extra 10E or so was really worth it! Hotels were fairly easy to find (well sign posted), though often not too close to transport.

We tried the random approach to finding good restaurants to start with, but this led to a number of disappointments. The solution was to ask our hoteliers for their favourite restaurants – this led to some really great meals 🙂

We had planned to rent a car for some parts of the trip.. however, make sure you learn to drive a manual before attempting this! Autos in France are horribly expensive to rent, so we ended up doing everything by public transport – bit tricky in winter time especially, but we managed. Tourist offices were generally very helpful.








































































 

Holiday 2007 – South Korea

South Korea is a great place to visit. People tend to be very friendly, the alphabet is phonetic, food is good and everything is excitingly foreign! Don’t forget your phrase book though.. English is not widely spoken. This was my 3rd trip to Korea, and it was an opportunity to catch up with Soosun‘s relatives, improve my pitiful Korean and see some interesting areas.

Should you happen to go to Korea with a partner, I would recommend staying in ‘motels’. They are around 30,000-40,000 WON in most places per night, are conveniently located near transport and generally have nice rooms. Despite their reputation as love hotels, they are often more comfortable and cheaper than other alternatives. Don’t be surprised, however, if they don’t ask for your name, and require payment in cash!

Also, visiting the local jimjil-bung (sauna) is an experience not to miss. They are generally open 24h and provide showers, sauna rooms, hot and cold pools, massage and general sleeping and relaxing areas, as well as funny coloured clothes to wear while you are there 🙂

Some of the fun stuff I did this trip was catching up with friends and relatives, walking around fortresses, going to a hot spring spa, doing a little caving, taking in some amazing scenery and going skiing.
















 

Back from Holidays

Back to Sydney after a very enjoyable holiday! Soosun and I were away for a bit over a month, and spent time in South Korea, France (Provence, Cote D’Azure), Monaco and Italy (Venice and Padua). The next few posts are going to give a little taste of these places 🙂

My Sister’s Indian (Red) Wedding

Yesterday was Mia’s second wedding. This one was a Hindu, Fiji-Indian, red wedding and quite different to the first, although it had some similarities in terms of having vows and speeches (and yes, the same husband!). The red wedding included a lot of reading by the Pundit (the Hindu minister) in Sanskrit, many prayers with rice and petals held in hands, and various things put in a mango-wood fire. There were also various prayers with coloured powders, stuff to put on the forehead, water, gee, milk and bananas in front of statuettes. Male members of the bride and groom families wore turbans. Food was all vegetarian, but nice, and alcohol was forbidden. We danced a little at the end of the night. All in all, it was a lot of fun 🙂

As the brother of the bride, I had quite a lot to do in terms of prayers and ceremonies. On the Tuesday before, the Pundit visited my place to bless a bundle of clothes and other things for Neeraj (Mia’s husband) with water and a banana leaf. We then went to the Neeraj residence where we did a ceremony for about an hour, with all the ingredients mentioned above. Before the wedding, I was also responsible for making some popped rice – similar to popcorn but made from rice in the husk. I needed to give this to Neeraj and Mia several times from a yellow cloth sling the Pundit wrapped around me during the wedding, as the couple walked around the fire 9 times. Also there were various points where I needed to pour water for foot washing and similar.

To give you more of an idea, here’s some pictures!

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!

Page 17 of 20

Powered by WordPress & Theme by Anders Norén