Friday, January 19, 2007

TWI Roadies



I went on a biking (motorcycles) trip with a few colleagues from ThoughtWorks last weekend. We rode from Bangalore to Calicut and back (about 750 Kms in all). It was such an amazing experience --- good highways, lovely countryside and an great set of bikers to go along with. We took the following route..


Bangalore >> Mysore >> Gundlupet >> Sultan Bathery >> Kalpetta >> Lakkidi >> Calicut


We rode upto Lakkidi on the first day which is about 320 Kms from Bangalore. The roads are amazing till lakkidi -- first the Bangalore-Mysore highway. We were doing 100-110 Kmph on this highway. The road from Mysore to Gundlupet is also quite good. Then comes the ride through the Bandipur forest, which is simply superb. Lovely forests on both sides and very little traffic. This led us till Sultan Bathery where we entered the Kerala state border. The roads from Sultan Bathery to Lakkidi were well made narrow winding roads. It feels great to tilt your bike to such an extent on these winding roads; sometimes you almost feel you're gonna fall of the bike!!
We reached Lakkidi about 4pm and decided to stay there for the night. After dumping our bags in the rooms, we headed out on a small trail up the tea estate, which was quite scenic. We ended the day with some beer and silly jokes :)

The next day we went down the ghats and rode up to Calicut where we stopped for lunch (about 60 kms from Lakkidi). We visited the beach for a short period of time and then decided get back to Lakkidi. Once again we ended the day with some beer and silly jokes :)

On the following day (the 3rd day) we decided to head back to Bangalore. On our way back, we stopped at Edakkal caves at Wayanad for a couple of hours. Most of us were quite tired climbing up the hill to reach the mouth of the cave. The cave is huge and contains some caveman art; nothing much to explore there though.

We headed out from there at about 1:30 pm. We took the same route back and were back in bangalore by 8pm (with some breaks to rest our sore butts :). All in all, it was a great 3 day road trip. Most of us weren't really sure we could do over 300 kms a day. Now, we are quite sure we can easily do 400 kms per day. Should soon do a biking trip to Kanyakumari or probably Pune (visit the new TW office there :)

Here is a video of 2 camp elephants searching Sumukh for food.

Tuesday, December 19, 2006

WebServices --- Java/.NET interop issues

I've been working on a project where I need to port an existing service written in C# to Java. Your first question would be -- WHY ?? One should be able to access the service irrespective of the language its written in; So whats the point in porting a .NET service to Java ? I am not too sure about this, but I think the client wants all his applications in one language, so that its easy to modify it as and when needed.

With that answered, one would think its pretty much straight forward to port such a service. After all Java and C# have similar frameworks/libraries and constructs. Well.. that’s where most of us go wrong :(. Let me explain ---

This service is currently used only by .NET clients (but would soon be used by Java clients too). Many methods of the service return .NET specific data types like DataSet. This works fine with .NET clients since DataSets are serializable. When you come across such a method while porting, you realize you are pretty much screwed. Java doesn’t understand DataSets !! So, this is what we did -- we wrote a class which contains the following:-
1) Column names array (from the ResultSet metadata)
2) Column types array (from the ResultSet metadata)
3) Array of rowData objects ( each rowData object is an array of column values obtained from the resultSet)
4) Table name (required by DataSet)

An object of this class can be serialized and sent across to the client. On the Java side, you can create/generate this class and use it to read the results. On the .NET side, you can set the metadata and rowdata objects to a DataSet and also set the table name. You could then use that DataSet as before.
We could not return a 2 dimensional array of values (instead of array of rowdata), since we had problems deserializing the 2 dimensional array on the .NET side.

There have been quite a few such issues over the past couple of weeks, and I am sure there are more to confront. I’ll post again when I come across such issues. Btw, if you are designing web services with Apache Axis, do take a look at their wiki page for .NET interop issues ---> http://wiki.apache.org/ws/FrontPage/Axis/DotNetInterop

