Thursday, August 28th, 2008
Category: Articles
, Editorial
, Standards
I met with a colleague recently who wants to take his project and create a standard on the web that actually gets adopted. We talked for a long time, and when we finished up I pointed him at a paper that had a huge impact on me, called “In Praise of Evolvable Systems” by Clay Shirky.
This paper was written a long time ago in the ancient year of 1996 by the web’s timeline, but everything in it still holds on why the web won and some possibilities of how we can move forward from where we are today. Under the tagline for his paper Clay has the summary “Why something as poorly designed as the Web became The Next Big Thing, and what that means for the future.”
Clay starts by pointing out how bad the Web is:
If it were April Fool’s Day, the Net’s only official holiday, and you wanted to design a ‘Novelty Protocol’ to slip by the Internet Engineering Task Force as a joke, it might look something like the Web:
The server would use neither a persistent connection nor a store-and-forward model, thus giving it all the worst features of both telnet and e-mail. The server’s primary method of extensibility would require spawning external processes, thus ensuring both security risks and unpredictable load. The server would have no built-in mechanism for gracefully apportioning resources, refusing or delaying heavy traffic, or load-balancing. It would, however, be relatively easy to crash. Multiple files traveling together from one server to one client would each incur the entire overhead of a new session call. The hypertext model would ignore all serious theoretical work on hypertext to date. In particular, all hypertext links would be one-directional, thus making it impossible to move or delete a piece of data without ensuring that some unknown number of pointers around the world would silently fail. The tag set would be absurdly polluted and user-extensible with no central coordination and no consistency in implementation. As a bonus, many elements would perform conflicting functions as logical and visual layout elements.
HTTP and HTML are the Whoopee Cushion and Joy Buzzer of Internet protocols, only comprehensible as elaborate practical jokes. For anyone who has tried to accomplish anything serious on the Web, it’s pretty obvious that of the various implementations of a worldwide hypertext protocol, we have the worst one possible.
Except, of course, for all the others.
The web, however, was better than the contenders of that time. He argues that all the other formats, such as Gopher, Interactive TV, and so on were too well designed and had too much internal consistency:
These various [non-web] protocols and services [Gopher, Interactive TV, AOL, etc.] shared two important characteristics: Each was pursuing a design that was internally cohesive, and each operated in a kind of hermetically sealed environment where it interacted not at all with its neighbors. These characteristics are really flip sides of the same coin — the strong internal cohesion of their design contributed directly to their lack of interoperability. CompuServe and AOL, two of the top online services, couldn’t even share resources with one another, much less somehow interoperate with interactive TV or CD-ROMs…In other words, every contender for becoming an “industry standard” for handling information was too strong and too well-designed to succeed outside its own narrow confines. So how did the Web manage to damage and, in some cases, destroy those contenders for the title of The Next Big Thing? Weakness, coupled with an ability to improve exponentially.
Clay then goes on to argue that successful systems must be evolvable and gives three rules:
Evolvable systems — those that proceed not under the sole direction of one centralized design authority but by being adapted and extended in a thousand small ways in a thousand places at once — have three main characteristics that are germane to their eventual victories over strong, centrally designed protocols.
Only solutions that produce partial results when partially implemented can succeed. The network is littered with ideas that would have worked had everybody adopted them. Evolvable systems begin partially working right away and then grow, rather than needing to be perfected and frozen. Think VMS vs. Unix, cc:Mail vs. RFC-822, Token Ring vs. Ethernet. What is, is wrong. Because evolvable systems have always been adapted to earlier conditions and are always being further adapted to present conditions, they are always behind the times. No evolving protocol is ever perfectly in sync with the challenges it faces. Finally, Orgel’s Rule, named for the evolutionary biologist Leslie Orgel — “Evolution is cleverer than you are”. As with the list of the Web’s obvious deficiencies above, it is easy to point out what is wrong with any evolvable system at any point in its life. No one seeing Lotus Notes and the NCSA server side-by-side in 1994 could doubt that Lotus had the superior technology; ditto ActiveX vs. Java or Marimba vs. HTTP. However, the ability to understand what is missing at any given moment does not mean that one person or a small central group can design a better system in the long haul.
I know we sometimes get frustrated with the state of the web today, but its useful to know why we are here, and what characteristics any new ideas, features, or standards probably need to have in order to be successful; Clay’s paper helps guide me in terms of navigating these issues.
Thursday, July 17th, 2008
Category: Articles

