Sunday, December 24, 2006

ORM Vs SQL

There are two religious parties in java development world while dealing with persistence part of enterprise applications. It is one of the toughest decision Java architect has to make while joining any one party here.
  1. ORM

  2. SQL (JDBC).

Let me confess first, I belong to first party & here I am trying to put some arguments in favour of that. :-)

As the software evolving from monolithic programming to object oriented (We have procedure oriented, structured way of coding in b/w these two)the main motivating factor has been,

  1. Code reuse (No code duplication) that improves time to market and maintanability.

  2. Smallest possible lines of code providing the same result without sacrificing the readability & acceptable performance(Speed,memory etc...).

Hence the major criteria for assesing quality of the source code is reusability and maintainability.

Why SQL affects maintanability and scalability of application?

Working in Java - my business logic is object-oriented (With the advent of lightweight framework and domain driven design). As we cannot create well designed java application without (OOAD, all the data-models and queries that I need to construct separately & is definately duplicate my logic, even though I already have the same in my Java code I need to duplicate the same in SQL, so source code is defintely not going to be short.And worst part is every time I change my Java code, SQL also needs to be changed.

With ORM (Hibernate), we have persistence meta information in annotation ( with XDoclet) & we don't have to write any extra code if we change any of java code(for schema change). An ANT task should be able to do all the schema update. Database is a persistence layer. There is no need to know anything about persistence layer, except that it stores data persistently & that's it business logic should have nothing to do with it. ORM also gives RDBMS independence it can be huge benefit supporting business agility and avoiding vendor lock.

"PL/SQL provides better performance"
I don't think (from my experience) where well designed ORM fails on performance. Proper use of cache layer should solve the problem. Now cache frameworks are much matured, and ORM tools comes with out of box solution for the same.
Thinking about performance too much is counter-prodctive. It is always possible to revisit 5% of usecases where we might have to refactor to improve the performance with PL/SQL. With the productivity gain that we get out of ORM it is very much possible to absorb this 5% effort very easily in the end.

ORM Learning curve is huge”
This is usual execuse given by the project development team & these set of lazy developers/managers who refuse to learn new techniques & happy using old worked solutions. Actually dead line pressure should be more strong reason to choose ORM. Nothing can be done to DBA paranoids who cannot (probably unwilling) learn and appreaciate the the importnace of Object orientation.

Having said that here I am not trying to downplay the importance of SQL. ORM tools are using SQL behind the scenes - that's what they do and I beleive Hibernate is the most popular exactly because Gavin King made it as SQL-friendly as possible. But it needs proper usage, that's all. One has to learn & appreciate the importnace of referential integrity and durabability that RDBMS has brought into the software and the huge cost/effort investment made in these RDBMS products will be valuable in the coming decades as well. We need to understatnd why it is an bad idea to run the same query in a loop, why there should not be many networking calls, why the query needs to be optimize to minimize the scan, why we should try to bring minimum possible data to presentation layers, why to device a way to handle open ended queries etc...

In situations like complex legacy model, Many set based operations (Batch updates/inserts), too much normalization or denormalization (No natural O/R mapping) ORM is definitely not a good candidate. It's a overkill.
In these scenario's also iBatis SQL map & Spring JDBCTemplate offers better value proposition.

Finally,
In any new development project there is no technical or political reason left to use plain JDBC/SQL solution for handling persistence layer.

Monday, December 18, 2006

Interviewing Tips

With the plenty of FAQ/Q&A available on Internet & books, most of the programmers are aware of nature of questions. If any one get selected by sheer power of raw memory, I guess that is unfair. Memory is also important but definitely not more important than the ability to assimilate just in time information to solve a particular problem.This is more important with the advent of Google Search & development methods.
So I think we should give 50-50 for both knowledge & analytical skills. We cannot undermine any of these two, both are equally important. With amount of APIs and available options we cannot afford to have good analytical person taking more than few months to learn & apply in 6-7 month duration projects.

Give a problem and see how the API design is done for that. Look out for class names, method names and handling alternate flows. Naming classes/methods and cache invalidation remains toughest part of the software creation. Probe on what difficult problem they have solved so far.

Q & A on factual details aren't useful & definitely not the best way to reject or consider.

Here some personal set of questions that I would like to consider while interviewing a person for technical lead position in my company. (Mainly in Java) All the professionals claiming developing web applications should be able to answer all these questions without any hesitation.

JSP/Servlet:
1. Difference b/w forward and re-direct & use cases for them
2. Difference b/w jsp include and include directive
I would expect senior guys to explain the actual implementation details by the container rather than just functional difference & usage scenario's.
3. Scope questions (session,request,application & page)
I expect senior guys to explain me terms like web clustering, session replication, load balancing, thread safety & it's implications on data stored in above scopes.
4. Explain the stateless nature of servlets,(It's life cycle, SingleThreadModel, web.xml entry requirements, ActionServlet implementation details if the candidate is aware of struts)
5. Filters, Listeners & their importnace.
6. Web framework(s) & their relative merits/de-merits. (Action Oriented Vs Component oriented) again from senior guys.

Core Java:
1. java.io.Serializable/Cloneable marker interfaces and their importance. Deep cloning Vs Shallow cloning.
Different ways of instantiating Objects & their overheads (new, Cloning, Serialize/De-serialize, reflection)
2. Collection API knowledge
Choosing a right collection is one of very important characterstic of good java programmer.
Practical usage of Map,Set,List from their experience. Performance related issues with them.
(Synchronized, Non synchronized)
A problem that involves string manipulation and usage of Collection APIs.A successful candidate should be able to produce code using proper APIs.
3. Exception Handling, Im-mutable nature of String
Any programmer who has coded in java should be easily able to tell about the difference/example for Checked Exception & Unchecked Exception. It will be interesting to debate on this issue with senior guys taking popular framework into consideration.

For Example reversing a given set of string with removing duplicates & sorting them alphabetically in case insensitive manner. Candidate should be able to pick up TreeSet, Comparator & String manipulation stuff.
Searching for a string in a file, It's important to see how the candidate write the code taking performance, Exception handling into consideration.

JDBC/Database:
1. Importance Normalization & join.
Difference between an inner join and an outer join
2. foreign key constraint? what can happen when you try to delete a parent record?
3. ResultSet, Template pattern, How to get column details from the table name?
4. A SQL query problem involving either outer or inner join with aggregate functions.
5. Dirty Reads/Phantom Reads. Selecting isolation levels .
6. Spring/Hibernate value addition
Spring Templates (For JDBC, Hibernate) I can't forgive a experienced person who is unaware of these APIs or he should be able to explain the home grown utility to reduce the # of lines of code in persistence layer
7. Lazy, Eager & Batch fetch strategies (With hibernate context if the candadate is hibernate aware)

Overall application architecture:
(These are must for architecture position)
1. Layering of application and their importance.
2. Technical benefits of EJB & how i tries to solve all these issues.
a. Security
b. Transactions
c. Distribution
d. Scalebility
Pragmetic aproach here should be appreciated rather than violent pro-against stand on EJB's.
3. Lightweight architectures
4. Design patterns & their benefits
You can pick up any pattern & discuss on the same, It's amzing to see people's answers when I ask difference b/w Singleton/class with all static methods & use get/set methods of javabeans :)
5. OOAD
Difference static binding Vs Dynamic binding typically discussion should start with questions like can we extend String class (with String being a final)
6. Knowledge of existing frameworks & shortcomings of those.
7. Asynchronus communication JMS, Thread, MDB

After this I have this matrix to measure the technical competence

Technology Ratings (1-5)
Core Java 3
Application/Framework 2
JDBC/DB 2

I will enter my rating (1 min & 5 Max), & it is more 5 in any he should be hired or can be considered for next round. If it is 3 in all the cases he can be considered.

In the same fashion non-technical competence can also be considered. But I don't want really want to consider this (May be as input for HR guys)

Criteria Ratings(1-5)
Previous Company/Projects 3
Academic Record/Stream 1
Attitude/Communication 2

For management position
1. Estimation techniques.
FP, WBS
2. Conflict solving ability
3. CMM levels & overall quality processes

Any thoughts on this??

Thursday, December 07, 2006

It is very important to articulate the expectations on attitudes and behaviour from new developer coming into software development team.
Here are the few points I tried to come up with...
I want to ask them to take oath on these principles

  • I will not resist learning new techonology to solve problems, but enjoy the chance to do so.
  • I will not blindly accept any technology or innovation but will always try new solutions, I will research & keep up on news about new solutions & never feel unconfortable to modify the source code that I am not familiar with.
  • I will not throw out the same working solution to a problem every time. I want have the good track record of introducing new ideas & technologies
  • I will try solutions without complaint or fear of failiure (& always own up the responsibilities to correct the same & never insist on using the same solution behind other's backs to management
  • I will never undermine the technology & always ready to accept good things coming from all the ways.


Tuesday, October 24, 2006

Java Framework Information Fatigue Syndrome

'We're often seeing a failure of concentration. We're seeing a loss of motivation, loss of morale. We're seeing greater irritability.'
-- Psychologist David Lewis
This was attributed to ammount of information that a person has to take in general these days & I guess same principle can be easily applied to Java space as well. There are so much of frameworks and patterns. I have seen this syndrome in many senior Java developers. It is becoming harder to cope this day after the day.

In today's competitive business world it is imperative that everyone delivers at a pace that has never been imposed upon in the past. User expectations risen sharply & there is growing trend of technical awareness & knowledge how technology can help to deliver products with shorter time to market impose an overwhelming challenge to business.

More often than not it is discovered that the programmers/designers requires technical assistance and guidance to be able to successfully deliver. It is also observed that strong technical people get caught in several non-technical (but important) aspects. This quickly results in shift of focus, diluting the drive towards technology & there is no time validate the information & the quality of web frameworks. There is so much of options to choose & there is no time to spend in learning.

Annual increase in the rate of change of information is moving at alarming speed. A modern java programmer after spending about 18 months to attempt to master JDK 1.4 >25,000 methods, now he must learn an additional 8,000 more methods for JDK 1.5 ( >30% increase) Now we have huge JEE stack with all the tons of web & persistence frameworks.

So forget about mastering all the stuff, it is nearly impossible to master all the technlogy stack with fighting ever ending project dead lines. Can we afford to neglect these trends? Not possible ! especially people in technical stream (Like me) & decided make living out of technical career, the situation is frightening.

So what's the way out?
There is no way we can get out of reading/learning new frameworks; We have to understand and appreciate the innovation to stay competetive. We have to spend quallity time in going through the code/innovation.

I think the best for us to follow the best brains. I consider Rod Johnoson & their ilk of Spring are the best bet. We have wasted enough time on EJB's & many JCP specs. JCP seems to be worried about only the technical excellence (Making generic very clever specs) but forgetting the developer life. Even big guys like IBM & BEA didn't help. It was Rod & his ilk who made our life simpler by making us to write lesser code & hence lesser bugs. So that we can spend more time with our family.

Even if people with same caiber like Gavin King (JBoss Seam), Geert Bevin(RIFE)... can innovate better, Spring team should be able to adapt these innovation without any hesitation. (By seeing there track record of DRY). So it is best for us to stick to them.

Final words,
The key to survival and indeed productivity is to have a firm grasp of fundamentals, and to be able to assimilate just-in-time information.
&
Blindly follow the Spring.

Saturday, October 07, 2006

Java Design patterns - Few tips to learn.

Learning & remembering design patterns is a difficult task. The real world working samples & real world metaphors on how really a pattern is used to effectively to solve a problem in a given business context is very important in learning patterns.

I found this article on http://mahemoff.com/paper/software/learningGoFPatterns/ is very useful in that context.

I really liked idea of coming up with metaphors for each pattern & I think if the metaphor includes some of the open source code as samples it will be really great. Cooper's book on design pattern gives only the java SWING samples & I guess it would be better we can extract the patterns samples from popular server side java framework. 90% of java programmers write server side programs & not the SWING.
Unless untill these pattern samples are captured from successful implementation (with real productivity improvements) I really doubt the effectiveness of the patterns. I felt the samples provided by Martin Fowler (Both in Archtectural & Refacatoring pattern books) are mediocre & outdated.

Here are the few steps I suggest to learn patterns;
1. Buy this book, best book to learn & remember patterns
http://www.oreilly.com/catalog/hfdesignpat/
2. Go through the popular open source framework code (Hibernate, Spring etc...) . Most of the class name start with pattern names & it is very grasp their usability that way very easily
3. Don't ever force yourself to use patterns in your code/application. It is very important that it should come naturally & read the related anti-patterns before using it.

Remember real stregnth of patterns is when it is used as design communication tool & hence it has to be correct, precise & contexually relevent.
Bookmark and Share