Some points for making interoperable services. Please avoid the following (taken from the wiki) :-
* Standard Java Collection classes.
* Typesafe enumerations. Use static final variables within Java instead.
* Multi-dimensional and jagged arrays.
* Sparse arrays (allowed in SOAP 1.1, not in SOAP 1.2).
* The Java char datatype is not supported because of an omission in XML Schema.
* Avoid using the same method name multiple times with varying parameters on a web service.


One last point --- If you are using Axis, please start with the WSDL first. Do not generate the WSDL from your classes/interfaces. Its a BAD idea !! Doing the WSDL first would help you comply with the W3C xml standard types, so you'd be almost guaranteed to interoperate. Unfortunately, we learnt it the hard way :(

Wednesday, December 06, 2006

Cordyceps

Came across this video on Yodha's blog. "The fungi infects the ant's brain, makes it go mad, pushes the ant to higher ground, kills the ant and grows a spike out of its brain !!". Another lovely narration by Sir David Attenborough.

Saturday, October 14, 2006

The best way to conserve....

is for humans to disappear from this planet.



Source : timesonline UK

Wednesday, September 27, 2006

7 signs of an entrepreneur

Came across this site while browsing casually.
So, how much of an entrepreneur do you have in you ?

Friday, September 01, 2006

Language Wars

I just finished reading this article on joelonsoftware and it is definitely an interesting read.


"In particular, a debate between the C#/.NET/IIS stack and the Java/J2EE/Apache/Solaris stack and the PHP/Apache/Linux stack could go on and on for years and years and you'd never find the right answer. That's because there are so many pros and cons of all these platforms that advocates of each side can debate and debate and never get any closer to the Truth, but it sure as heck is a fun debate."


Couldn't agree more !! You would come across such a debate in any IT/Software development firm, and quite often you'd be a part of such a debate. And it doesn't stop at programming languages... Developers love to argue over their favorite IDEs (Eclipse/IDEA/VS etc) too.


"Ruby is a beautiful language and I'm sure you can have a lot of fun developing apps it in, and in fact if you want to do something non-mission-critical, I'm sure you'll have a lot of fun, but for Serious Business Stuff you really must recognize that there just isn't a lot of experience in the world building big mission critical web systems in Ruby on Rails......"


This part is particularly interesting :-). I dont have enough Ruby or ROR experience to comment here, but I am sure some of my colleagues would be flaming Joel Spolsky about such a remark. Now that would be good fun to watch :-)

Wednesday, August 23, 2006

When Tigers attack....

Read this article --->

http://www.wildlifetrustofindia.org/html/news/2004/040609_joymala.htm



Now check out the video footage of the same incident

http://www.wildlifetimes.com/video/tiger.wmv



The tigress saw the ankush coming, dodged it in mid-leap and took a swipe at Pegu without actually landing on the elephant, which had stepped back,” Menon said.


What now happened was even more amazing. As the tigress landed on the ground Joymala quickly pinned her down with her left fore foot and tried to control it with its trunk. The tigress struggled under this weight for at least half a minute roaring, as other people in the vicinity shouted and fired shots in the air. In this commotion another attempt was made to dart it, but even this shot was off the mark. The tigress finally struggled loose and ran away.


The wonders of wildlife !! Marvelous.

Someday I'll work for the conservation of our wildlife.

Until then, I guess I'll be writing code :-)

Wednesday, April 26, 2006

Sahi --- A nice Web Automation and Testing Tool

