Friday, October 21, 2005

Updations on XML

I didn't have much work for today except for attending a series of (boring) meetings and churning out word docs and spreadsheets, the weekly status reports and the rest of the junk, tch!. A friend of mine mailed a problem that triggered a deluge of mails with interesting and impressive ways to solve the problem. The hinge point of the problem relied on a XPath expression that should perform a "reverse search" - retrieve all nodes with any attribute having value "abc". Here is my approach:

1. The attribute can be nested anywhere in the document, so my expression starts with //
2. Should return all matching nodes, //*
3. Th test condition is a predicate, //*[]
4. The tricky one, each is a attribute node and can be any attribute,
//*[@*='abc']

That completed the XPath expression.

The complete solution for the problem was decided to be implemented using XQuery. Awesome! Sometime back, I implemented a basic screen scraper (HTML parsing) using XQuery, but that was stop-gap solution and didnot scale well. I'm still a novice to XQuery and wanted to learn the nitty-grrity of the FLWOR expression. As XQuery relies on XPath, I chose to update on the XPath2.0 first. The new version has added functions to make lives easy. Some of such functions are collection,current-date,current-time,implicit-timezone etc. Ofthese, the collection function, apparantly, was found very useful. It can be used to overcome the memory issues with the doc/document() function. This would not only eliminate a round of looping but also offers a clean solution in terms of performance.

Thanks to my friend, my XML arsenal got enriched with new info.

Monday, October 10, 2005

Program to an Interface or Design Pattern

Nowadays, I often hear people saying I used the X design pattern, Y design pattern giving a lengthy list of all the patterns. But when asked what is the motivation behind using a particluar pattern, there is always a stunning silence. Most of the developers these days want to make their resume impressive, so they use every available api and design patterns. The outcome is code that is not readable, bloated and not maintenable.

This reminds me an incident in a well known Telugu movie - the hero wants to learn the fine points of a martial art and want to avenge the death of his brother. The master asks him to realize that the true meaning of the martial arts is Non Violence. The analogy many not be apt, but sensible developers should realize that the design patterns help in producing code that is adhering to the OO principles and code that is maintenable.

Power of XML Entities

I have been using XML for quite sometime in my projects and was quite comfortable with the semantics and syntax. Today, I added a new tool to my XML arsenal - realized the true power of "entities". So far, my understanding of entities is that Entities are variables used to define shortcuts to common text viz. "& copy ;" for © etc. Now, I would like to paraphrase the statement to Entity references are references to entities. The reason for this ...

My requirement was to copy the contents of two config (XML) files into one single config file. The two files are in different directories. I was evaluating the possible solutions to pick an optimal option. A few lines of code did the work, in a elegant way:



<!ENTITY file1 PUBLIC "path1/file1.xml" "path1/file1.xml">
<!ENTITY file2 PUBLIC "path2/file2.xml" "path2/file2.xml">
<root>
&file1;
&file2;
</root>


The entities would get resolved while parsing the file and the contents get copied dynamically. This is such a useful feature, saved lot of LOC and moreover the bottleneck of "transformation" has been avoided. And to display the code fragment correctly on this page, I had to use "& lt ;" and "& gt ;" :-)

Monday, October 03, 2005

A week full of activity

Last week was full of Activity. on Monday and Tuesday, I worked for 14 hours a day under a "unrealistic" target. Whew! Wednesday and Thursday were bit eased up with 10 hours of work. I had to accede to such unplanned and a work without a process as it was a request from the client. Friday was a day of relaxation with absolutely nothing to work on except going thru the BRD of the work for the subsequent week.

On the weekend, I met some of my colleagues from previous companies and the topic immediately was the burgeoning job market in Bangalore and Hyderabad, and interview (er)s. It seems one of them has attended an interview with a major telecom company in Hyderabad. The first round went off well, both the interviewer and interviewee enjoyed the discussion talking many things about technology, issues faced in the project and how they have been resolved. The next round, it seems, was pathetic.

An (incompetent) interviewer with more than 8 years of experience and miserable communication took the second round. I couldnot help laughing when my friend told that the person literally barged into the room, shook hands and immediately asked about JVM architecture and the difference between "==" and ".equals()". My friend got a shock of his life at the crude behavior and started answering with patience. Soon, he realized that the interviewer is expecting bookish answers and is reluctant to accept any answers other than what he had in the mind. My friend should have known "Telepathy". A couple of funny questions and answers from the interview:

Interviewer: "Which method will you use for file upload, doGet() or doPost() "
My Friend:"doPost(), as multipart requests are supported, explained about multipart requests, form processing of the fileupload, limitations with doGet()"
Interviewer:"Fine, but you didn't tell that doGet() doesn't support transfer of binary content."


A more funny interaction occured at a later stage..

Interviewer:"Do you know design patterns? How did you use them in your projects?"
My Friend;"I know core java patterns and J2EE patterns, but don't use them because they are there. If there is a compelling reason, I use a design pattern. In my projects I used Factory, Visitor, Singleton.. the list went on"
Interviewer:"Hold on.. You said Singleton.. How did you use Singleton, How did you implement a Perfect Singleton?"
My Friend: (Routine Question)..gave the bookish answer the interviewer was expecting and the end added "I prefer using registries instead of singletons as singletons are not interface friendly and pose problem in a clustered application"

Now it was the turn of the interviewer to get shocked and it seems he was reluctant to take the answer and started arguing insensibly. My friend remained silent, nodded his head in agreement to whatever the other person said and finally got an offer from the company and now the interviewer is his project lead..hehehe!
These days it is not uncommon to hear about such incidents.