Friday, February 10, 2006

Google's Javascript Library

I often find myself reading the source code of other developers. Typically I am studying the code that I have inherited from a coworker or former coworker. But, I also enjoy analyzing code in my spare time, as a sort of hobby. Consequently, I find myself browsing the internet for articles with source code or dusting off one of the many titles on my bookshelf.

Recently I have spent some time looking at the JavaScript code Google has developed to power its AJAX based web services. In particular, I have been reviewing the source that is used to power the Personalized Home Page (source) and the Lens Reader (source) application. Maybe it’s just me, but I find it to be a fun challenge deciphering the obfuscated code to reveal the meaning behind each of the functions.

Today as I was examining the code in the reader application and came across the function that is used to return the DOM element with the ID that matches the value of the parameter that was passed into the function. This is a commonly used procedure in AJAX applications and I distinctly remember its implementation in the Personalized Home Page source. It stunned me to find two different implementations of the same function. With all of the JavaScript code that Google has developed, I would have thought by now they would have established a library that consisted of commonly used functions and could be included in all of the AJAX applications that Google develops. I have included the two variations below.

The reader implementation:
function h(a){
return document.getElementById(a)

The Personalized Home Page implementation:
function _gel(a){
return document.getElementById?document.getElementById(a):null

Which implementation is better is not my concern here, but rather the principle of code reuse and familiarity. While this is a very short function, there may be others which are substantially longer. Should the Google application developers each have to write there own implementation of functions or would it be better to create a library of standard JavaScript functions that are included in all of the AJAX applications? Further, if a Googler changes projects or is assigned to a new project, it would seem helpful to have a standard AJAX library to supplement the development of the application.

Get all of the MSN Conspiracy Game Answers here


Post a Comment

<< Home