Monday, October 20, 2008

Rediff.com Coding Standards: An Analysis

By Hussain Fakhruddin

hussulinux@gmail.com




Rediff has a lot of portals within its main portal.

This is how they organize their re-usable code.

The first thing I did is logged on to: http://indian-railways.rediff.com/


I opened my Fire Fox’s Error Console and found this:




The next thing I did was to open up the source code:

I was shocked. I could really figure out that this type of code was

1) Written by just “Jugard” of code from their own paces here and there!

2) Not at all reviewed!

3) Done in haste to meet the deadlines!


I will put some screenshots to prove my point:(Please enlarge them as needed)



  1. Are these written by the same programmer?

Subsequent lines of code, but one in caps and other in small.
- Seems like they have just copied it from some previous page.

  1. Dirty CSS to look good? : Reuse of CSS codes, but not at all arranged in a proper manner. They are probably using the code which is lying here and there.


  1. Code lying here and there + insert what is needed and get the things done!


  1. JavaScript in the middle of an external CSS.
    Why not place it together along with the code above!

  1. Just Wow: Internal JS > CSS > External JS > Internal JS
    CSS surrounded between JavaScript and JavaScript surrounded between CSS!

  1. Where are your code conventions Mr. Rediff?
    See the CSS classname ‘Naming standards’

  1. Rediff’s way of importing external JS!

They are using JavaScript to import another JavaScript code!
Look carefully!





  1. Debugging debris remains…



  1. Reuse the code, but not in the same page man!
    I saw this CSS defined AGAIN somewhere below the code!
  2. What a waste of memory!
    Everything commented inside the function, what does this function do then?!



  1. Agreed we all use broadband, but what a waste of Bandwidth?

Why so many wide spaces!

Don’t you guys know browser ignores them but bandwidth network doesn’t!


  1. Broken Link

Wanna report?

  1. Total time over 512KBPS
    No comments!

  1. 19 Requests to the server! Woah!
    Thank you that I have an advance browser to do these for me!

  1. So many DNS resolutions
    My ISP might think I am doing a DNS attack!



16. Best of all:
Around 8 MB of Memory occupied by just 41KB of HTML code!


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 window.open('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...

Tuesday, July 1, 2008

Practical DWR Guidelines

I have written a Paper on Practical DWR (Direct Web Remoting) Guidelines. You'll enjoy it if you're a J2EE guy who wants to do some Ajax.


Saturday, June 14, 2008

Hussu Linux: DWR : Direct Web Remoting

Hussu Linux: DWR : Direct Web Remoting

DWR : Direct Web Remoting

Direct Web Remoting or DWR is the future for Ajax and Java.
DWR is a tool which allows you to invoke a Java Method residing on your AppServer from the browser through JavaScript.

Here's a little introduction about it and a small tutorial which you can try out.
You will also find all the necessary ingredients' links as you move along.