James Crisp

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

JRuby Setup

Recently got a JRuby/Rails system with Java integration up and running. Unfortunately, it took quite a few hours, as most of the docs and code you find through Google are out of date.

If you use JRuby 0.9.2 from Codehaus, you will get an error similar to this when you try to access a rails application:

[2007-02-26 17:54:59] INFO WEBrick::HTTPServer start: pid=22540508 port=3000
<ArgumentError: Anonymous modules have no name to be referenced by>
[“c:/jruby-0.9.2/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/
active_support/dependencies.rb:402:in `to_constant_name’…

If you’re stuck in this rut, fear not! Nick Sieger has written very helpful instructions which outline how to get and set up the latest development snapshot. Please note that in addition to the instructions, you need to set your JRUBY_HOME environment variable. Under Windows, do something like this:

set JRUBY_HOME=c:\jruby

If you’d prefer not to use the snapshot, you can get the source code through subversion from:

http://svn.codehaus.org/jruby/trunk/jruby

but at the time of this post, you need to run svn checkout or update with “–ignore-externals” to avoid the following error:

Error: URL ‘svn://rubyforge.org/var/svn/bfts/bfts/trunk’ doesn’t exist

Many thanks to Nick Sieger and the JRuby user mailing list for their help.

Holiday 2007 – Venice and Padua

It was a sudden decision to take a sleeper train to Venice. We didn’t really know what to expect. By chance, we arrived at Carnivale (mask and costume festival), probably the busiest time of the year. Venice was filled to the rafters with tourists, prices were high and it was difficult to walk in many areas due to the number of people in the narrow streets! The solution was to take to the water – catching the ferry was fun and it got you out of the crowds.

Venice is really beautiful. The Doges (ruler’s) palace and nearby Cathedral in St Marco square are amazing. The palace has huge painted ceiling murals by famous artists and enormous open halls. In the Cathedral, there are golden mosaics over the whole ceiling, and even the floor is an artwork in tiles. There’s also some impressive golden relics from when the Venetians sacked Constantinople during the crusades.

In Venice, most streets lead to the water, and the best facades are turned towards the canals. It really is a city designed to be traversed on the water. The buildings are mainly standing on foundations made from hundreds of pine trees hammered into the silty mud under Venice. Historically, Venice’s influence peaked in the 13th century or so, and from then on, it was a slow decline in power. But to make up for this, the wealthy families spent lavishly on buildings, clothes and decorations.

On our last day in Italy, we went to Padua to take a look at a more typical Italian city. It was a friendly and fun place with few tourists, but good food and a nice atmosphere. Last picture is of Padua, all the rest are from Venice!














 

Holiday 2007 – Monaco

Monaco is easily accessible from Nice – about 1/2h by train. We spent an enjoyable afternoon and evening there, visiting the cactus “exotic” garden, castle, casino and cave. The cave was particularly interesting – it was about 18degC inside (despite winter temperatures outside), and walkways for visitors had been made using explosives and diamond drills! Despite the damage, it was still a lovely cave. Monaco was clean and tidy, and felt almost like a movie set.





 

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.

Page 17 of 21

Powered by WordPress & Theme by Anders Norén