We are using Sahi as a functional testing tool on my current project (Well, what else would you expect when Narayan is on the same team :-). Having used Selenium on my previous project, I find quite a few features of Sahi a lot more helpful in writing functional tests.

  • The record/playback feature is fantastic. While you are recording a functional script, you can append assertions to it by simply hovering over the required text (or other document objects) and clicking the assert button on the recorder.

  • You can assert text in any/every row in a table. This is a particularly useful feature when you have a sorted list of items to display and you want to assert that they are ordered correctly.
  • The ability to run multiple scripts simultaneously (i.e. in multiple threads) is wonderful. There are a couple of benefits in running your test suite using multiple threads – 1) it makes sure that you don’t have interdependent tests (i.e. some test that depends on the data created/modified by a previous test) and 2) Runs the entire test suite in a fraction of the time.

  • You can hit any remote machine and record/run tests against it. For example, if you have a build deployed on a production/QA machine, the QAs/testers can record and run the suite of tests on that machine instead of having to deploy the build on their local machine. (We are using this setup on our project and its working very well).
  • The kind of support you get when the author is on the same team :-).

I have used Selenium quite a bit on my previous project and I have liked it a lot. With Sahi, I see myself writing a lot more functional tests than I used to do before (and it doesn’t take much time to run them all).

Monday, January 23, 2006

In search of a Tiger

Narayan and I participated in a tiger census conducted by the forest department at Balle near Kabini. We were there for 4 days, trekking through the forest in search of pug marks, scat and prey animals (deer, sambar, wild boars, elephants etc.). We worked with the RFO (Range forest officer), Mr. Ravindra Kumar and few of his forest guards. Here’s a brief description of my experience during those 4 days.


Counting tigers in the wild

Well, it’s not an easy task. Chances of spotting a tiger in the wild are very low. A tigers' stripes may look striking in a zoo, but in the wild, it’s very well camouflaged. The thick vegetation of the south Indian jungles makes it a lot more difficult to spot one. We were in the jungle for 4 days, but weren’t lucky enough to see a tiger.

The census is conducted for a period of 6 days. There are 2 parts to it :- 1) Trek for about 5 -10 kms in the forest searching for tiger pug marks, scat and scratch marks on the barks of trees. 2) Walk along line transects of 2.4 kms, stopping at every 400m to note down the kind of vegetation, scat and sighting (if any) of prey animals. With this data, (i.e looking at the approximate number of prey animals) the forest department tries to estimate the number of tigers it could support, and also the distribution of tigers in various parts of the forest. This is nothing more than an informed guess and by no means an absolute number (or even close) of tigers in the wild.

Radio tracking tigers in the wild has been tried by conservation scientists like Dr. Ullas Karanth in various parts of India. Although this sounds to be a viable solution for counting tigers, it has a few problems :- 1) Catching tigers in the wild is a very difficult task in itself .. 2) A more serious problem is tranquilizing a tiger when seen. If the dosage is too little, it doesn’t serve its purpose; if it’s too much, it could be fatal. The forest guards told us that a few tigers had died due to excessive dosage. Hence, it’s not a widely used method to count tigers, although, it has been used to study individual tigers.

Another method worthy of mention is camera trapping. In this method, an automatically triggered camera is strapped to a tree. Whenever any animal moves in front of the camera, it fires and captures a snap of the animal. Since the pattern of stripes on each individual tiger is unique (much like the human fingerprints), these pictures can give us some idea about the number of tigers in the wild. But again, this method had its own problems :- 1) to setup camera traps at multiple sites in the forest proves to be expensive. 2) Large mammals (elephants) get disturbed when the flash fires and they attack the camera, breaking it into pieces. 3) It doesn’t necessarily photograph all the tigers in the wild.

Due to these problems, the first method is preferred and is widely used all over India to count tigers.


Challenges faced by the forest department

1) Habitat destruction:- A lot of tribals still live within the forest. They depend on the forest for their very existence – wood, food (basically meat), water etc. The forest department is trying their best to relocate them to the outskirts of the forest by providing them agricultural land and shelter.

A lot of villages surround the forest. The villagers have been cutting down the forests and converting it to agricultural land over the years. They graze cattle at the edges of the forest which eat most of the grass required for the survival of herbivores in the forest. Most of the poachers come from these villages. Since they have easy access to the forest, these poachers’ setup traps to capture deer meat, tiger skin, elephant tusks etc. (In the images below, you can see the paw bones of a tiger which was caught in one of these traps. Click on the image for a bigger picture.)