Jeffrey Barke has written up a tutorial detailing how to create a density map with Prototype, the Google Maps API and the HeatMapAPI.
The heat map API looks cool indeed, and that piece of code looks simple:
JAVASCRIPT:
addHeatMap: function() {
var heatMap = new GEOHeatmap();
heatMap.Init(this.width, this.height);
heatMap.SetData(this.data);
var preUrl = heatMap.GetURL();
var heatmapOverlay = new HMGoogleOverlay(preUrl);
this.map.addOverlay(heatmapOverlay);
}
Monday, April 14th, 2008
Category: Aptana
, Articles
, JavaScript
, Server
Davey Waterson of the Aptana Jaxer team has posted an article on using jQuery on the server-side with E4X and more that shows an example of server-side Ajax with a popular framework.
The article describes a polling application that features:
Using jQuery server-side to manipulate a DOM before it's sent to the client Doing some database / SQL interactions, server-side in javascript of course User sessions in javascript (Jaxer.session.set('status', status);) Using E4X on the server-side.
There are fun little features such as nuking portions of the page if the permissions call for it:
JAVASCRIPT:
$((status == 'voter') ? '.nonvoter' : '.voter').remove();
Since the application delivers no JavaScript itself, this would all work even if the user has JavaScript turned off, on a simple mobile phone, etc.
Friday, March 28th, 2008
Category: Articles
, JavaScript
JAVASCRIPT:
TheRulesAre(function() { with(this) {
a(Player).mayNot('buyProperty').unless(function(player, property) {
return property.owner === null &&
player.funds>= property.price;
});
a(Property).mayNot('addHouse').when(it().isMortgaged());
}});
Composing DSLs in JavaScript is James Coglan's latest perusal into fun with JavaScript and DSLs.
He walks through the building of this DSL in a step by step manner. He uses his JS.Class library, but you could of course substitute your favourite JavaScript library.
Tuesday, March 25th, 2008
Category: Articles
, JavaScript
Because JavaScript is the language of the web browser, and because the web browser has become the dominant application delivery system, and because JavaScript isn't too bad, JavaScript has become the World's Most Popular Programming Language. Its popularity is growing. It is now being embedded in other applications and contexts. JavaScript has become important.
Douglas Crockford got to act all curmudgeonly as he talks on how The World's Most Popular Programming Language Has Fashion and Luck to Thank.
He starts out talking about the black art of languages:
The art in language design is knowing what to leave out. The features of a good language work together harmoniously. A good language helps us to better understand a problem and to find the best expression of its solution.
A good language is composed of a limited set of features. But there is little agreement on which features are best. Programmers can argue endlessly about features and whether a set of features makes one language better than another. Features matter, but we just don't understand yet how they matter.
Language design has more to do with fashion than technology. It may seem strange that fashion is a major factor in the nerdliest of arts, but it is true. A language with radically different syntax, for example, has no hope of finding broad adoption, regardless of the brilliance of its design. This tends to constrain the rate at which languages evolve.
Just like fashion, a programming language is often a product of its time. The deep problem in language design is not technological, it is psychological. A programming language should equip us with structures that help us to reason more effectively.
And then he gets to JavaScript itself, and how it has managed to become the most deployed language in history even with its foibles.
Thursday, March 13th, 2008
Category: Articles
, Dojo
, JavaScript

