June 2008 - Posts

Silly Design Decision?

Silly-TL-placement

Just a bit of disclaimer up front... This is purely based from my point of view / observation and I don't claim to have any prior knowledge or understanding on why this thing is designed this way, so I might be completely wrong.  If so, please let me know.

Every morning, I usually pass by this particular street crossing (Panglima Polim and Panglima Polim 9 from Barito to go toward Darmawangsa) to get to work (See attached map below).

And usually if I am lucky, the traffic light at Panglima Polim will be green by the time I arrived at the intersection, but this is not the case most of the time.

Having nothing better to do I started looking around and let my mind wonder about.  One thing keeps coming up in my mind as I looked around the area and it really bothers me a lot.

If you see the picture to the left, you can see the 2 traffic lights, one at Panglima Polim crossing and another one 1 street parallel to the first traffic light and the distance between the two is probably not more than 30 meters. 

 

As you can see, this can be quite a dilemma, especially if there are a lot of traffic coming from Barito that is going on toward Panglima Polim 9 and this is happening quite often.  What happen next, you can imagine for yourself.  The tail of the traffic going toward Panglima Polim 9 will block the perpendicular traffic of Panglima Polim since the two traffic lights are not even synchronized!  Meaning if the first traffic light is green the one after that is actually red!  So you moved a little across Panglima Polim and stopped right away for the next traffic light.

 

 

 

Cybermap: Panglima Polim

Map image from Cybermap.

I wonder why the need for the second traffic light at all.  I believe it does more harm than good.  I am also wondering what kind of analysis had been done before putting the second traffic lights in place.  I am wondering what kind of process was used to decide to put this silly traffic lights configuration.  Last but not least, what can you do to remove it or at least turn it off completely (the second traffic light).

 

One agitated Jakarta road user.

Share this post: | | | |
Posted by Jimmy Chandra | 1 comment(s)
Filed under: , ,

Of Usability and User Experience

gaugeThere are a couple of things that I like about this picture.  Well, not actually the picture, but the car itself.  This is the dashboard of my Nissan Grand Livina.  I am not sure if any other cars have similar dashboard or not, but I think this one is pretty usable.  And from using the car, the usability factor can be found not just on this dashboard but also on some other components of the car.

So, you might ask yourself, "What is so special about this design?  It sort of look like any other car dashboard to me.  There is really nothing special about it."  Instead of pointing out what's different between this dashboard and dashboard of some other car, I'll just talk about what I like about it.

This particular car is using automatic transmission.  In that I can put the gear into Park, Reverse, Neutral, Drive, 1 and 2.  What I like about this car is I don't have to look down at my gear stick to figure out what position I am in right now.  I can just glance on the dashboard and know right away that I am currently in Neutral (see the boxed N indicator on the lower right).

Sometimes when you try to fill up your gas, you have to make a guess where the heck is the silly tank?  Is it on the left side of the car or is it on the right side (especially if you are new to the car)?  And I believe this is not just on this particular car model, a lot of new car models have similar tank position indicator. See the tank indicator to the lower right of the fuel gauge?  It has a small triangle next to the gas pump icon?  It tells me that my tank is on the right side of the car.  Brilliant Smile.  And yes, I need to fill up my tank soon Sad.

Another thing that is not in this picture, sometimes when stopping at traffic lights, I like to put the car to neutral and pull on the hand brake and when the turned green, I forgot that I put the brake on and started to drive (or sometimes the brake didn't get fully released).  Can you guess what the car do?  It beeps to tell me something is wrong!! Smile.  A quick glance at the dashboard afterward showed me that the break indicator is still on (It's not in this particular picture) and I can rectify the problem.

Another thing that I like about the car is that the steering wheel is adjustable.  You can put it in a higher / lower position depending on your preference.  For me, this is great since I need the extra leg room.

So, why am I talking about car when it has really nothing to do with software development?  I believe we can learn from the team that design this car.  They really put a lot of thought on how to make the life of the "user (driver)" easier.  Thus making using "the product (car)" to be a little more comfortable and safer.  The user (driver) doesn't have to think so much about the "user interface".  There are less "noise" (not in the literal sense) to deal with.

I believe we should design software with similar mindset.  I know that making thing more usable won't be easy for us (developer), but it is a reward in itself when the user find your software very usable and is having great experience using it.

As they said, "making thing simple is not simple at all".   Making software is easy, but making good usable software is hard. So start thinking hard about this stuffs and have fun doing it.

Share this post: | | | |
Posted by Jimmy Chandra | with no comments
Filed under:

Back to Basic: C# Using statement, Return and IDisposable

In day to day coding, I found myself using a lot of disposable objects like DbConnection, Font, etc. And so, naturally, putting this code block inside a using statement is common sense. 