2) Finance:- The forest dept. is severely short of funds. Some officials mentioned that they couldn’t afford diesel to run their jeeps!! These jeeps / forest vehicles are old and in very bad shape. They don’t have sufficient funds to setup camera traps or procure GPS units to navigate within the forest.


Call for Help

Narayan and I spoke with the RFO about the kind of problems they face and how we could help them. We had no answers for many questions that he put forward --- “Why should we (i.e. the forest officials) put our lives at risk to protect these forests? We don’t get paid well enough, we have no social/family life and the living conditions/facilities aren’t great.”

This RFO (Mr. Ravindra kumar) had worked with Dr. Ullas Karanth at Nagarhole, helping him research the behavior and habitat of tigers. He has shot dead a poacher while a group of them were trying to steal deer meat from the forest (Read the full story here). We (Narayan and I) found him to be a very helpful, sensible, well educated and practical person and a great nature/wildlife enthusiast.

After spending 4 days/nights in the forest, living and working with the forest guards, I’m highly impressed (and moved) by dedication and interest that they’ve shown in protecting whatever is left of these Indian jungles. I’m thinking of ways to help them financially, but I alone can’t do much. I don’t know how many of you guys out there are interested in contributing to this cause, but if you are even remotely interested please do leave a comment or mail/IM me and I’ll try and get in touch with you.

PS :- 1) The paw bones that you see in the picture above belong to a tiger named “Maasti”. Maasti still survives (with only 3 paws) and is taken care of at Bannerghatta zoo, Bangalore.

2) I’ll upload the pictures (about 300 of them) as soon as possible.

Wednesday, November 30, 2005

Ruby Tuesday @ Xiamen(China)

I know that Perryn has already blogged about this; I'm just reiterating it. A group of us Thoughtworkers have started a small Ruby interest group here in Xiamen. We meet up every tuesday at 6:30 pm at Cafe Relax (near Xia Da) and read/pair/experiment with Ruby. We've had an impressive response so far (6 TWers and 2 local geeks, with one client developer dropping in occasionally). Perryn and Andy are writing a game(called "Go") in Ruby; their idea is to add as many new ruby features as possible and not really bother about good design.

I am really enjoying playing around with Ruby. It seems to have a few similarities to Java, but a lot of "new" ways of doing things (sometimes it makes you wonder why Java doesn't have those features). The only setback is the lack of a good IDE. I am currently using Eclipse with the RDT pluggin which provides syntax highlighting and (very little) context sensitive help. (When you've been working with IDEA or Eclipse for a while, it feels unnatural to type code!!) .

Anyways, If you are in (or around) Xiamen on a tuesday evening, and want to learn/discuss Ruby, make your way to Cafe Relax and look for a table with a lot of laptops (and some food :-).

Sunday, October 30, 2005

China : The Good, the Bad and the Ugly

I have lived and worked in Xiamen, China for the last 4 months. Its been an amazing experience, to say the least. I shall try and articulate my experiences/thoughts on what I liked and disliked during my stay there.

The Good

  • The people are simply great. They go out of their way to help others (including the “Laowai” --- Chinese for foreigner), even if they don’t speak the same language. There was this one time when Conrad and I wanted to board a bus but we didn’t have the exact amount of cash. Looking at our dilemma, an old Chinese lady (a complete stranger) actually offered us the required amount!!
  • The infrastructure is mind-blowing (compared to that of India).The public transport system is really clean and nice; Roads and sidewalks are wide and well made. The big cities like Shanghai and Beijing are well connected through subways. Shanghai in particular is simply awesome. It’s a well planned city with loads of high rise buildings and some amazing shopping malls. It’s also got the Maglev train which runs at 432 kmph!!
  • When it comes to food – the Chinese are definitely on top of the food chain. Meat constitutes the main part of their diet. Though this is not particularly great for vegetarians like me, the carnivorous humans :-) seemed to like the food a lot.