Neil Roberts has posted a great article on Creating Your Own $ with Dojo:
The bling, one of the best global variables in JavaScript. A tool which has come to mean, as a function, a way to locate a node or set of nodes. And, as a namespace, a simple way to access often-used functionality. "This can't be done with Dojo," you insist. But you're wrong, it's really easy. The ideas behind this little symbol are quite simple and I'm going to show you how to create your own customized version of it.
He manages to walk us through a path where he gets $ working in a way that mimics jQuery. He starts with $ = dojo.query; and ends up with:
JAVASCRIPT:
$ = dojo.mixin(function(){ return dojo.mixin(dojo.query.apply(this, arguments), $.fn); }, dojo, { fn: {} });
He then tackles plugins and using:
JAVASCRIPT:
$.fn.click = function(callback){
dojo.forEach(this, function(node){
dojo.connect(node, "onclick", function(e){
callback.call(e.target, e);
});
});
}
You end up being able to do:
JAVASCRIPT:
$("li.expandable").click(function(e){
$(this).toggleClass("expanded");
});
Very cool indeed!
Tuesday, February 26th, 2008
Category: Articles
, Canvas
, JavaScript
, Prototype
![[image]](http://mowser.com/img?url=http%3A%2F%2Fsnipersystems.co.nz%2Fcommunity%2Fpolarclock%2Fclock.png)
"agrath" has developed a very nice Canvas example using Prototype that makes use of a common Prototype-isms: Object.extend, Class.create, bind, enumerables, $w, $.
The Polar Clock is a different visualization of time and the example walks through all of the work required to implement it using Prototype 1.6.0.2 and Canvas, including the draw method:
JAVASCRIPT:
draw:function(){
this.clearCanvas();
var w = 20;
var r = 260;
this.date = new Date();
var cr = r;
$('labels').update()
$w("month day weekday space hour min second").reverse().each(function(interval){
cr = cr - w - w/2;
if(interval != 'space')
{
var ir = this.intervalToDegrees[interval].bind(this.date)();
var i = ((ir / 360) * 255) + 147;
var color = this.cc.rgbToCss(this.cc.hslToRgb(i.wrap(0,255),205,127));
this.drawSolidArc(color, cr, w, ir.toRadians());
$('labels').insert(this.getIntervalLabel[interval].bind(this.date)() + '<br />');
}
}.bind(this));
},
The article walks through a lot of Canvas as well as the Prototype side of things. Very thorough.
Thursday, February 21st, 2008
Category: Articles
, JavaScript
Peter Michaux has done some very thorough work on feature detection in the browser and cross browser widgets.
In his feature detection article he walks through a myriad of approaches with pros and cons:
Feature testing is not easy and there is no one right answer. From a practical stand point, the more strict your tests are the more likely your code runs only when it will run successfully.
There are some obvious wrong answers like navigator.UserAgent inference, unrelated execution inference and unrelated object inference. Check the library you are using. Does it use any of these techniques? I have seen many uses of these techniques in mainstream libraries even where there is a well known, better test available. The mainstream libraries cannot consider claiming to be state of the art until they remove these bad practices at the very least.
The above discussion focuses on tests against a single object to infer if that object or similar ones work. Sometimes it may be necessary to use multiple objects together to make an inference about one object. An example for scroll reporting. Even when using multiple host objects in a test the three isHost* functions will be useful.
Feature detection is not easy, but as professionals, we should use the best tests we can.
In his cross browser widget article he goes further to create a library to handle cross browser widgets:
Build a robust widget for the general web is hard work and the example above has room for improvement. The level of feature testing could be increased at the cost of file size. For example, on comp.lang.javascript, David Mark suggested that the browser could run out of resources and a call to createElement could return null. He also admitted this may be overly paranoid. I think it is and by testing for the existance of document.createElement I've inferred that calls to it will work as expected.
I've tried the tabbed pane in all the browsers I have and it is either enabled an works or it is disabled and doesn't throw errors. I suspect there is a browser out there somewhere that will throw an error. That is just the nature of the cross-browser challenge. In a perverse masochistic way, I somewhat hope someone can find a browser in which this widget breaks. That is one way we can continue to improve.
Tuesday, February 19th, 2008
Category: Articles
, IE
Two articles were shot onto A List Apart this morning. We have Jeffrey Zeldman on the threat or menace of version targeting. Then we have Jeremy Keith on browser shooting.
Both are opinions on the version targeting issue that has blown up on the Web recently.
Jeremy concludes:
Version targeting is not a bad idea. The choice of delivery mechanismsâ€â€meta element or server headerâ€â€is inspired. As an optional feature, this could prove to be a real lifesaver in some development environments. As a mandatory millstone however, it strikes a blow against progressive enhancement.
The proposed default behavior for version targeting in Internet Explorer solves the problem of “breaking the web†in much the same way that decapitation solves the problem of headaches. In its current state, version targeting is a cure that will kill the patient. Version targeting could have been an opportunity for Microsoft to demonstrate innovation. Instead, the proposed default behavior demonstrates a fundamental misunderstanding of the World Wide Web, a place that according to its creator, Sir Tim Berners-Lee, will always be “a little bit broken.â€Â
Jeffrey concludes:
Version targeting is a mind-bender. It shakes our browser-agnostic faith. Its default behavior, although beneficial to skilled and unskilled developers alike, runs counter to our expectations, and seems wrong. And it presents at least one Sphinxian riddle: namely, how can IE8 pass Acid 2 if IE8 behaves as IE7 by default? You can spend weeks on that one and not come up with a logical answer. Call me Lewis Carroll, but I’m okay with it.
He talks about how JavaScript already is opt-in:
And actually, Mozilla has offered opt-in version targeting, first when Firefox 1.5 introduced support for JavaScript 1.6, and later, when Firefox 2.0 did the same for JavaScript 1.7. In both cases, you had to explicitly opt in. The comparison is Mozilla’s favor, for they targeted scripting language versions, not browser versions. But although Mozilla did it more cleanly, both browser makers offered targeting, and for the same reason: to protect developers from unintended behavior as their browsers’ scripting support improved.
Non-standardistas have been writing JScript for years. While the CSS changes in IE7 may have “broken†a site’s layout, IE8’s JavaScript improvements could easily render a site useless. Real DOM support is a game changer. Enabled by default, it would bring many sites to their knees. That would break the web, and not in quotes. Providing IE8’s greater compliance on an opt-in basis is the only way to get everyone over the scripting hump.
But while the opt-in protects old-fashioned coders from a major change in the scripting environment, it also offers unique benefits to even the most die-hard standardista.
The opinions keep on coming!
Tuesday, January 29th, 2008
Category: Articles
![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.cio.com%2Fimages%2Fglobal%2Fnav%2Fprint_hdr.gif)
Michael Morrison, author of Head First JavaScript, has written a piece for CIO magazine titled You Used JavaScript to Write WHAT? which is part of a series of articles on when to use a particular language or platform.
It is always interesting to see what the CXO folks are reading wrt our beloved Web :)
The other side of the coin is the mentality of viewing a Web application as a program, as opposed to a page. In this scenario, the application is utterly dependent on the active functionality made possible by JavaScript, which means it's okay to forego users who lack JavaScript support. Google has embraced this philosophy in several marquee products, two of which are extremely popular: Gmail and Google Maps. Both applications make extensive use of Ajax (JavaScript), and neither apologizes to users who can't run them due to a lack of JavaScript. If this article had been written just a few short years ago, I might have used an e-mail application as the ridiculous example of when not to use JavaScript, instead of Halo. But Gmail has pushed through that barrier.
Even if JavaScript-powered, web-based e-mail ultimately takes hold, surely there are other stand-alone applications that will just never make sense in Web form. Two such applications that come to mind are video and photo editing. Similar to games, these are such media-intensive applications that they just can't make sense in JavaScript, right? Yet Adobe has already released Premiere Express for online video editing and is putting the finishing touches on Photoshop Express for Web-based photo editing. What's interesting about these applications is that they aren't technically built in JavaScript; they're built in ActionScript, a close cousin of JavaScript used in Adobe's Flex development environment. But the ActionScript in these applications is compiled, so the net effect is more akin to a native application. Adobe may be foreshadowing the future of Web scripting to some degree, at least in terms of building more feature-rich applications. And in doing so, they're forcing us to rethink just what is possible with scripting languages.
Monday, January 28th, 2008
Category: Ajax
, Articles
Coach Wei, of Nexaweb and Apache, has published a study of Ajax performance issues in browsers, and they won't surprise you:
Obviously, we would like to see browser vendors take a serious look into the following issues and put them on their roadmap:
In all major browsers, performance with Array and HTML DOM needs improvement in general. Browsers need to provide API support for Computed Box Model and Style; FireFox needs to improve performance of “evalâ€Â, object creation and “in†operation Internet Explorer needs to improve performance in general to be at least on par with other browsers. Beyond that, “String†manipulation on IE needs continued improvements; Safari: “pop†operation performance needs improvement Just-in-time (JIT) compiler: This maybe a bigger task than an incremental fix of some existing features, however, it is worthy of every penny. JIT will not only fix the String manipulation issue, it will enable JavaScript to truly shine in matching the performance of native applications. The amount of client side logic (aka, JavaScript code) needs to grow in order to accommodate the growth of application complexity, for which JavaScript runtime performance problem can be a major bottleneck.
Read the study to get the details on each item. It includes the results such as the DOM operation performance information:

