C# – Another “finally” trivia

November 4, 2007 Leave a comment

If a function implementation has a try – catch block with a finally clause, then the finally code block is executed in all cases before exiting the function.

For example, in the following case:

int Foo()
{
     try
     {
          //do stuff here
          if(something_happened == true)
               return;
          //do something else
     }
     catch(Exception)
     {
     }
     finally
     {
          MessageBox.Show("exiting method")
     }
}

In the above function, even if the function exits at the first ‘if’ condition, the message will still be displayed.

Advertisements
Categories: Programming Tags: , ,

Home Theater Guide – 1

November 2, 2007 Leave a comment

Couple of months back when I started off to buy my home theater setup, I was awestruck with the number of options available. I was especially bothered about spending a chunk of $$ only to realize I missed something or if some better/ cheaper alternative was available to what I brought. So I did my digging…this post is a kind of Home theater 101 based on what I found from my self learning. Coincidentally this also started my audiophile hobby so most of the post will be biased towards that.

Components of a Home theater
Keeping aside the TV, the following are the components of any HT system:
1. Audio/ Video source – DVD or CD player
2. Receiver
3. Speaker setup

A good home theater system will take your movie watching experience to a whole new level. This could be either a life like dialog delivery or a 3D sound environment that makes you think you are part of the movie. The different components of a HT system work towards this:
1. DVD or CD player – read the disc and send the audio + video signals to the receiver
2. Receiver – receiver comes in between your DVD player and the TV/ Speaker systems. It receives the signals from the source (DVD player) and distributes the signals to various units. Eg. video goes to the TV, sound is distribued across the speakers.
3. Speakers – reproduce the sound sent by the receiver

In order to create a life like audio environment, the HT setup distributes sound in 360 deg around the viewer. This is accomplised by the placement of the speakers. In a 5.1 setup, there will be 5 speakers that are placed around the viewer thus giving a realistic experience.

A “5.1” setup means there are 5 speakers and 1 sub woofer. Other popular setups are a 2.1 – stereo setup or the new 7.1 hidef setup. In these, there are 2 and 7 main speakers accompanied by a subwoofer.

Types of Speakers
One can broadly classify them into the main speakers and the sub-woofer. Different types of sound (instrumental, vocal, birds, animals, vehicles, music etc) fall in different frequency range. The sub woofer is used to play the sounds in the low frequency range (< 100 Hz) and the main speakers play the frequencies above this. The actual value of this cut-off frequency changes from system to system and also based on user preferance. It is called the “cross-over” frequency. Based on your preference you can set the value of cross over as 80, 100 Hz etc .

 As discussed above 5.1 means that there are 5 main speakers and 1 sub woofer.

Of the 5 main speakers, each speaker serves a special purpose. The receiver actually splits the sound from the DVD and sends different parts the different speakers. The vocals (dialogues etc) go to the central channel. Then the sound is distributed over the rest of the speakers. This enables effects like sound fading when subject goes out of screen etc.

So how to choose a HT system?
Whether you buy a cheap 200-300$ setup or a 15000$ both are going to have the same components listed above. What makes difference is the quality of sound reproduction – the elite ones reproduce sound the closes to the natural source. This is because they are able to accurately reproduce sounds of different frequencies. So sound quality of the speakers is the number one criteria for selecting a HT setup.

The second criteria is your DVD/ CD player. This player should be able to support multiple formats (CD audio, Apple, Mp3, WMA). One important thing is that it should support the latest Video and Audio formats – HD DVD, Blue-ray, Super Audio CD (SACD). There is a huge variety of players from 50$ to 3000$ to choose from.

The third criteria is the receiever. First it should be able to support a 5.1 setup atleast. Then it should have the required ports – HDMI, S-Video, component etc. Again based on the quality there are receivers available from 200$ to 8000$ and more.

The fourth criteria should be ease of setup. High end speakers usually need special placement to deliver the best sound quality.

When selecting a HT system the first three criteria should dictate what setup you choose. The ease of setup need not really be a deciding factor. Of course you would start with a budget so that really might be the deciding factor on what you end up buying. But within a given budget, it is generally a good idea to spend 50-60% on the speakers and the rest on the player+receiver.

