Monday, March 31, 2008

Asking questions on Forums

“The important thing is never to stop questioning.”
Albert Einstein

I was reading Shay Shmeltzer's and Hector Rivera Madrid's post on the generals rules on posting on User Forums. I don't want to summarize a list of my own as these gentlemen have already prepared a wonderful list of do's and don'ts.

I still have a bookmark to an old article - How to ask questions the smart way. The article is still being revised and maintained.

To summarize Shay's intentions :-

" I think there are some things that posters to the forums can do to make the whole experience of using the forums a lot better. "

Friday, March 21, 2008

Holi - 2008


It's Holi ! The festival of colors ! It's time to get drenched in a variety of colors !

Originally, Holi started out as a festival to celebrate good harvests. Now, it's more of a festival to have a good time :).

The day also marks Good Friday.

I am sitting at office trying to complete a pending task & suddenly, my colleagues smeared colors on my face. I am totally covered in colors & my laptop is sharing the same fate.

Well, I am looking forward to more fun & frolic during the weekend !

Self Appraisal

Another "gem" that I received in today's mail - thanks Vijay !:-

A little boy went into a drug store, reached for a soda carton and pulled it over to the telephone. He climbed onto the carton so that he could reach the buttons on the phone and proceeded to punch in eight digits (phone numbers).

The store-owner observed and listened to the conversation:

Boy: 'Lady, Can you give me the job of cutting your lawn?

Woman: (at the other end of the phone line): 'I already have someone to cut my lawn.'

Boy: 'Lady, I will cut your lawn for half the price of the person who cuts your lawn now.'

Woman: I'm very satisfied with the person who is presently cutting my lawn.

Boy: (with more perseverance): Lady, I'll even sweep our curb and your sidewalk, so on Sunday you will have the prettiest lawn in all of Palm beach, Florida.'

Woman: No, thank you.

With a smile on his face, the little boy replaced the receiver. The store-owner, who was listening to all this, walked over to the boy.

Store Owner: 'Son... I like your attitude; I like that positive spirit and would like to offer you a job.'

Boy: 'No thanks,

Store Owner: But you were really pleading for one.

Boy: No Sir, I was just checking my performance at the job I already have. I am the one who is working for that lady, I was talking to, and I was doing my 'Self Appraisal'

ORA-01000 maximum open cursors exceeded

" java.sql.SQLException : ORA-01000: maximum open cursors exceeded "

-- ORA-01000

I was recently asked my a colleague to help in resolving the ORA-01000 error. At a first glance, everything looked fine in the Java Code & it was baffling - it took sometime for enlightenment to illuminate the nature of the problem and one possible solution.

The program inherited by my colleague had two Java classes - Class A and Class B. Class A calls a method named insert() in Class B to save data into the database. Class A passed an ArrayList of Java Beans to the Class B's insert() method.

The logic to save the data was a plain - vanilla for loop :-

for ( int i = 0 ; i < number ; i++)
{

psSaveData = conOraleConnection.prepareStatement(insertSQL);
..........
..........
psSaveData.setString(1,dataBean.getId());
psSaveData.setString(2,dataBean.getName());
psSaveData.setString(3,dataBean.getAge());
..........
..........
psSaveData.executeUpdate();
}

Now, this piece of code was failing after the first 1000 rows !

We took sometime to methodically analyze the problem using an approach outlined at this link from BEA's Website. However, the problem persisted - either we missed something obvious or we were looking at something new. And then it occured to us :-

psSaveData = conOraleConnection.prepareStatement(insertSQL);

We finally figured out that the problem was caused by the statement marked in red. The line was actually telling the Oracle Database to precompile the same statement 1000 time !!

How does this matter ?

The Oracle Database contains a SQL Engine to deal with all SQL statements. The SQL Engine generally follows a two step process to execute a SQL Statement:-
  • parse : to check for syntax and semantic correctness.
  • execution plan : an optimized plan that details the instructions to execute the SQL statement.