The Bad

  • Software piracy is quite rampant in all parts of China. One can get any DVD (Movies, MS Windows, Adobe Photoshop, games… literally anything) for 8 RMB (approx. 1 USD). You’ll find stores selling these pirated DVDs everywhere, not just in some shady streets. I don’t understand what the government is doing about it.
  • “The great firewall” can lead to some frustrating times. Quite a few blog, news and web hosting (geocities, bravenet, netfirms etc) sites are blocked. I haven’t blogged in 4 months since blogspot is blocked in China L. Google news was blocked until a month ago. Hope the government realizes this is doing more harm than good.

The Ugly

  • I personally hate “Chinese traditional medicine” for what its done (and still doing) to the populations of tigers in the wild. The Chinese make use of tiger bones to prepare some of their “traditional medicine”. This has encouraged poaching and pushed the south China tigers to the brink of extinction (there are only about 20 left in the wild!!). Now, the Indian tigers are being killed to satisfy the demand. The Indian forest department is making an amazing effort to save the tiger from extinction; it hurts to see that this is a losing battle because of the “medicinal” products from China. I hope the Chinese are educated about the evil effects of their “traditional medicine” before its too late!


That said, I still miss China a lot. I’ve made some really nice friends out there (Thoughtworkers and the locals) and really liked hanging out with them. Looks like there’s a good chance that I would have to go back to Xiamen for a couple of months :-). Hopefully this time I would get to see a panda.


PS :- Some of you may regard this post as unprofessional. I never intended it to be “professional”; It’s simply a collection of my experiences/opinions. I apologize if I have offended you in any way.

Monday, July 04, 2005

Ni Hao

Its been about 2 weeks since I arrived here in Xiamen, China. The place is really beautiful and very clean. It’s an island in south east China (very close to Taiwan). Language seems to be my primary problem out here since not many localites speak English. So I'm trying to learn Mandarin :-) . Here nearly everthing (Billboards, business cards, magazines, sign/navigation boards... even Windows !!) is in mandarin. As Bhavin puts it -- "We work with 128 bit encrypted version of Windows !!"
We do get veg food.. and that's how i'm surviving here. I've learnt to use chop sticks pretty well now. Its good fun using chop sticks (atleast its fun until you drop something on the table :-))


Red Eared Slider

Lotsa places to visit around here. So far have only been to the Amoy botanical garden. Its really huge and beautiful. I've got a lot of snaps but I cant upload them coz the network connection is very slow here. I've taken some good snaps over here. The one above is a Tortoise (a red-eared slider as identified by Naveein from INP) which I found in our backyard. I havent had any luck trying to photograph pandas yet :-(
I was shocked to find out that China blocks all blogspot sites !! (although I can login and post something.... i cant view it, or for that matter cant view any blogspot site !) . Thats the update for now. Hopefully, I'd be posting my experiences regularly.

Monday, June 06, 2005

Rock Agama

Found this guy in my neighbour's garden. Couldn't identify him immediately, but then found out that he is a rock agama. Here are a few links which provide some info about this reptile :-

http://animaldiversity.ummz.umich.edu
http://www.anapsid.org/agamas.html
http://www.junglephotos.com/africa



I would have loved to get a better shot at it. But my Canon A75 with a 35 - 105 mm lens doesn't help me in taking good close up shots. I'm considering buying the Canon S2 IS sometime soon. Why am I not buying a DSLR ? Well.. Its quite expensive to buy one. A Canon 350D along with a 70-200 mm lens would cost me about $1500 !! Any opinions/reviews on the S2 IS ?

Wednesday, May 18, 2005

Land of the Tiger

This is extremely disturbing news !! (Here's the Hindu and Deccan Herald version of the same story). 352 Tigers fall prey to poachers in the last 5 years! Why are these people killing tigers? Obviously for the money that accompanies a dead tiger. Its skin, teeth and nails fetch a lot of money.
How can we help? Well, sites like the http://www.tigerfdn.com and http://www.globaltigerpatrol.co.uk provide some information on how we can help. The most important thing to do is to stop buying such stuff and look down on people who do buy it (I would say... kill those bastards) .
Someday, I hope I would work like Valmik Thapar and Fateh Singh Rathore and help save the tiger. But until that day, I will have to write code to make a living :-).

PS :- Here's a gruesome video (taken from Anirudh's blog) which shows how animals are stripped of their fur to make fashionable dresses for us. I guess its high time for us to push back and stop supporting trading of fur, leather and other animal body parts.