In the next post I will go through some famous brands/ setups available. 

Bitwise2007: Programming contest @ IIT Kharagpur

January 14, 2007 1 comment

IIT Kharagpur has declared the date for the Bitwise2007. It is on Feb 11th, 2007. More details can be found at http://www.bitwise.iitkgp.ernet.in/index.php?q=home.

Bitwise is an annual programming contest open to all (students and professionals) and has been running since 2001. Last year there were more than 2500 participants! this will be my second year. Lets see.

Categories: Uncategorized

For the movie buffs like me

December 9, 2006 Leave a comment

Movies to be released in December (and not to be missed)

1. Rocky Balboa (this is going to be huge. the trailers rock!)

2. SpiderMan 3

3. Pursuit of happiness

Sesh

Categories: Uncategorized

Model based testing

October 5, 2006 Leave a comment

What is the best way to test software?

Delivering quality code and keeping customers happy is the ultimate goal for any software development effort. Common problems people complain about software are that it does not do what they expect it to. Lot of times, particularly in R&D environments the specs are not clear and there are 2-3 iterations before the customers and developers agree that they have a working solution. While ambiguous specs do lead to some kind of re-work, in my personal experience developers do spend time fixing issues reported by the customer. Instead of adding new features, time is spent on fixing bugs in a previous release. If most of the bugs were to be found before the release, there is a good chance of project success as the customers get a stable ‘working’ build.

Software testing plays an important role in ensuring that the application released to customers does what it is supposed to do and without any errors. The definition for testing that I like most is “software testing is running the code in a controlled environment with the intent of finding errors”.  Automated testing has come a long way in ensuring that a software product is tested consistently through its various releases. Through automated testing it is possible to excercise so many scenarios that are impossible to be executed manually within a limtied time and with limited resources.

Helpful as it is, traditional automated testing suffers from the pesticide paradox. Just like how a pesticide can kill only a particular type of pests and how useless it becomes once those bugs have been killed, the throughput from automated testing drops drastically over time. Automated tests are still good for smoke tests and regression testing where you are interested to find if some core functionality is working or if old functionality remained unbroken.

However one of the bigger challenges for product release is to extensively test the software. All the functionalities have to be tested, all the code in the application has to be excercised with various inputs to ensure that the program behavior is verified in all its possible states.

This verification of program behavior in all its possible states is quite difficult with traditional testing techniques.

Here comes Model Based Testing.

In model based testing, a behavior model of the software is constructed that describes all the possible functionalities of the system and the manner in which the software system transitions from one state to another. A typical tool used to represent such behavior models are the finite state machines.

A typical model based testing framework consists of (or is developed as):

1. Create or define a model of the system under test. Examples of models are state transition table or the finite state machines.

2. A separate component then uses the model to generate test cases. From the state transition table or the FSM a directed graph can be built with the different states of the system as nodes and the transitions as the edges. Using graph traversal techniques it is possible to determine a sequence of input actions that leads the software to a particular state. The sequence of input actions form the test case and the final state is the excpected result.

3. As the software evolves, only the model needs to be updated with any new states and transitions. The test suite can then be updated automatically. Another advantage of this methodology is that the expected behavior (test oracle) is also built into the scheme.

An excellent and comprehensive reference to MBT is available at www.model-based-testing.org and www.geocities.com/harry_robinson_testing. This is maintained by Googler Harry Robinson.

In future posts, I will share examples of creating behavior models and also blog about creating a model based testing framework.

Categories: Programming Tags: ,

Project ideas

September 29, 2006 6 comments

1. super script engine for .net applications.

2. plugin that reads out the contents of gmail.

Categories: Uncategorized

XAML contest

September 21, 2006 Leave a comment

Michael Swanson has announced a XAML conversion contest. You need to write a tool that convert certain graphics formats to Microsoft’s XAML, the mark up language for GUI in vista. Details are available here and here.

Seshagiri

Categories: Uncategorized