The SQL Statement and the corresponding execution plan are stored together in a structure called a "Cursor". The Cursor is then stored in a special area of database memory called the "Shared Pool".

You can get handle to a cursor from a variety of languages like PL/SQL, Java, etc. You can then :-
  • Open the cursor.
  • Fetch the results
  • Close the cursor.
The Oracle database opens an "implicit cursor" for every SQL Statement that it encounters. Hence, a cursor is opened for every SELECT, INSERT, etc. statement that is issued to the SQL Engine.

Hence, you only need to prepare the "blueprint" once and execute it multiple times. The piece of code marked in red was preparing the "blueprint" 1000 times - as a result, 1000 cursors were opened !

We simply moved this line out of the for loop and solved one bottleneck.

We also noticed that the plain-vanilla JDBC Insert statement was not suitable for batch inserts. Well, that's another story :)


Thursday, March 20, 2008

Inspirations from Frogs

I was Googling around for something & came across this wonderful site about frogs. A page on the site is dedicated to "Frog Fables" - an eclectic of parables with a frog / toad as the topic of discussion.

I personally liked the story of "The Boiled Frog". I found it surprising that a frog's natural instincts are fine tuned to detect sudden changes in an environment, but not the slow changes that ultimately lead to the same change in the environment.

Well, this quote from the page, summarizes the story :-

" This parable is often used to illustrate how humans have to be careful to watch slowly changing trends in the environment, not just the sudden changes. Its a warning to keep us paying attention not just to obvious threats but to more slowly developing ones. "

Monday, March 17, 2008

Appending zeros in front of a number

I recently helped a colleague who had this simple requirement - to append zeros in front of a Number in a Java Method.

The purpose of the Method was to scan numbers between 1 and 999 and ensure that every number has three digits - the ones that have only two digits are appended by zeros.

The problem has multiple solutions & we were looking for the simplest possible solution. We tried a lot of solutions, starting with a simple for loop that counted the number of digits and appended zeros in front of it. We also looked at the Java API to see if a solution is already present.

However, we finalized two solutions that were very simple & elegant :-

Solution #1 ( JDK 1.5 onwards )

String.format("%03d", 1);
String.format("%03d", 10);
String.format("%03d", 100);


Solution #2 ( pre - JDK 1.5 )

NumberFormat objNumberFormat = new DecimalFormat("000");
objNumberFormat .format(Integer.parseInt( "1"));
objNumberFormat .format(Integer.parseInt( "10"));
objNumberFormat .format(Integer.parseInt( "100"));

We used Solution #2 to make the code reusable between JDK versions.

Thursday, March 13, 2008

What is domain knowledge ?

"Domain knowledge is defined as the collective knowledge gained through education, training, or a series of assignments in a functional area"

- Compensating for Incomplete Domain Knowledge

I frequently encounter profiles of candidates who claim to have knowledge in many domains in a very short time - sometimes, even less that two years. I usually view these profiles with suspect & many times, my suspicion was confirmed during conversations with the candidates. The candidates merely mention the domain of the clients they have worked with - often, they are unable to answer simple domain related questions or explain business needs that prompted the solutions they implemented.

I found that the definition I have mentioned in the beginning of his article captures the essence of Domain Knowledge. I would like to present my views about Domain Knowledge in this article.

Domain Knowledge is often gained through conversations with the business users. Often, Domain Knowledge is :-
  • Informal
  • Ill Structured
  • Incomplete
How is this kind of knowledge important ? What makes some of the IT companies & head hunters scourge for people with this kind of Domain Knowledge ?

Domain Knowledge is a key component in understanding :-
  • the problem space
  • the proposed solution
  • the slightly "bigger picture " - how the proposed solution formed a piece of the bigger puzzle.
Domain Knowledge is important as it helps you to communicate confidently with the business users in a particular domain. It helps you communicate to the business users in their language.