Thursday, January 24th, 2008
Category: Articles
, Games
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi2.sitepoint.com%2Fgraphics%2Fmaze_finished-dungeon.thumb.png)
James Edwards has written a very detailed tutorial on using dhtml to create a game which is part of his book:
In this chapter, we took the languages of CSS and JavaScript well beyond the tasks for which they were intended?the presentation and basic behavior of HTML documents -- and used them to create an interactive 3D maze.
First, we looked at the basic principles by which triangles can be displayed using only CSS. We then extended that concept to render a perspective view, creating the illusion of three dimensions. Next, we established a convention for specifying floor plan data, and for dynamically translating that data into a perspective view. By adding listeners for user events, we successfully created an interactive maze that can be completely customized and extended. To top things off, we added some usability aids, such as a top-down map, and accessibility aids including keyboard navigation and captions.
While I haven't delved into the details of every method that comprises the game script (there are plenty of comments, so I'll leave that for you to pursue in your own time), I hope this chapter has convinced you to look at JavaScript in a new light. The possibilities really are only limited by your imagination!
Wowser :)
Friday, January 4th, 2008
Category: Articles
, Testing
Dr Nic has written a tutorial on testing JavaScript in Rails using a new javascript_test plugin.
Once you ruby script/plugin install javascript_test you can ruby script/generate javascript_test maths. Then you can write a test a la:
JAVASCRIPT:
testTruth: function() { with(this) {
assert(true);
}}
You can go further though with the autotest watching over files, and Nic shows some TDD in action.
![[image]](http://mowser.com/img?url=http%3A%2F%2Fdrnicwilliams.com%2Fwp-content%2Fuploads%2F2008%2F01%2Fjavascript-testing-intro.jpg)
Wednesday, January 2nd, 2008
Category: Articles
, JavaScript
Colin Morris, author of Y-Validator, has written a piece on JavaScript: It's Just Not Validation! which discusses JavaScript validation, and "input assistance":
JavaScript input assistance, when built separately from back-end validation, is not ideal. At worst, the two piece of functionality work differently, and what's valid on the client side isn't valid at the server. At best they work fine -- initially. But with validation logic in multiple locations, there's an increasing likelihood that only one will get updated when changes are required, at which point we get inconsistent results.
Finally, back-end validation is required. JavaScript assistance is nice.
The use of a central object to manage both the validation and input assistance tasks creates a consistent end user experience even with JavaScript disabled.
We have one place to update both the enhancement (JavaScript assistance) and the required functionality (back-end validation). Therefore, the two can't get out of step, and we can ensure a seamless experience for the user. We have one place to find the enhancement, so it's less confusing for future maintainers of our code to located the points at which various validations and assistances are implemented in the code. The code also promotes the separation of behaviour from presentation. The programmer programs the validation and the designer implements the presentation of the feedback. The user feels in more control, having confidence in hitting the big submit button.
Don't forget: the code for the PHP-Validate and a sample form is available for download.
Thursday, December 27th, 2007
Category: Articles
, Comet
Arena Albionu has written about Django and Comet using the Orbited Python event driven comet server.
The article walks through the hello world of Comet... a chat server. The JavaScript looks like this:
JAVASCRIPT:
function processGetPost()
{
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4)
{ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1)
{ //if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}
function connect()
{
var nick = document.getElementById('nickname').value;
Orbited.connect(chat_event, nick, "/chat", "0");
ajaxpack.getAjaxRequest("/join/" + nick + "/", "", processGetPost, "txt");
}
chat_event = function(data) {
var chat_box = document.getElementById('box');
var div = window.parent.document.createElement('div');
div.className = "event";
div.innerHTML = data;
chat_box.appendChild(div);
chat_box.scrollTop = chat_box.scrollHeight;
}
function send_msg() {
var msg = document.getElementById('chat').value;
var nick = document.getElementById('nickname').value;
ajaxpack.getAjaxRequest("/send/" + nick + "/" + msg + "/", "", processGetPost, "txt");
}
Wednesday, December 19th, 2007
Category: Articles
, Java
, JavaScript
Java and JavaScript share the first four letters of their name, and have an entangled past. Joe Walker has an interesting little take on the evolution of the languages that shows some mirror images such as:
It's interesting that the current simple version of JavaScript already has the features (i.e. closures) that people want to keep out of Java otherwise it will become too complex, and that Java already has some of the features (i.e. classical inheritance) that people want to keep out of JavaScript, otherwise it will become to complex.
And some thoughts on JS2:
With JavaScript, people see a neat, compact language and fear it turning into Java. The good news is that it won't fully turn into Java because JavaScript already has closures and no one thinks they should be taken out ;-) The danger of the "features over complexity" argument, is that it can be applied indiscriminately, creating a monster, and the fear is that JavaScript will become a monster.
I'm gradually coming round to the opinion that many of the changes proposed to JavaScript actually reduce complexity. There are nearly as many frameworks that add classical inheritance to JavaScript as there are Ajax frameworks. Having one solution that we can all agree on can't be a bad thing even if you prefer prototypal inheritance.
Next Page »