AJAX made simple

November 29, 2007

As a software developer and a beginner to , I can certainly say that the acronym “Asynchronous JavaScript And XML” is not very helpful in understanding how this incredible technology revolutionized the way information is accessed and made Web 2.0 development possible. To put it simply, AJAX is a method of accessing information on a server and displaying it without interrupting the user’s work on the web page. The traditional paradigm for web information access relied on navigation from page to page, with each page remaining a static representation of content. AJAX allows users to request additional information to be displayed on the web page without requiring a full refresh of the page. Today’s biggest web applications work exactly in this way. What gives these web pages the feel of desktop applications is that the archaic method of accessing information in a page by page manner has been done away with: there is no more pause and screen refresh in between user actions, the information is queried from the server and displayed asynchronously with respect to the work-flow of the web page. In this manner, AJAX web pages are much more usable and extend the functionality of static web pages by a long shot.

The main web design tool that makes AJAX work is JavaScript, a client-side scripting language that has been around since 1995. “Client-side” means that the programs written in JavaScript (or scripts) run on the user’s computer, affecting only the content displayed in the user’s browser. JavaScript has been traditionally used for accomplishing tasks such as displaying pop-up windows and validating form field input. AJAX utilizes the JavaScript XMLHTTPRequest object to make asynchronous requests to the server for additional information. When an XMLHTTPRequest is used in a script, the programmer must specify the server to which it will be sent, in addition to the query parameters and a callback function. A callback function is exactly what it sounds like: it is the function that is invoked when the server “calls back” or finishes processing the client’s request and sends back some data. After the server responds to the XMLHTTPRequest, the callback function is invoked and processes the data that the server returned. The callback function is also responsible for displaying the data to the user.

Hopefully the description above is not too complicated, even for a non-technical audience. The key point here is that this entire process does not require the browser to refresh the page or interrupt the user’s reading or work on the page. The information can be requested and displayed while the user continues to work. It is this dynamic page behavior that makes AJAX pages web applications.

To wrap this up, I’ll tell you about a classic example of AJAX usage that is very simple but remarkably powerful. is an extension of the Google search engine that displays a drop-down list of search “suggestions” and their corresponding numbers of search results as the user types in the text input field. These suggestions appear based on what the user has typed so far and a database of previous searches on Google. At any time the user can simply click on a suggestion and view its list of search results. To try out Google Suggest, click here. The suggestions are generated and displayed in the drop down list asynchronously via AJAX, without requiring a page refresh. This is just a small example of how basic AJAX functionality can transform a commonly used internet tool into a full-fledged web application.


Computational Decentralization

November 21, 2007

The concept of distributed computing has gained enormous popularity in recent years with mind-blowing applications such as Folding and NVIDIA CUDA. Folding is a project managed by Stanford that conducts research on protein folding by utilizing the computational power of personal computers around the world, if the owners are willing to participate, of course. The NVIDIA graphics card company recently developed an API for utilizing the massively parallel computational power of GPUs (a requirement for their general purpose as graphics processors) as a mere extension of the C language. Before CUDA, the only way to access the power of GPUs was through complicated graphics libraries such as DirectX and OpenGL.

Anyway, it may seem from first glance at several examples that distributed computing is indeed practical but extremely complex. In the book Turtles, Termites, and Traffic Jams, Michael Resnick explores how people think about distributed computing or “decentralized systems”. The main idea is that unexpected, complex emergent behaviors can take shape amongst a massive group of individuals, with each acting under a very simple and restricted set of rules for operating. For example, the first case presented in the book (a biologically inspired one) is the clustering of slime mold cells. The rules for each cell are very simple: the cell must move around aimlessly until it encounters a cloud of pheromone, and then it must follow the gradient of the pheromone to where its scent is strongest (with a bit of random motion added in, for a good reason to be explained soon). At the same time, each cell must continuously deposit a configurable amount of pheromone on the ground. The pheromone also slowly evaporates at a configurable rate. The emergent behavior of this scenario is such that the slime mold cells end up aggregating into clusters: each cell is following all the others by means of the pheromone trails. However, one gigantic cluster does not form; instead, multiple clusters form due to that random motion that was used to somewhat degrade the cells’ ability to follow the pheromone scent. In this manner, interesting patterns begin to emerge, governing how clusters form and break apart.

Resnick’s book contains many other examples of decentralized systems, such as ants foraging, termites building, traffic jams forming, and ecology. Some of the system wide behaviors (those of the cluster, colony, or population) that emerge from the simple individual rules are completely unexpected and a challenge to comprehend. I highly recommend this book: its main focus is on escaping the common “centralized mindset” that we are born with. The goal is to be able to think on the ant level and the colony level, and realize that the interactions of many individual parts may be contributing to the overall behavior of a seemingly “singular” whole that we witness. Decentralization is the future of the internet – microformatted data makes it possible for content to be published in many locations and for services to utilize this content in a decentralized fashion (but that’s a topic for another post). Natura in minima maxima.


Initialization

November 18, 2007

Hi! Welcome to dbencoded! My goal for this blog is to provide concise and understandable updates about the latest topics and news in various areas of software development, including web 2.0 development, AJAX, Java, functional programming, and more advanced topics such as evolutionary computation and parallel processing. I’m hoping to post a couple times a week about code I write and things I learn here and there about those topics. Thanks a lot for reading. Feel free to leave comments adding information, asking questions, or making corrections if need be. This blog can be viewed as an RSS feed at the following URL: http://dbencoded.wordpress.com/feed.


Follow

Get every new post delivered to your Inbox.