In theory, I know that when you use a using block in your code, your code is guaranteed to be disposed without having to do it manually. 

emoticon

 

But sometimes I doubt myself with question like "if I return something inside the using block, will my object be disposed properly?"

 

To alleviate my doubt I decided to do a little experiment.  The code is as follow:

 

   1:  using System;
   2:   
   3:  namespace ConsoleApplication1
   4:  {
   5:      class Program
   6:      {
   7:          static void Main(string[] args)
   8:          {
   9:              Console.WriteLine(GetBar());
  10:              Console.ReadKey();
  11:          }
  12:   
  13:          static string GetBar()
  14:          {
  15:              using (Foo foo = new Foo())
  16:              {
  17:                  Console.WriteLine("In Using...");
  18:                  return foo.Bar();
  19:              }
  20:          }
  21:      }
  22:   
  23:      class Foo : IDisposable
  24:      {
  25:          private bool disposed = false;
  26:   
  27:          public void Dispose()
  28:          {
  29:              Dispose(true);
  30:              GC.SuppressFinalize(this);
  31:          }
  32:   
  33:          protected virtual void Dispose(bool disposing)
  34:          {
  35:              if (!disposed)
  36:              {
  37:                  if (disposing)
  38:                  {
  39:                      Console.WriteLine("Disposing");
  40:                  }
  41:                  disposed = true;
  42:              }
  43:          }
  44:   
  45:          public string Bar()
  46:          {
  47:              return "Hello, World!";
  48:          }
  49:      }
  50:  }

 

As you can see, line 9 is calling the GetBar method (line 13-20) which has a using block and inside the block I return something from my sample disposable object Foo (Line 23-49).

I also added some tracing line in the example (Line 9, 17, and 39).  To see if the assumption is correct.

After running the code the console displayed the following:

In Using...
Disposing
Hello, World!

 

emoticon

 

Well, I guess that proved the assumption.  I can be sure that my code will work as intended now.  Happy, Happy, Joy, Joy!

 

If you are curious about Dispose pattern, there is an Implementing IDisposable and the Dispose Pattern Properly article in Code Project by Scott Dorman that you should read.  It gives a much deeper insight on this stuff.

Apparently, the compiler will translate the using block (line 15-19) to something like:

   1:  Foo foo = new Foo();
   2:   
   3:  try
   4:  {
   5:      return foo.Bar();
   6:  }
   7:  finally
   8:  {
   9:      if (foo != null)
  10:     {
  11:         IDisposable disposable = foo;
  12:         disposable.Dispose();
  13:     }
  14:  }

 

emoticon

 

Hmm... so... if I have a try finally block and I return something from inside the try block....  Nevermind...  We already know that finally will be called no matter what... or is it?

Share this post: | | | |
Posted by Jimmy Chandra | with no comments
Filed under: , , ,

Err... Unity - Better "Documentation"

Last week I sort of rant on how bland the documentation for Unity, the Dependency Injection Framework from the Enterprise Library.   Well, I still think they are a little bit hard to follow (compared to others).

My colleague, who is an EntLib afficionado, pointed me to some sceencasts by David Hayden on the subject which you can find on the PnP Guidance site.  Heeding the pointer, I decided to give the screencast a try.

Now I've visited PnP Guidance site a long time ago and did enjoy some of the webcasts that can be found there.  But it has been a long time since I visited the site and I forgot what a wonderful resource it was.

Long story short, David's screencasts on the subject really help me understand quickly what the capability and how to use the Unity framework.  If only the documentation can be written in this way...

emoticon

Kudos to David.  Great job on explaining this stuff in a simple and concise matter.

I'll be sure to visit PnPGuidance site and watch more screencasts from there.   Definitely more enjoyable than reading the docs.

Share this post: | | | |
Posted by Jimmy Chandra | with no comments
Filed under:

Update on Onionhead Windows Live Writer Plugin

Well, it's been a week or so since I posted about this little side project of mine.  It's still not fully done yet, but it's working, albeit not exactly the way I want it to work.

My original idea was to have a Windows Live Writer plugin where I can write a partial keyword in a textbox and based on the keyword (emotion like sad, crying, angry, screaming, etc.), the plug-in will give me a bunch of emoticons that match those keyword / emotion.  I can then click on the image that I want and it will insert the custom emoticon in the post.  Originally, I also wanted so the emoticon image will be uploaded to whatever blog service that is hosting the post.  Sort of like the Insert Picture... plugin for WLW.

Unfortunately, after doing some testing.  I am still unable to upload the custom emoticon image, so I decided on a different approach which is just to link it to an online repository of the said emoticons for now.  Later on, I'll work on this some more to see if I can get it to post to the blog service itself.

