Monthly Archives: April 2012

Back to basics – object equality

What do you think this piece of code will output?

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(GetValue() == (object)true);
            Console.WriteLine(object.Equals(GetValue(), true));
        }

        static object GetValue()
        {
            return true;
        }
    }

I won’t be like others and ask you not to run the code. Run the code if you feel like it. I’ll wait here.

Back already? Surprised?
I surely have been.. I’ve found a piece of code similar to this as I was cleaning up code in our repository. You have a method that is required to return object (as in System.Object) and you want to check if, unboxed, it holds the value of true (or not).

Why exactly does

    GetValue() == (object)true

return false considering that GetValue() returns always a true value? Well… because you are comparing two instances of a System.Object and the ‘==’ operator is coded in a way that uses the ReferenceEquals (and not Equals) method on System.Object.

The author could have unboxed it to a local variable and do the check after but the speed of coding is so much important for some of us.. Thank you ReSharper for pointing this to us and fixing a potentially subtle bug.

How not to build an online flight booking site

I had a rough experience a few days ago while trying to book a flight for my upcoming holiday. I … no, we, chose TAROM (site link here).

What happened, in short, I started to book the flight, filled-in all the flight details, got to the point where I need to provide the billing details (card number etc.), pressed next and then… “session expired, please start over again”. For a moment I checked my bank account. Sure enough they took the money and offered me just an error. No email, no nothing.

After 1 hour and something, I finally got to customer service representative who manually issued the tickets which couldn’t have been issued by the site. (Meanwhile I found out how hard is to cancel a payment from your bank to a rogue vendor).

In the end things got fixed but a bitter taste persists towards this TAROM operator. Anyway I tried to understand what went wrong in the process, IT-wise and this is what happened, I think :

  1. The site gathered all the flight details from the sucker customer (me)
  2. The site then asked for the billing info
  3. Tried to bill me and succeeded
  4. Tried to book the flight and failed (the session expired in the meanwhile)

From this short analysis a few WTFs have emerged :

  • Why did they chose to have an absolute-date expiration policy for the session? (i.e. the session expires precisely 10 minutes after you start the booking process, no matter how many or how frequent you do further requests
  • Why didn’t they leave the billing step as the final step?

Having had to put up with Romanian services for the last three decades I’ve learnt that the most probable reason for these WTFs is this :

Why? Because FUCK YOU! that's why..

Leaving the funny thing aside I suppose the ‘architects’ that built TAROM’s site (hope the plane doesn’t crash like the site) thought that it’s better to have the money in the bag and then see if all else went ok… or maybe they thought of a situation where many people would try to book few tickets? Or who knows…

What do you think dear reader?