Monday, May 09, 2005

Hibernate in Action

I have been trying to learn to use Hibernate over the last couple of days. After reading through the first 2 chapters in Hibernate In Action, I decided to try the "Message" example mentioned in the book. I used HSQLDB to persist the data. Initially I thought that we only needed to add the jdbc driver (i.e hsqldb.jar) and hibernate3.jar in the classpath. But then, a whole series of exceptions hit me in the face one after the other. Reading through the stack trace and resolving the exceptions one by one, I finally figured that the following jars need to be in the classpath for the program to run successfully.
  • the jdbc driver (in my case hsqldb.jar)
  • hibernate3.jar
  • asm.jar
  • cglib-2.1.jar
  • commons-collections-2.1.1.jar
  • commons-logging-1.0.4.jar
  • log4j-1.2.9.jar
  • jta.jar
  • ehcache-1.1.jar
  • dom4j-1.6.jar
All of these jars (except for the jdbc driver) come bundled with hibernate 3.0.

While specifying the configuration options for hibernate, we have 2 options --- either to use the hibernate.properties file or the hibernate.cfg.xml. There are subtle differences b/w these 2 methods :-

1) If you are using the hibernate.properties file --- While building the SessionFactory object, we don't need to call Configuration.configure() , but we do need to call Configuration.addResource() to specify the mapping files. i.e. --
Configuration configuration = new Configuration();
configuration.addResource("Messages/Message.hbm.xml");
SessionFactory sessionFactory = configuration.buildSessionFactory();

If you are using the C3P0 connection pool, you need to add c3p0-0.8.5.2.jar (comes with hibernate 3.0) to the classpath.

2) If you are using the hibernate.cfg.xml file --- While building the SessionFactory object, we do need to call Configuration.configure() , but we don't need to call Configuration.addResource() to specify the mapping files since we could specify it in hibernate.cfg.xml itself. i.e. --
Configuration configuration = new Configuration();
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();

Hope this helps when you are writing your first hibernate program :-)

Tuesday, April 26, 2005

Visit to Bannerghatta


The majestic white tiger at bannerghatta


On Sunday, I had been to Bannerghatta wildlife sanctuary with a few friends. It was an amazing experience, although it was very depressing to see the human population surpassing the animal population at the sanctuary. We got to see a whole lot of wild animals --- Indian Python, Rat snakes, Russell’s vipers, King Cobras, Zebras, Bears, Leopards, Tigers, Lions, Hippos etc. I believe there are about 35 tigers at the sanctuary, including 3 white tigers. I didn’t get very good shots of the big cats as I hoped to get. Here are a few snaps that we managed to shoot. I wish I could take a break from work and shoot some more of the wildlife. Anyone willing to sponsor a wannabe wildlife photographer ??

Saturday, April 09, 2005

OODBs

