6 January 2006
EIBTI for Javascript: explicit is better than implicit
Javascript's "prototype" driven nature allows programmers to alter the behavior of built-in types thusly:

String.prototype.isEmpty = function() { return /^\s+$/.test(this); }

Just because you can, doesn't mean you should though.  For instance, a method you add to String's prototype might require two arguments, but a future update to the language itself might add the very same method with the arguments reversed.

Consider this alternative:

function FormValue(str) { this.str = str}
FormValue.prototype.isEmpty = function() { return /^\s+$/.test(this.str); }
var test = new FormValue(" ");

Note you must explicity instantiate a FormValue instance, rather than implicitly operating on a String (primitive).  Consider this a feature.  For instance, Python has popularized the acronym EIBTI, or "explicit is better than implicit."  No wonder MochiKit, "a production-quality framework that brings powerful and well-known Python idioms to JavaScript," rightfully leaves String.prototype alone.
Posted by htmatters at 11:55 AM | Comments (2)
9 September 2005
Javascript Meets Ruby
Javascript meets Ruby, in the context of Kiko, a new online calendar application.  Specifically, Kiko has implemented a Javascript port of Ruby on Rails' "ActiveRecord" subproject, for implementing the "model" facet of an MVC (model-view-controller) application.  If record/model have you thinking data/database you'd be correct, and if you're thinking AJAX so Javascript can talk to the backend, you'd be correct again; see http://www.kiko.com/jsactiverecord/ for an abstract/tutorial and source code, a snippet of which is:
var me = types.user.create({email:"", password:"pass"});
Note, that is not XML being passed but rather a Javascript "object literal", or JSON.  No wonder Kiko, though barely a month old and still in beta, is being held up as a shining showcase for cutting edge Javascript technology.
Posted by htmatters at 6:36 PM | Comments (0)
Java Objects ColdFusion Views
The August 2005 issue of a prominent ColdFusion magazine wastes several pages on OO with ColdFusion.  Let's face it, CFC's are about as object oriented as PHP4: neither are enterprise-ready.  For one, they both lack the "Interface" construct, an absolute must for genuinely robust object oriented architectures.  There are other shortcomings as well, but interfaces provide an acid test as to developers' understanding of objects: if you don't grok interfaces, you shouldn't be leading an enterprise OO project.  All is not lost for ColdFusion however, it's advantage over PHP4 being it's foundation: Java.  Let Java do the OO "heavy lifting", and then leverage the servlet API's getServletContext().getRequestDispatcher() functionality to subsequently forward both request and response to ColdFusion templates.  OO with ColdFusion itself is not necessary to its continued thriving, rather it can provide the view component of MVC under Java.
Posted by htmatters at 6:54 AM | Comments (0)
11 August 2005
ColdFusionMX7 Servlet Development
How to start developing servlets under ColdFusionMX7 (in 150 words or less ;)
Posted by htmatters at 7:40 AM | Comments (0)
19 July 2005
eval'ing JSON
JSON's unfortunate reliance on Javascript's eval() method calls for a new standard: JSON++
Posted by htmatters at 7:12 AM | Comments (2)
19 June 2005
AJAX' Achilles Heel
maps.google.com with Javascript disabled
AJAX -- "Asynchronous Javascript and XML" -- is certainly getting a lot of attention lately.  Too bad it, and the so-called XmlHttpRequest upon which it relies, are misnamed: XML is not necessarily required.  Of much greater consequence, however, is that AJAX applications may not work if the user disables Javascript.

Try it yourself: disable Javascript in your browser, then visit maps.google.com, which arguably started the AJAX buzz.  You will receive the message that "JavaScript must be enabled in order for you to use Google Maps".

Enablement of Javascript is outside of the control of the developer and cannot be relied upon, except perhaps for a private intranet application.   For a public website however you should consider alternative strategies alongside of, or instead of, AJAX.  We will consider such a strategy next month.
Addendum, Dec 2005: The image below is a screenshot, dated Aug 2005, of visiting maps.google.com with Javascript disabled. Now instead they provide verbiage ("Your web browser is not fully supported by Google Local.") followed by this unhelpful link