Example: if the users want to see a "tank", do they want to see an Armored Tank or a Septic Tank ?

You'd definitely be more confident in your solutions, if you knew precisely what the users expect to achieve from your solution - a few of these are :-
  • save time
  • co-ordinate better with their peers.
  • focus more on higher level activities after automating the trivial ones.
Domain Knowledge is also narrow - you may only focus on one minute part of a bigger piece in a huge puzzle. However, a good understanding of the minute part will serve as a foundation to explore the bigger piece & venture into the huge puzzle.

Example: if you are confident about your understanding of the Recruitment Loop ( contact - schedule interview - propose offer - recruit ), you could easily move into other functions such as Trend Analysis, Vendor Management, etc.

Example: if you are confident about your understanding of the HL7 Healthcare Messaging Protocol, you could comfortably move up to understanding Patient Demographics, etc.

Domain Knowledge is thus very helpful in understanding the needs of the business users better & providing solutions that closely match their needs.

I would definitely love to hear about different opinions on this topic.

Tuesday, March 11, 2008

Learn Programming in 10 Years


" Learn thoroughly whatever is to be learnt;
Then, let the conduct be worthy of this learning "


I just came across a wonderful article titled "Teach Yourself Programming in Ten Years" crafted by Peter Norvig. I would recommend the article for anyone looking at a career in the IT Industry.

It takes a lot of effort, discipline, sacrifice & experience to learn & understand a subject, let alone master it. An artifact that claims to offer a "shortcut" to learning in a particular subject in a very short time, is simply dubious in it's claim.

You may probably get an insight into the subject being discussed, but learning takes its own time. You my need to encounter many "aha!" moments to ultimately arrive at an understanding of a small part of the subject.

I feel that the books that claim - "learn x in y days/hours" are best to simply get a "foot in the door". You can get hooked to the topic and the books do justice in enticing your interest in the topics. I would recommend these books if you need to quickly get an outline of a subject and start work on it - and, probably plan to learn on the fly.

A good example is the software books with similar titles - you can quickly learn the syntax & replicate some of the code recipes shown in the book & achieve small-time victories.

However, if you are looking for a long term solution, there is no shortcut.

Many thanks to Thiruvalluvar and Peter Norvig !

Which Programming Language is good ?

"...One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them...."


The topic has been debated numerous times in the past, in various Forums, Newsgroups, mailing lists, coffee tables,etc. - but, it still goes on. The answer has always been the same - you need to choose the right tool for the right job. The mythical "Silver Bullet" does not exist & there will never be one.

You need to decide the tool to use for a particular job & use that tool correctly. It's no use trying to debate over the "best" language & these discussions are simply absurd.

I think this "old" article by Tim Daneliuk summarizes the thought process that goes on in these kind of debates.

Moral of the story : There is no Silver Bullet. There is no One Ring.

Monday, March 03, 2008

Pitfalls of JSF

Java Server Faces ( JSF ) is yet another Java Web Framework that promises to simplify the development of JEE-based web applications.

It deviates from the traditional "request-driven" approach adopted by MVC frameworks such as Struts & attempts to achieve the same with a component-driven model.

I am a fan of this Component-driven model & am still nostalgic about some of the work I did in Visual Basic, Oracle Forms, etc. many eons ago.

However, JSF, in its current version has a lot of pitfalls - some of the pitfalls are unique to JSF & drastically hinder the productivity gains that were promised in the JSF specification.

I was reading an interesting article on TheServerSide.com about the pitfalls of JSF . The article by Dennis Byrne was well written & covered some of the most important pain points in JSF.

I particular liked his last topic where he sympathizes with Portlet Developers. I found this sentence very emphatic :-

" I feel sorry for Portlet developers. I really do. These people are always on the mailing lists and forums with problem after problem and it's never their fault. If any group of people has been bent over by the standards bodies, it is Portlet application developers. "

Truly, a very good article that captures some burning issues that can keep a developer up all night.