I was discussing with Sheroy about persistence frameworks and the need for O/R mappers in Enterprise applications. We were talking about Hibernate and how it is being incorporated in EJB3 specs. The conversation then (naturally ??) shifted towards OODBs. There seems to be quite a few advantages of OODBs.
The most significant advantage of OODBs is that we eliminate the need of a separate data model. The data model just reflects your object model. Most modern Enterprise Applications have different object models and data models, and an O/R mapper to map the objects to rows in the database. This adds another layer of complexity to an already existing complex system, at a substantial cost. An OODB eliminates the need for this layer altogether.
If your application uses an RDB and you must reconstruct an object from data in the database, you frequently have to perform multiple queries. These queries could result in serious performance bottlenecks if not written efficiently. Constructing Objects from OODB records is straightforward. Another advantage with OODBs is that we don't require a separate query language like SQL. All the queries can be written in the OO language itself.
If OODBs have all these advantages, why are we then stuck with RDBs yet ?? Here are a few reasons that I could think of -
RDB is a proven technology which has lasted the test of time. From legacy systems written in COBOL, to applications written in Java/C# interface with RDBs. This allows the us to change the application technology to enhance scalability, performance and security and still use the same data model. This is a significant advantage, since the persistent data is considered to be the vital part of an application. OODBs on the other hand, tie us to a specific programming paradigm (and possibly to a particular OO Language) .
OODBs are an excellent tool for storing and retrieving objects. Most applications do not always load objects. Rather, there will be times when we need to search by ranges, patterns, and fuzzy criteria spanning objects that do not have obvious relationships. OODBs may not provide adequate support to such ad hoc queries.
All said and done, I think OODBs are a great way of working with data, and definitely worth a closer look.

Thursday, March 17, 2005

Photography

Photography is my latest craze. I have developed an interest for digital photography ever since I got my Canon A75 a few months ago. Although, this camera doesn’t have SLR like features, it’s good enough for beginners like me to get started on photography. Once I get really good at the art of photography, I hope to buy the Canon Digital Rebel (EOS 300D) or the Nikon 70D or some other Digital SLR….
I have been playing around with Adobe Photoshop for a couple of weeks now. It’s probably the best piece of software that I’ve ever used. The number of tools available is simply mind-boggling. I have never really used GIMP, but I am told that GIMP supports quite a lot of features that Photoshop currently provides. Guess, I’d be experimenting with GIMP sometime soon.
I have uploaded a few shots that I have taken at http://chirdeep.netfirms.com . I have also uploaded a few Photoshop effects that I’ve experimented with. Hope to update it as frequently as possible. Feedback/Criticism is welcome.

Thursday, March 03, 2005

Bad usage of instanceof

If ( Object instanceof ClassA || Object instanceof ClassB){
// do something
}

I have come across such code in many applications. Why would developers write such horrendous code? It clearly beats the whole purpose of polymorphism, doesn’t it?

Consider ClassA, ClassB and ClassC implement an interface (say InterfaceA). Wouldn’t the code look more elegant if we add a method to InterfaceA (say doSomething()), implement the method in ClassA and ClassB and provide a dummy implementation in ClassC. Then, the code would look like

Object.doSomething();

The problem with this approach occurs when there are too many implementations of InterfaceA and only a few of them need to implement the method doSomething(). In such a case we could create an Abstract class (say AbstractClassA) which provides a default implementation of the method doSomething(), and override the method only in those few classes. I really think this would be a more elegant solution.

Having said all that, I fail to understand why the instanceof operator was provided in the first place!! Is it only to promote short term hacks like this??

Thursday, February 17, 2005

Mac at first sight

Last weekend Rajesh had got his new Mac G5 to the office. It was simply superb, to say the least. Karthik and I used the machine for sometime and we were totally bowled over by the features. This was the first time I was using a Mac. I have seen the ibook and the Powerbook, but never really played around with them. This was my first shot at it. In one of my previous posts, I had mentioned that Microsoft was “arguably” the best UI designer. I couldn’t be more wrong!! The UI of the Mac OS simply rocks. It’s a lot more responsive and has tons of visual effects. Also, there’s the familiar bash shell for the console freaks.

We were looking through the hardware configuration of the machine when suddenly something called AirPort caught my attention. Guess what that is! It’s the wireless port! Come to think of it, the name actually makes a lot of sense, doesn’t it?

There’s one thing I dislike about the Mac though. It comes with a single button mouse!! To right click, you need to hold the command key and click. Also there’s no scroll wheel !! The right mouse button and the scroll wheel makes life so much more convenient while using a PC. What were those Mac designers thinking?? It’s like giving the next generation computer with a 20th century mouse.