Posted by htmatters at 6:27 AM | Comments (39)
Open Source ColdFusion
To augment your choice of free ColdFusion components, look no further  than  cfopen.org.  It describes itself as a "a collaborative software  development  environment designed to facilitate the development of open source  software  for ColdFusion."  Here you will find not just components, but even  full-fledged frameworks (not unlike FuseBox) that can provide the  foundation  for an entire site.  More and more of these ColdFusion projects are  supporting freely available databases as well, e.g. MySQL.  Besides  downloading existing software, you can establish your own project, or  apply  to join an existing one, for instance if you want to contribute some  customizations you've made.  And don't forget to google "ColdFusion  Open  Source" while you're at it.  This will return results ranging from  custom  tags all the way to content management systems.
Posted by htmatters at 5:28 AM | Comments (0)
22 May 2005
Grokking the Virtual Machine
This month we consider Javascript's syntactic cousin, Lua:  

a = {}
a["b"] = "c"  

This code is valid in both Lua and Javascript; the first line creates a Javascript "associative array", or in Lua, a "table".  In both languages these constructs serve as "objects", so both of the following are valid statements for retrieving the "b" property of "a":  


Other similarities include that functions are first-class values in both languages: they can be stored in variables, passed as arguments, and returned as results.  Furthermore, both languages support "lexical closures", which allow "data hiding" (see last month's column).  

Lua may well be the lowest-level of the C-based scripting languages: it is a "register-based" virtual machine, and has some hooks directly into C.  Lua originated in Brazil but, designed especially for embedding, is popular worldwide, particularly with game programmers.  Look into Lua, and become a better Javascript programmer!
Posted by htmatters at 3:56 PM | Comments (0)
Blue Dragon Redux & CFEclipse
First some corrections to last month's column regarding NewAtlanta's free  ColdFusion implementation, "BlueDragon", specifically the Linux version.  As of version 6.2, distributions more current than RedHat 9, including Fedora  Core 1/2/3, are indeed supported.  Furthermore, configuration issues,  particularly integrating BlueDragon with Apache, can be overcome through a  thorough reading of the installation guide. 

Since BlueDragon comes in a free version, let's consider another free tool  for ColdFusion, the Eclipse plugin "cfeclipse".   Eclipse is now the de  facto Java IDE (60% now use it, according to onjava.com's 2004 survey), and  is becoming more popular for other languages because of it's plug-in  architecture.  CFEclipse does not provide WYSIWYG editing, but if you also  develop in Java, perhaps even custom ColdFusion tags, then Eclipse with  CFEclipse really makes sense.
All the software you will need to get up and running with CFEclipse is  available at the following sites:

Posted by htmatters at 3:00 PM | Comments (3)
22 April 2005
Blue Dragon Server
If you are looking for a FREE ColdFusion engine that, unlike ColdFusion Express, continues to be actively developed, look no further than New Atlanta Communication's "Blue Dragon Server" (http://www.newatlanta.com/products/bluedragon/index.cfm). Your best bet is to install version 6.2 alongside IIS on Windows XP Pro or Windows Server 2003, enabling ColdFusion on the default port 80, as well as its own port, 8080.  

Linux however is more problematic. New Atlanta 's documentation recommends RedHat 9 for free BlueDragon, but RedHat no longer supports that distribution. The good news is that it will install on Fedora Core 3, though in my experience with this configuration, it won't integrate with Apache. Regardless, you can develop and test your ColdFusion apps on port 8080, making BlueDragon definitely worth a try on either Windows or Linux.
Posted by htmatters at 3:49 PM | Comments (0)
Data Hiding with JavaScript
Did you know that JavaScript supports "data hiding" inside user defined objects? Consider the differences between how the two properties myVar1 and myVar2 are declared inside the following constructor function:  

function MyObject() {
  this.myVar1 = "public";
  var myVar2 = "private";  
  this.getMyVar2 = function() {      
    return myVar2;

myVar1 can be directly accessed because it was defined using "this", but myVar2 cannot because it was defined using "var"; myVar2 can only be accessed via a "method", e.g. the inner function "getMyVar2", as demonstrated below:  

var myObj = new MyObject();
alert(myObj.myVar1);        //returns "public"
alert(myObj.myVar2);        //returns "undefined"
alert(myObj.getMyVar2());   //returns "private"  

Think of "this" as the equivalent of the "public" access modifier in other object oriented languages, and "var" as the equivalent of "private". Read more about this technique at: http://devpapers.com/article/291
Posted by htmatters at 3:45 PM | Comments (0)