Thursday, September 25, 2008

Life without Apache : Meritocracy in Action.

I am obsessed with Apache. Yes! I am and I am proud that I am!

I was just wondering how life would be WITHOUT Apache!

  • We would still be doing ASP. Many of us would have gone into ASPX and C#

  • CGI and PHP wouldn't have come out..

  • Total no. of websites in the world would be less. I don't know how much % but yes, it would surely be less.

  • There would all be Windows Hosting Services everywhere and the prices would be higher and higher...

  • Who can forget the popular Tomcat. Java wasn't open source before, other app servers were not that comfortable interms of price, simplicity and ease of use. Every newbie in JSP/Servlet starts with Tomcat. People crib that Tomcat doesn't have EJB, who needs EJB these days?

  • No Java projects would compile using Make, so Ant came it. Imagine how difficult life would be without ANT scripts.

  • MVC the most popular design pattern: Struts is the name you think of. If it weren't there, you'd still be writing your own servlets and JSP and controller logic.

  • Almost 80-90% of GOOD Java EE developers would use Apache Commons. I mean who doesn't use it?

  • Logging your application for debug and support, What would you do without Apache Logging Sevices

  • Forget all programming, there is still no comparision with Xerces for XML. I challenge.

  • Make your code as Webservice? No words about Axis, yet again apache product!

  • You want a middleware java messaging framework for your JMS? Use ActiveMQ

  • Object relation model: Try iBatis, you wont leave it again.

All in all, If there was no Apache, Life wouldn't have stopped but would have been SO SO damn difficult. My many many thanks to Apache...

Some Javascript Tips

I have been doing a lot of JavaScript these days. Each day I learn newer things and each day I am starting to like it more and more.

I am going to compile a few queries where I broke my head.

Q) If I do'anotherPage.html'), How can I change the DOM of the parent window.
This problem arrived when I was trying to add more rows to a table from another window itself.
Problem: Firefox allows it. But IE doesn't allow.
Solution: Use cloneNode() for FF. For IE , create the row again by attachRow()
Now for each cell, loop through it and do insertCells() and then copy the innerHTML to it.
All this is done in a simple loop through the table.

Q I have 3 frames on a page, I want to submit requests to page 2 and 3 at the same time
Do: document.forms[2].functionName();
yes, its as easy as this...
in your functionName(), you can add code to submit the form.submit();

Q Recursive Ajax calls.
Problem: To keep refreshing content of a page through Ajax.
One might typically use setInterval() but what if setInterval fires while a request from your ajax is coming back?
Solution: Use a global variable called "lock". Everytime you make a request set this lock, the call back function should release the lock.
When setInterval fires your ajax request function it should exit if its locked.

Q. getElementById('idname'). Don't use it too often, Try to traverse though the DOM by your code.

Q. Always give IDs to your form. Someday you'll find that this is very useful. You can submit a form from anywhere if you do this by getting the refrence of the form and then yourform.submit()

Q. Try to avoid excess IDs, This will occupy more browser memory interms of DOM parsing.
For example, If you have a table, don't give ID to each row. instead give the id to the table and then traverse the table.

Q. Do overuse Ajax and submit multiple requests simultaneously. Browser might allow this, but your database will not. Specially when you're doing connection pooling. In connection pooling , you have the same connection object and multiple execution of sql queries on the same object from different clients will result in failed transactions.

Q. attaching events is a good idea , but beware, IE and FF behaves differently. The API is completely different.

Q. Always use a common Javascript Browser detection Module. Make the detected browser global and then customize your scripts that way.

Q. Often while debugging we use alert("debug msg here.."); and waste time in commenting and uncommenting it. Instead use a global variable called "debug=true". And use if (debug) alert("");
You wont have to comment or uncomment it all the time.

Q. There are some good Javascript debuggers. Use them. The simplest one is FF error console. But what about IE? Yes, now you can use FF error console to debug IE related Errors too.. Install the FF IE tab plugin and have fun.

Q. Another great FF extension is Firebug. MUST MUST have for all you JS guys....

Saturday, September 13, 2008

PHP Camp 2008

Barcamp, BlogCamp.... and now Introducing PHPCamp

I am attending PHP Camp on 20th Sept 2008. I will be presenting on

PHP Vs Java:But I love them both...