In the beginning I was only targetting the Onionhead emoticons, but after spending some time coding I decided to make it more generic so you could actually use any custom emoticons that you wish with this plugin, hence the name of the plugin now is Insert Custom Emoticon.  All you need to do to make it work with a different emoticon set is just edit the data.xml that comes with it and point it to the right places.

If you wish to try it out, I'm attaching all the files that you need and a rough instruction on what to do to install it manually.  I'm still working on an installer for this.

Here's some screenshots of the thing in action...

Insert Custom Emoticon in the action pane

wlw2 wlw3

Share this post: | | | |
Posted by Jimmy Chandra | 2 comment(s)
Filed under: ,

Back to Basic: Debug.Assert(...)

I wonder how many of us litter our code with this particular line?  How do you use them?  Do you know what you need to watch out when you do use them?  Is it necessary to put this line of code in our code? What is the consequence of putting this line into your code?  What's the right way to use Debug.Assert? Have you ever stop and think about all these stuffs?

If you are an old timer C/C++ coder, you'd probably have tons of this in your code, at least that's the place I've seen lots of them.  Frankly, I don't use them that much.  In fact, I'd go as far as saying it's not necessary anymore.  Of course I can say this since nowaday, hopefully, a lot of us are already moving toward unit testing, either using TDD (Test Driven Development) or after the fact.  So why litter our code with this line when you have a better way to assert the behaviour of our code.

Let's step back a bit, so, what does it do?  Well, it will throw an "exception" of sort when the line is executed and the assertion is not satisfied.  To be more precice, it will show a dialog box with the "exception" and some buttons that will allow you to Abort, Retry or Ignore the assertion. For example, you have the following code:

            const int FIVE = 5;
 
            int a = 2, b = 3;
 
            //All is fine and dandy
            Debug.Assert( (a + b) == FIVE);
            Console.WriteLine(string.Format("{0} + {1} = {2}", a, b, a + b));
 
            a = 3;
 
            //Uh oh!!
            Debug.Assert((a + b) == FIVE);
            Console.WriteLine(string.Format("{0} + {1} = {2}", a, b, a + b));

emoticon
When your code hit the second assert, it will go berserk and spit out the following dialog box:

assert

emoticon
As you can see, that's just not a pretty sight

 

 

If you do use them in your code, consider using the overloaded version that will also accept a string message instead the one parameter version.

//Bad
void Debug.Assert(bool condition)
//Better
void Debug.Assert(bool condition, string message)
//Best
void Debug.Assert(bool condition, string message, string detailMessage)

Why? Trust me, you wouldn't want to be bitten with not knowing what's going on when your application stop working if something fails the assertion, especially when the code that have this assert line is a server component.

See the following example:

    class Program
    {
        const int FIVE = 5;
 
        static void Main(string[] args)
        {
            int a = 2, b = 3;
            Foo(a, b);
 
            a = 3;
            Bar(a, b);
 
            Console.ReadLine();
        }
 
        static void Foo(int a, int b)
        {
            //Bad Assert, not enough info, might cause headache to maintain
            Debug.Assert((a + b) == FIVE);
            Console.WriteLine(string.Format("{0} + {1} = {2}", a, b, a + b));
        }
 
        static void Bar(int a, int b)
        {
            //Better Assert, it shows clearly which method is failing 
            //and description of the assertion that is failing
            Debug.Assert((a + b) == FIVE, 
                "Program.Bar(a,b): Assertion failed!\n" +
                "a + b should always equal to 5, but it's not!");
            Console.WriteLine(string.Format("{0} + {1} = {2}", a, b, a + b));
        }

 

A call to Foo method will fail misserably when a + b != 5.  But when you call Bar, eventhough it will still fail when the assertion is not met, it will fail more gracefully.  It will tell you what method is causing the problem and what the problem actually is.

assert2

emoticon

Yes, yes, I experienced this first hand last time when I had to change some rules on my server component and forgot to update the assertion somewhere in the downstream code. Took me a while to figure out why the heck my frontend application just sitting idly and not doing anything and it turned out the server component decided to pop up a dialog box when my new logic hits the the now falsy assertion.  And to make thing worse, the dialog box was an empty dialog box with no information whatsoever and a single OK button.  So I had to break out the debugger and started doing remote debugging session.  After finally stepping through the code I finally figured out that the Debug.Assert line was the culprit.  Not fun.  If I were to use the overloaded version at least I don't have to start debugging since the info would more than likely be sufficient to tell me that the specific assertion had failed.

Agree, disagree, comment?  Let me know...


Happy Asserting.

emoticon
Share this post: | | | |
Posted by Jimmy Chandra | 1 comment(s)
Filed under: , ,