<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
<title>Bitstructures</title>
<id>http://bitstructures.com/</id>
<link href="http://bitstructures.com/" />
<updated>2008-09-04T08:04:41-05:00</updated>
<author><name>Simon Bates</name></author>


<feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="bitstructures" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://bitstructures.com/atom.xml" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Fbitstructures.com%2Fatom.xml" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Fbitstructures.com%2Fatom.xml" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Fbitstructures.com%2Fatom.xml" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://bitstructures.com/atom.xml" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fbitstructures.com%2Fatom.xml" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Fbitstructures.com%2Fatom.xml" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Fbitstructures.com%2Fatom.xml" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><entry>
<title>Open Web Podcast</title>
<id>http://bitstructures.com/2008/09/openwebpodcast</id>
<link href="http://bitstructures.com/2008/09/openwebpodcast" />
<published>2008-09-04T08:04:41-05:00</published>
<updated>2008-09-04T08:04:41-05:00</updated>
<content type="html">
&lt;p&gt;Awesome: &lt;a href="http://openwebpodcast.com/"&gt;Open Web Podcast&lt;/a&gt;
&lt;/p&gt;

</content>
</entry>


<entry>
<title>ondemand.js</title>
<id>http://bitstructures.com/2008/07/ondemand-js</id>
<link href="http://bitstructures.com/2008/07/ondemand-js" />
<published>2008-07-06T18:06:42-05:00</published>
<updated>2008-07-06T18:06:42-05:00</updated>
<content type="html">
&lt;p&gt;This weekend I finished up some code that I'd started a little while ago but hadn't had the chance to complete: a function, that can be used in the progressive enhancement style, for showing and hiding parts of a web page &lt;a href="http://designinginterfaces.com/Extras_On_Demand"&gt;on demand&lt;/a&gt;.
&lt;/p&gt;
&lt;script type="text/javascript" src="http://static.bitstructures.com/js/dojo-1.1.1/dojo/dojo.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://static.bitstructures.com/js/ondemand.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
dojo.addOnLoad(function(){
ondemand("ondemand1", "Show Details", "Hide Details");
});
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
document.write('&lt;style type="text/css"&gt;#ondemand1 { display: none }&lt;/style&gt;');
&lt;/script&gt;


&lt;h3&gt;Example&lt;/h3&gt;
&lt;div id="ondemand1"&gt;
&lt;form id="form1" action="#"&gt;
&lt;p&gt;&lt;label for="tags"&gt;Tags:&lt;/label&gt;&lt;br&gt;
&lt;input id="tags" type="text"&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for="description"&gt;Description:&lt;/label&gt;&lt;br&gt;
&lt;textarea id="description" rows="5" cols="30"&gt;&lt;/textarea&gt;&lt;/p&gt;
&lt;p&gt;&lt;button type="submit"&gt;Save&lt;/button&gt;&lt;/p&gt;
&lt;/form&gt;
&lt;/div&gt;

&lt;p&gt;Source for example:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;dojo/dojo.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;ondemand.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
    dojo.addOnLoad(function(){
        ondemand(&amp;quot;ondemand1&amp;quot;, &amp;quot;Show Details&amp;quot;, &amp;quot;Hide Details&amp;quot;);
    });
&amp;lt;/script&amp;gt;

&amp;lt;div id=&amp;quot;ondemand1&amp;quot;&amp;gt;
&amp;lt;form id=&amp;quot;form1&amp;quot; action=&amp;quot;#&amp;quot;&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;label for=&amp;quot;tags&amp;quot;&amp;gt;Tags:&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;input id=&amp;quot;tags&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;label for=&amp;quot;description&amp;quot;&amp;gt;Description:&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;textarea id=&amp;quot;description&amp;quot; rows=&amp;quot;5&amp;quot; cols=&amp;quot;30&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;button type=&amp;quot;submit&amp;quot;&amp;gt;Save&amp;lt;/button&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Usage&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;ondemand(elem, showLabel, hideLabel)
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
 &lt;li&gt;
     elem: the element to make on demand (either an element object reference or an id)
 &lt;/li&gt;

 &lt;li&gt;
     showLabel: the label for the button to show the element
 &lt;/li&gt;

 &lt;li&gt;
     hideLabel: the label for the button to hide the element
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The function hides the specified element and inserts a button into the document to show and hide the element again. To use in a progressive enhancement style, include the part of the web page that you'd like to be shown and hidden on demand as static content, and then call the ondemand function on it. If JavaScript is turned off, the content will always be shown and there will be no button to hide or show the content.
&lt;/p&gt;

&lt;h3&gt;Source code&lt;/h3&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://trac.bitstructures.com/browser/collected/trunk/ondemand-js/ondemand.js"&gt;ondemand.js&lt;/a&gt;
 &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Progressive enhancement and flicker&lt;/h3&gt;
&lt;p&gt;Due to the page being reworked after loading you may see flicker as the content is initially shown and then quickly hidden. One approach for minimizing the flicker is to add a document.write statement that inserts a CSS rule to hide the content to be made on demand before it appears in the document. For example:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Content-Type: text/plain
document.write('&amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;#ondemand1 {
    display: none }&amp;lt;/style&amp;gt;');
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The document will still change after the page is loaded, as the button is inserted, but the change will be smaller than before and it will be additive rather than subtractive.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Firefox 3 released!</title>
<id>http://bitstructures.com/2008/06/firefox-3</id>
<link href="http://bitstructures.com/2008/06/firefox-3" />
<published>2008-06-17T19:46:41-05:00</published>
<updated>2008-06-17T19:46:41-05:00</updated>
<content type="html">
&lt;p&gt;Congratulations Mozilla! &lt;a href="http://www.spreadfirefox.com/en-US/worldrecord/"&gt;Firefox 3 is out today.&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;Some highlights, for me:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     faster performance
 &lt;/li&gt;

 &lt;li&gt;
     Mac OS X integration
 &lt;/li&gt;

 &lt;li&gt;
     the awesome &lt;a href="http://www.marcozehe.de/2008/02/29/what-on-earth-are-places/"&gt;Awesome bar and new Places database&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     goodbye modal remember password dialog, hello &lt;a href="http://www.byte.com/art/9608/sec4/art3.htm"&gt;modeless&lt;/a&gt; goodness
 &lt;/li&gt;

 &lt;li&gt;
     the new site information user interface makes it very easy to access security information for the site that you are currently using
 &lt;/li&gt;

 &lt;li&gt;
     and, of course, the updated &lt;a href="http://www.w3.org/TR/wai-aria/"&gt;ARIA&lt;/a&gt; implementation
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://beltzner.ca/mike/"&gt;Mike Beltzner&lt;/a&gt; has put together a nice &lt;a href="http://people.mozilla.com/~beltzner/overview-of-firefox3.swf"&gt;screencast introducing some of the new features&lt;/a&gt;, including the awesome bar, site information, malicious site block, and new features for the download window and add-ons dialog.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Installing Accerciser on Ubuntu 7.10</title>
<id>http://bitstructures.com/2008/03/installing-accerciser-ubuntu</id>
<link href="http://bitstructures.com/2008/03/installing-accerciser-ubuntu" />
<published>2008-03-01T15:06:20-06:00</published>
<updated>2008-03-01T15:06:20-06:00</updated>
<content type="html">
&lt;p&gt;I recently installed the awesome &lt;a href="http://live.gnome.org/Accerciser"&gt;Accerciser&lt;/a&gt; accessibility testing tool on my Ubuntu 7.10 virtual machine. I installed the trunk version from subversion and needed these packages:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     subversion
 &lt;/li&gt;

 &lt;li&gt;
     gnome-common
 &lt;/li&gt;

 &lt;li&gt;
     libglib2.0-dev
 &lt;/li&gt;

 &lt;li&gt;
     libgconf2-dev
 &lt;/li&gt;

 &lt;li&gt;
     ipython
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I checked out, built, and installed Accerciser with:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Content-Type: text/plain
$ svn co http://svn.gnome.org/svn/accerciser/trunk accerciser
$ cd accerciser
$ ./autogen.sh
$ make
$ sudo make install
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &amp;quot;make install&amp;quot; installs a binary called &amp;quot;accerciser&amp;quot;.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Ajax Pub Nite #1</title>
<id>http://bitstructures.com/2008/01/ajax-pub-nite</id>
<link href="http://bitstructures.com/2008/01/ajax-pub-nite" />
<published>2008-01-15T20:58:41-06:00</published>
<updated>2008-01-15T20:58:41-06:00</updated>
<content type="html">
&lt;p&gt;Last night I went to the first Toronto &lt;a href="http://ajaxcamp.org/"&gt;Ajax Pub Nite&lt;/a&gt; at &lt;a href="http://therhino.ca/"&gt;The Rhino&lt;/a&gt; on Queen West. It was clearly the right location for a JavaScript get together as not only is the rhino the animal featured on the cover of David Flanagan's &lt;a href="http://www.oreilly.com/catalog/jscript5/"&gt;JavaScript: The Definitive Guide&lt;/a&gt; (&amp;quot;the Rhino book&amp;quot;) and the name of a &lt;a href="http://www.mozilla.org/rhino/"&gt;JavaScript engine&lt;/a&gt;, but they also have free wifi! We'll be meeting at The Rhino on the second Monday of each month (February 11 is next up). If you're doing cool web stuff and you're in Toronto, come along!
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Running IE6 and IE7 on the same machine with Virtual PC</title>
<id>http://bitstructures.com/2008/01/ie6-ie7-same-machine</id>
<link href="http://bitstructures.com/2008/01/ie6-ie7-same-machine" />
<published>2008-01-11T13:16:02-06:00</published>
<updated>2008-01-11T13:16:02-06:00</updated>
<content type="html">
&lt;p&gt;Dojo supports both IE6 and IE7 so when developing it's important to test on both of these browsers. And it's nice to be able to test both browsers on the same machine.
&lt;/p&gt;
&lt;p&gt;My Windows XP has IE7 installed and to test on IE6 I was, until recently, using the &lt;a href="http://browsers.evolt.org/?ie/32bit/standalone"&gt;&amp;quot;standalone&amp;quot; packaged version of IE6&lt;/a&gt; from the evolt.org browser archive. However, its behaviour is not always consistent with a regular IE6 install on other computers.
&lt;/p&gt;
&lt;p&gt;I've just switched to another solution: virtualization with &lt;a href="http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx"&gt;Virtual PC&lt;/a&gt;. Microsoft offers Virtual PC as a free download and also offers a free &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&amp;displaylang=en"&gt;Virtual PC image of Windows XP with IE6&lt;/a&gt; (an image of Windows XP with IE7 is also available from the same download page).
   The images have been available for a while (&lt;a href="http://blogs.msdn.com/ie/archive/2006/11/30/ie6-and-ie7-running-on-a-single-machine.aspx"&gt;announced on the IEBlog in November 2006&lt;/a&gt;) and have been regularly updated.
&lt;/p&gt;
&lt;p&gt;For testing, I run a web server on my local machine and my browsers can access it with &amp;quot;http://localhost/&amp;quot;. But I can't access the web server with &amp;quot;localhost&amp;quot; inside the virtual machine &amp;mdash; it'll point to the virtual machine. To access my web server from the virtual machine I've been using the IP address of the host machine (you can get the IP address by running &amp;quot;ipconfig&amp;quot;). So, if my host machine, running the web server, has IP address 1.2.3.4 then I'd use &amp;quot;http://1.2.3.4/&amp;quot; inside the virtual machine.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Getting, setting, and removing tabindex values with JavaScript</title>
<id>http://bitstructures.com/2008/01/tabindex-javascript</id>
<link href="http://bitstructures.com/2008/01/tabindex-javascript" />
<published>2008-01-09T14:07:25-06:00</published>
<updated>2008-01-09T14:07:25-06:00</updated>
<content type="html">
&lt;p&gt;I recently implemented some functions for Dojo for getting, setting, and removing tabindex values. And, as it wasn't entirely straightforward, I've written up a &lt;a href="http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/"&gt;post for the Fluid project blog&lt;/a&gt; on what I found out.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>ARIA and jQuery and YUI</title>
<id>http://bitstructures.com/2008/01/aria-jquery-yui</id>
<link href="http://bitstructures.com/2008/01/aria-jquery-yui" />
<published>2008-01-06T21:52:31-06:00</published>
<updated>2008-01-06T21:52:31-06:00</updated>
<content type="html">
&lt;p&gt;Couple of recent ARIA developments:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     Chris Hoffman has built a jQuery plugin called &lt;a href="http://www.outstandingelephant.com/jaria/"&gt;jARIA&lt;/a&gt; for getting and setting ARIA roles and states; the source can be found at &lt;a href="http://www.outstandingelephant.com/jaria/jARIA.js"&gt;http://www.outstandingelephant.com/jaria/jARIA.js&lt;/a&gt; 
 &lt;/li&gt;

 &lt;li&gt;
     Todd Kloots and Victor Tsaran have written up an article on using ARIA with the YUI menu: &lt;a href="http://yuiblog.com/blog/2007/12/21/menu-waiaria/"&gt;Using WAI-ARIA Roles and States with the YUI Menu Control&lt;/a&gt;
 &lt;/li&gt;
&lt;/ul&gt;

</content>
</entry>


<entry>
<title>ARIA support in Internet Explorer</title>
<id>http://bitstructures.com/2008/01/aria-ie</id>
<link href="http://bitstructures.com/2008/01/aria-ie" />
<published>2008-01-06T16:33:50-06:00</published>
<updated>2008-01-06T16:33:50-06:00</updated>
<content type="html">
&lt;p&gt;&amp;quot;Internet Explorer Support of Web ARIA via UIA Express&amp;quot; is listed as a &lt;a href="http://www.accessinteropalliance.org/aboutus/index.html"&gt;current project on the website of the recently-formed Accessibility Interoperability Alliance (AIA)&lt;/a&gt;. No further details or timeline but it's really good to see that ARIA support in Internet Explorer is planned. The AIA has a three-person steering committee consisting of Andrew Kirkpatrick from Adobe, Claudio Giugliemma from QualiLife, and Rob Sinclair from Microsoft.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Functions, closures, and objects: implementing a filter function in Scheme and Java</title>
<id>http://bitstructures.com/2007/12/functions-closures-objects</id>
<link href="http://bitstructures.com/2007/12/functions-closures-objects" />
<published>2007-12-24T14:00:19-06:00</published>
<updated>2007-12-24T14:00:19-06:00</updated>
<content type="html">
&lt;p&gt;Continuing with the theme of functions and closures (&lt;a href="http://bitstructures.com/2007/11/javascript-method-callbacks"&gt;Registering JavaScript object methods as callbacks&lt;/a&gt;, &lt;a href="http://bitstructures.com/2007/11/python-bound-methods"&gt;Python bound methods&lt;/a&gt;), I thought I'd have a look at the relationship between functions, closures, and objects.  I'll build a &lt;a href="http://en.wikipedia.org/wiki/Filter_(higher-order_function)"&gt;filter&lt;/a&gt;, that returns elements from a collection for which a given predicate is true, in &lt;a href="http://schemers.org/"&gt;Scheme&lt;/a&gt; (a language with first-class functions and closures, but no objects), and in Java (a language with objects, but no first-class functions or closures.)
&lt;/p&gt;

&lt;h3&gt;A function is an object with an &amp;quot;apply&amp;quot; method&lt;/h3&gt;
&lt;p&gt;In Scheme we can define a filter function that takes two parameters: a function (the predicate), and a list. It will call the predicate function on each element in the list, returning a new list containing all of the elements for which the predicate is true:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(define (filter pred lis)
  ; if lis is empty
  (if (null? lis)
    ; return an empty list
    '()
    ; otherwise, if the predicate is true on the first element
    (if (pred (car lis))
      ; return the first element concatenated with the
      ; result of calling filter on the rest of lis
      (cons (car lis) (filter pred (cdr lis)))
      ; otherwise (if the predicate was false) just
      ; return the result of filtering the rest of lis
      (filter pred (cdr lis)))))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can then define a predicate and use it to filter:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(define (non-negative n)
  (&amp;gt;= n 0))

(filter non-negative '(-2 3 7 1)) ; (3 7 1)
(filter non-negative '(100 -9 8)) ; (100 8)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In Java, we don't have first-class functions, but we do have objects. And we can define a Predicate as an object with a public method that takes a single parameter and returns a boolean:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public interface Predicate&amp;lt;T&amp;gt; {
    public boolean apply(T arg);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can now write our Java filter function as a method that takes two parameters: a Predicate and a Collection:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import java.util.Collection;
import java.util.List;
import java.util.ArrayList;

public class Utils {
    public static &amp;lt;T&amp;gt; List&amp;lt;T&amp;gt; filter(Predicate&amp;lt;T&amp;gt; pred, Collection&amp;lt;T&amp;gt; c) {
        List&amp;lt;T&amp;gt; filtered = new ArrayList&amp;lt;T&amp;gt;();
        // loop through all the elements in c
        for (T obj : c) {
            // if the predicate is true for the current element
            if (pred.apply(obj)) {
                // append it to the result list
                filtered.add(obj);
            }
        }
        return filtered;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;NonNegative.java:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class NonNegative implements Predicate&amp;lt;Integer&amp;gt; {
    public boolean apply(Integer n) {
        return n &amp;gt;= 0;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With Predicate, Utils.filter, and NonNegative defined we can now filter:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// as our NonNegative class instances have no state,
// we only need one
Predicate&amp;lt;Integer&amp;gt; pred = new NonNegative();
Utils.filter(pred, Arrays.asList(-2, 3, 7, 1));
Utils.filter(pred, Arrays.asList(100, -9, 8));
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Scheme and Java examples above operated on collections of numbers but the filter functions (and Predicate interface in the Java case) are generic -- they can filter collections of any type and filter on any provided predicate logic.
&lt;/p&gt;

&lt;h3&gt;A closure is an object with an &amp;quot;apply&amp;quot; method and some state&lt;/h3&gt;
&lt;p&gt;Let's say we want to filter all numbers greater than 4. We could define a greater-than-4 function:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(define (greater-than-4 n)
  (&amp;gt; n 4))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And if we wanted to filter all numbers greater than 1, we could define a function for that too. The greater-than-1 function is going to be very similar to greater-than-4 and it would be quite convenient to write a generic greater-than function:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(define (greater-than m n)
  (&amp;gt; n m))

(greater-than 4 1) ; false
(greater-than 4 20) ; true
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, if we want to use our greater-than predicate with our filter function, we have a problem: the filter function expects the predicate to be a function that takes exactly one parameter (the element currently being considered), not two.
&lt;/p&gt;
&lt;p&gt;We can make our greater-than predicate work with our filter function by &lt;a href="http://foldoc.org/?curried+function"&gt;currying it&lt;/a&gt;:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(define (greater-than m)
  ; return a closure:
  ; a function that takes one parameter
  ; with a binding to the value provided for m
  (lambda (n)
    (&amp;gt; n m)))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We have rewritten greater-than to be a builder of functions (that take one parameter, as we need for filter). Rather than calculating if n is greater than m immediately, we delay the test and package it up into a closure and return that. We provide the parameters m and n in two stages: m is provided when we call greater-than (and stored for later use in the closure) and n is provided whenever the function returned from greater-than is called. For example, if we wanted to calculate 1 &amp;gt; 4 and 20 &amp;gt; 4:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(define greater-than-4 (greater-than 4))
(greater-than-4 1) ; false
(greater-than-4 20) ; true
; or, without naming the function
((greater-than 4) 1) ; false
((greater-than 4) 20) ; true
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It is this two-stage quality that enables us to use greater-than with our filter function:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(filter (greater-than 4) '(-2 3 7 1)) ; (7)
(filter (greater-than 10) '(100 -9 8)) ; (100)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can do something very similar in Java, but rather than a closure we use an object. We can implement GreaterThan as a Predicate in which m is provided to the object constructor and stored in an instance variable. The apply method will retrieve it later to perform its test:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class GreaterThan implements Predicate&amp;lt;Integer&amp;gt; {
    private Integer m;
    public GreaterThan(Integer m) {
        this.m = m;
    }
    public boolean apply(Integer n) {
        return n &amp;gt; m;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;No changes are necessary to either the Predicate interface or to Utils.filter:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Utils.filter(new GreaterThan(4), Arrays.asList(-2, 3, 7, 1));
Utils.filter(new GreaterThan(10), Arrays.asList(100, -9, 8));
&lt;/code&gt;&lt;/pre&gt;
</content>
</entry>


<entry>
<title>My Arduino arrived!</title>
<id>http://bitstructures.com/2007/12/arduino</id>
<link href="http://bitstructures.com/2007/12/arduino" />
<published>2007-12-22T13:46:37-06:00</published>
<updated>2007-12-22T13:46:37-06:00</updated>
<content type="html">
&lt;p&gt;&lt;a href="http://static.bitstructures.com/arduino/arduino-diecimila.jpg"&gt;&lt;img src="http://static.bitstructures.com/arduino/arduino-diecimila-small.jpg" alt="Arduino Diecimila: a printed circuit board with an ATmega168 processor, USB interface, power socket, and input and output pins"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;I've always had an interest in input and output devices beyond those typically available on desktop and laptop computers. But I've been limited by my electronics knowledge to build much stuff myself. My understanding of computing is pretty solid down to a certain point but when it comes to electrons and building circuits I'm a little lost. So, I was very excited to recently discover the &lt;a href="http://www.arduino.cc/"&gt;Arduino&lt;/a&gt; open hardware and software platform. It's a small board with an Atmel AVR processor, USB interface, power socket, and input and output pins. There's an open source programming environment based on the &lt;a href="http://processing.org/"&gt;Processing&lt;/a&gt; IDE with a C-like language (based on &lt;a href="http://www.wiring.org.co/"&gt;Wiring&lt;/a&gt;). The Arduino looks like an excellent place for beginners like me to learn microcontroller programming and electronics. I'm making my way through Dan O'Sullivan and Tom Igoe's excellent &lt;a href="http://www.amazon.com/Physical-Computing-Sensing-Controlling-Computers/dp/159200346X"&gt;Physical Computing: Sensing and Controlling the Physical World with Computers&lt;/a&gt; and I'll post my experiments here as I start building stuff!
&lt;/p&gt;
&lt;p&gt;(I bought the &lt;a href="http://www.adafruit.com/index.php?main_page=product_info&amp;cPath=17&amp;products_id=68"&gt;Arduino Starter Pack&lt;/a&gt; from Adafruit Industries.)
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Python bound methods</title>
<id>http://bitstructures.com/2007/11/python-bound-methods</id>
<link href="http://bitstructures.com/2007/11/python-bound-methods" />
<published>2007-11-28T22:21:10-06:00</published>
<updated>2007-11-28T22:21:10-06:00</updated>
<content type="html">
&lt;p&gt;In my &lt;a href="/2007/11/javascript-method-callbacks"&gt;last post&lt;/a&gt; I looked at registering JavaScript object methods as callbacks. When we reference a JavaScript object method we get a function object, which is not bound to the object that it is retrieved from, and I looked at various approaches that one can use to bind a method to an object instance. I thought it might be interesting to have a look at Python's &amp;quot;bound methods&amp;quot; to see how Python facilitates passing around object method references.
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Content-Type: text/plain
&amp;gt;&amp;gt;&amp;gt; class MyObject:
...     def __init__(self, val):
...         self.val = val
...     def get_val(self):
...         return self.val
... 
&amp;gt;&amp;gt;&amp;gt; obj = MyObject(8)
&amp;gt;&amp;gt;&amp;gt; obj.get_val()
8
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In Python when we reference an object method we don't get a function but rather a &lt;a href="http://www.python.org/doc/2.5/tut/node11.html#SECTION0011340000000000000000"&gt;&amp;quot;bound method&amp;quot;&lt;/a&gt;:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; obj.get_val
&amp;lt;bound method MyObject.get_val of &amp;lt;__main__.MyObject instance at 0x71e18&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A bound method is one of Python's &lt;a href="http://docs.python.org/ref/types.html"&gt;&amp;quot;callable&amp;quot; types&lt;/a&gt; (others include functions and generators.) Like a function, a bound method can be called but it is bound to the object that it was retrieved from. And when it is called, it operates on that object:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; f = obj.get_val
&amp;gt;&amp;gt;&amp;gt; f()
8
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If we need to, it's possible to access a bound method's object and function:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; f.im_self
&amp;lt;__main__.MyObject instance at 0x71e18&amp;gt;
&amp;gt;&amp;gt;&amp;gt; f.im_func
&amp;lt;function get_val at 0x64d30&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In JavaScript we had to bind a method to an object instance ourselves to use it as a callback. However, in Python when we reference an object method we get a callable object that is already bound.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Registering JavaScript object methods as callbacks</title>
<id>http://bitstructures.com/2007/11/javascript-method-callbacks</id>
<link href="http://bitstructures.com/2007/11/javascript-method-callbacks" />
<published>2007-11-27T10:28:30-06:00</published>
<updated>2007-11-27T10:28:30-06:00</updated>
<content type="html">
&lt;p&gt;The registration of callback functions is very common in JavaScript web programming, for example to attach user interface event handlers (such as onclick), or to provide a function to handle an XHR response. Registering an object method as a callback function is not entirely straightforward, but there are a number of approaches that we can use.
&lt;/p&gt;
&lt;p&gt;Let's say we've got a constructor, an object, and a function that registers a callback:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;function MyObject(val){
    this.val = val;
}
MyObject.prototype.alertVal = function(){
    alert(this.val);
}

var obj = new MyObject(8);

function register(callback){
    // some time later...
    callback();
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The constructor stores its single argument, and the alertVal() method alerts it. The simple register() function takes a function and calls it. In a real situation the behaviour here would be much more interesting but this will do for illustration.
&lt;/p&gt;

&lt;h3&gt;Why we don't want to just pass obj.alertVal to register()&lt;/h3&gt;
&lt;p&gt;Object methods are first-class functions in JavaScript and we could pass obj.alertVal to register() -- but it isn't quite what we want. Let's see what happens:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;register(obj.alertVal);
// inside register(), callback === obj.alertVal
callback()
// inside MyObject.prototype.alertVal
alert(this.val);
// because callback() was not called on an object,
// this === the JavaScript global object and not obj;
// this.val is the global variable val, not obj.val
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When a function is called as a method on an object (obj.alertVal()), &amp;quot;this&amp;quot; is bound to the object that it is called on (obj). And when a function is called without an object (func()), &amp;quot;this&amp;quot; is bound to the JavaScript global object (window in web browsers.) When we passed obj.alertVal to register() we were passing a reference to the function bound to obj.alertVal, but no reference to the object obj.
&lt;/p&gt;
&lt;p&gt;So, we need to bind our method to the object.
&lt;/p&gt;

&lt;h3&gt;Closure with an anonymous function&lt;/h3&gt;
&lt;p&gt;In JavaScript, whenever a function is defined within another one a closure is created [&lt;a href="http://blog.morrisjohns.com/javascript_closures_for_dummies"&gt;JavaScript Closures for Dummies&lt;/a&gt;] [&lt;a href="http://www.jibbering.com/faq/faq_notes/closures.html"&gt;JavaScript Closures&lt;/a&gt;]. A closure remembers the variable bindings that were in scope when the function was created. These bindings are then available whenever the function is called. We can bind our method to our object instance with the following:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;register(function(){obj.alertVal()});
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Whenever the anonymous function is called, &amp;quot;obj&amp;quot; will be bound to the value that it had when the function was created. Which is exactly what we want.
&lt;/p&gt;
&lt;p&gt;(If we execute the above code outside a function it will behave differently. No closure will be created, instead, the current value of the global variable &amp;quot;obj&amp;quot; will be used whenever the anonymous function is called, not the value at function definition.)
&lt;/p&gt;
&lt;p&gt;If we want to register a method on the object currently bound to &amp;quot;this&amp;quot;, we need to take an extra step:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;var obj = this;
register(function(){obj.alertVal()});
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If we don't explicitly bind &amp;quot;this&amp;quot; to a named variable (obj) and instead use &lt;code&gt;register(function(){this.alertVal()})&lt;/code&gt;  we will lose our object reference. &amp;quot;this&amp;quot; will be bound to the JavaScript global object whenever the anonymous function is called.
&lt;/p&gt;

&lt;h3&gt;Build a generic closure maker&lt;/h3&gt;
&lt;p&gt;Instead of building a closure each time we want to register a method as a callback, we could write a utility function to do it for us. For example:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;function bind(toObject, methodName){
    return function(){toObject[methodName]()}
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With such a function we can then register our method with:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;register(bind(obj, &amp;quot;alertVal&amp;quot;));
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Dojo (dojo.hitch()) and Prototype (&lt;a href="http://www.prototypejs.org/api/function/bind"&gt;bind()&lt;/a&gt;) both have such utility functions (that also allow you to provide arguments to pass to the method when called, something that our &amp;quot;bind&amp;quot; doesn't do.)
&lt;/p&gt;
&lt;p&gt;If we want to register a method of &amp;quot;this&amp;quot;, we don't need to explicitly bind it (as we did above) before calling &amp;quot;bind&amp;quot; -- the function call does the binding for us. &lt;code&gt;register(bind(this, &amp;quot;alertVal&amp;quot;))&lt;/code&gt; works as expected.
&lt;/p&gt;

&lt;h3&gt;Alter the register function to take the object too&lt;/h3&gt;
&lt;p&gt;If we changed our register function to:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;function register(anObject, methodName){
    // some time later...
    anObject[methodName]();
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We could register our call with:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;register(obj, &amp;quot;alertVal&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="http://www.dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/functions-used-everywhere/dojo-connect"&gt;dojo.connect&lt;/a&gt; and YUI's YAHOO.util.Event.addListener() [&lt;a href="http://developer.yahoo.com/yui/event/"&gt;YUI Event Utility&lt;/a&gt;] [&lt;a href="http://developer.yahoo.com/yui/docs/YAHOO.util.Event.html"&gt;YAHOO.util.Event API docs&lt;/a&gt;] both include this binding style in their API.
&lt;/p&gt;

&lt;h3&gt;Bind the method to the object at construction&lt;/h3&gt;
&lt;p&gt;We could bind our method to the object (or instance variables as shown here) in the constructor function:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;function MyObject(val){
    this.alertVal = function(){
        alert(val);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We could then register obj.alertVal directly as &amp;quot;val&amp;quot; is already bound:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;obj = new MyObject(8);
register(obj.alertVal);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Douglas Crockford writes about this programming style in &lt;a href="http://javascript.crockford.com/private.html"&gt;Private Members in JavaScript.&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;Circular references and memory leaks&lt;/h3&gt;
&lt;p&gt;Whichever method you use you need to be careful about avoiding circular references when registering event handlers (such as onclick) on document objects. For example, if we register an object method as an event handler on an element, such that the method is bound to the object, and the object has a reference back to the element, then we have a circular reference, and a potential leak (in this case a solution would be to have the object store the element's id rather than store a reference to the element object itself.) Here are some articles that discuss ways to cause memory leaks and ways to avoid them:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://www-128.ibm.com/developerworks/web/library/wa-memleak/"&gt;Memory leak patterns in JavaScript&lt;/a&gt; by Abhijeet Bhattacharya and Kiran Shivarama Sundar (IBM developerWorks)
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://msdn2.microsoft.com/en-us/library/Bb250448.aspx"&gt;Understanding and Solving Internet Explorer Leak Patterns&lt;/a&gt; by Justin Rogers (Microsoft)
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.jibbering.com/faq/faq_notes/closures.html"&gt;JavaScript Closures&lt;/a&gt; by Richard Cornford
 &lt;/li&gt;
&lt;/ul&gt;

</content>
</entry>


<entry>
<title>Hello Dijit Ajax World</title>
<id>http://bitstructures.com/2007/11/hello-dijit-ajax-world</id>
<link href="http://bitstructures.com/2007/11/hello-dijit-ajax-world" />
<published>2007-11-23T13:43:29-06:00</published>
<updated>2007-11-23T13:43:29-06:00</updated>
<content type="html">

&lt;h3&gt;Getting and deploying Dojo&lt;/h3&gt;
&lt;p&gt;You have 2 choices here:
&lt;/p&gt;

&lt;h4&gt;1. Download Dojo and serve it up yourself&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://dojotoolkit.org/downloads"&gt;Download Dojo,&lt;/a&gt; unpack the distribution and then serve it up with your web server. If you wanted to use Dojo from a page served up beside the Dojo distribution you could use something like this:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;
src=&amp;quot;dojo-release-1.0.0/dojo/dojo.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;2. Use Dojo from the AOL CDN (Content Delivery Network)&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://build.dojotoolkit.org/1.0.0/"&gt;AOL provides Dojo for public use on their Content Delivery Network.&lt;/a&gt; With this option you don't have to download Dojo at all (but you're going to need an internet connection of course to test your pages!) You would use Dojo with something like this:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;
src=&amp;quot;http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Hello Dijit Ajax World&lt;/h3&gt;

&lt;h4&gt;hi.html&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Hello Dojo AJAX&amp;lt;/title&amp;gt;
    &amp;lt;!-- load the Tundra theme from the AOL CDN --&amp;gt;
    &amp;lt;link rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot;
      href=&amp;quot;http://o.aolcdn.com/dojo/1.0.0/dijit/themes/tundra/tundra.css&amp;quot;&amp;gt;
    &amp;lt;!-- load Dojo from the AOL CDN:
      we set parseOnLoad true in djConfig so that we can
      specify Dijit widgets declaratively with dojotype
      (see the button below) --&amp;gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot;
      src=&amp;quot;http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js&amp;quot;
      djConfig=&amp;quot;parseOnLoad: true&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
      // use the Dojo dependency mechanism to pull in the
      // code for the parser and the Dijit Button
      dojo.require(&amp;quot;dojo.parser&amp;quot;);
      dojo.require(&amp;quot;dijit.form.Button&amp;quot;);
      // our button click handler:
      // sends an HTTP GET request to message.php
      // and alerts the response
      function click() {
        dojo.xhrGet({
          url: &amp;quot;message.php&amp;quot;,
          handleAs: &amp;quot;text&amp;quot;,
          load: function(response){
            alert(response);
          },
          content: {name: dojo.byId(&amp;quot;name&amp;quot;).value}
        });
      }
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;!-- use the Tundra theme --&amp;gt;
  &amp;lt;body class=&amp;quot;tundra&amp;quot;&amp;gt;
    &amp;lt;label for=&amp;quot;name&amp;quot;&amp;gt;Please enter your name:&amp;lt;/label&amp;gt;
    &amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot;&amp;gt;
    &amp;lt;br&amp;gt;
    &amp;lt;!-- a Dijit button that calls our click() handler --&amp;gt;
    &amp;lt;button dojoType=&amp;quot;dijit.form.Button&amp;quot;
    onClick=&amp;quot;click()&amp;quot;&amp;gt;Hi there&amp;lt;/button&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;message.php&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;?php
header(&amp;quot;Content-type: text/plain&amp;quot;);
$name = $_GET['name'];
echo &amp;quot;Howdy $name&amp;quot;;
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="http://static.bitstructures.com/hello-dijit-ajax-world/hi.html"&gt;Here's the page in action.&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;Using Dijit widgets&lt;/h3&gt;
&lt;p&gt;There are 2 strategies for creating Dijit widgets, declarative and programmatic. In the declarative strategy widgets are declared in markup. We put a placeholder element into our document and specify the type of the widget and any parameters or event handlers using HTML attributes. The button widget was created declaratively in &lt;code&gt;hi.html&lt;/code&gt; above. It used a &lt;code&gt;dojotype&lt;/code&gt; attribute to specify its type, &lt;code&gt;dijit.form.Button,&lt;/code&gt; and an &lt;code&gt;onClick&lt;/code&gt; attribute to specify an event handler. For another example, here's how we might declare a ProgressBar:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;div dojotype=&amp;quot;dijit.ProgressBar&amp;quot; progress=&amp;quot;0&amp;quot; maximum=&amp;quot;50&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At page load time a parser reads through the document processing elements with &lt;code&gt;dojotype&lt;/code&gt; attributes. For widgets, this typically means replacing the element with elements to build the widget. For example, the above ProgressBar placeholder div would be replaced with elements for the bar container, the bar at its current progress width, and a label for the bar. To see a ProgressBar in action have a look at the &lt;a href="http://download.dojotoolkit.org/release-1.0.0/dojo-release-1.0.0/dijit/tests/test_ProgressBar.html"&gt;ProgressBar test page.&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;In the programmatic strategy we create the widget instance ourselves. We can still use a placeholder element but this time we don't specify the widget type or any other attributes:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;div id=&amp;quot;bar&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then at some point, we can construct a widget in code:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Content-Type: text/plain
var bar = new dijit.ProgressBar({progress: 0, maximum: 50}, &amp;quot;bar&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This call will create the widget and modify the document, replacing the placeholder div with the elements for the widget. When we create widgets programmatically we specify widget properties by passing an object to the widget constructor, rather than with HTML attributes. The use of a placeholder element is optional and we can construct a widget without one. In this case elements are built but they won't be located in the document. You can insert the elements for the widget into the document later by using the widget's domNode property (for example, &lt;code&gt;foo.appendChild(bar.domNode)&lt;/code&gt;). Here are some reasons why you might want to use the programmatic strategy:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     widget creation is under your control, this is important when developing in an unobtrusive or progressive enhancement manner
 &lt;/li&gt;

 &lt;li&gt;
     it is unnecessary to add attributes to HTML
 &lt;/li&gt;

 &lt;li&gt;
     the parser is not needed (less code to load and less code to run at page load)
 &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Programming with Dojo&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo-0"&gt;Dojo provides a rich set of programming supports,&lt;/a&gt;  including functions for managing events, DOM querying and manipulation, animations, and JavaScript language utilities. Here's a couple to get you started:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/functions-used-everywhere/dojo-addonload"&gt;dojo.addOnLoad:&lt;/a&gt;
 registers code to run whenever the page has been loaded
 &lt;/li&gt;

 &lt;li&gt;
     dijit.byId: retrieves the widget object for an element
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If we created a widget:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;div id=&amp;quot;bar&amp;quot; dojotype=&amp;quot;dijit.ProgressBar&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;we could access it programmatically, say to change the progress value, with:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Content-Type: text/plain
dijit.byId(&amp;quot;bar&amp;quot;).update({progress: 10});
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Further reading&lt;/h3&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://dojotoolkit.org/book/dojo-book-0-9-0"&gt;The Book of Dojo&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://dojotoolkit.org/book/dojo-book-0-9/part-2-dijit-0"&gt;Widget section of the book&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/ajax-transports"&gt;Ajax section of the book&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/debugging-facilities"&gt;Debugging facilities&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     The &lt;a href="http://download.dojotoolkit.org/release-1.0.0/dojo-release-1.0.0/dijit/themes/themeTester.html"&gt;Dijit Theme Tester&lt;/a&gt; is a good place to see the available widgets in action
 &lt;/li&gt;

 &lt;li&gt;
     The &lt;a href="http://download.dojotoolkit.org/release-1.0.0/dojo-release-1.0.0/dijit/tests/"&gt;Dijit test pages&lt;/a&gt; also work quite well as examples for how to use each widget; see test_WIDGET_NAME.html (for example &lt;a href="http://download.dojotoolkit.org/release-1.0.0/dojo-release-1.0.0/dijit/tests/form/test_Button.html"&gt;test_Button.html&lt;/a&gt;)
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.onlamp.com/pub/a/onlamp/2007/11/01/the-mojo-of-dojo.html"&gt;The Mojo of Dojo by Matthew Russell&lt;/a&gt;
 &lt;/li&gt;
&lt;/ul&gt;

</content>
</entry>


<entry>
<title>AxsJAX</title>
<id>http://bitstructures.com/2007/11/axsjax</id>
<link href="http://bitstructures.com/2007/11/axsjax" />
<published>2007-11-14T09:52:31-06:00</published>
<updated>2007-11-14T09:52:31-06:00</updated>
<content type="html">
&lt;p&gt;We have been building accessibility support into the Dojo JavaScript toolkit to enable developers to create accessible web applications. But what if you are using a web application written in a toolkit without accessibility support or you are not satisfied with the user experience you are getting? You could try injecting new behaviour with AxsJAX -- the new JavaScript framework from Charles Chen and T.V. Raman. AxsJAX can inject accessibility support, such as keyboard behaviour or ARIA roles and states, into web applications at the browser. &lt;a href="http://code.google.com/p/google-axsjax/"&gt;AxsJAX is open source and up on Google Code&lt;/a&gt;. There's an &lt;a href="http://google-axsjax.googlecode.com/svn/trunk/docs/faq.html"&gt;FAQ&lt;/a&gt; and &lt;a href="http://google-axsjax.googlecode.com/svn/trunk/docs/"&gt;other documentation&lt;/a&gt; on available injection scripts (Google Reader and Google Search at the time of writing this post.)
&lt;/p&gt;

</content>
</entry>


<entry>
<title>Dojo 1.0 is out!</title>
<id>http://bitstructures.com/2007/11/dojo-1-0</id>
<link href="http://bitstructures.com/2007/11/dojo-1-0" />
<published>2007-11-05T12:09:09-06:00</published>
<updated>2007-11-05T12:09:09-06:00</updated>
<content type="html">
&lt;p&gt;Congratulations to the Dojo community! Version 1.0 of the JavaScript toolkit has been released. There's lots of great stuff in this release and Alex has a &lt;a href="http://dojotoolkit.org/2007/11/05/dojo-1-0"&gt;post up on the Dojo site outlining the new features in 1.0.&lt;/a&gt; One of the things that we have really been working at for this release is solid accessibility support:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     widgets are usable by keyboard alone, keyboard and mouse used in combination, or mouse alone
 &lt;/li&gt;

 &lt;li&gt;
     widgets use &lt;a href="http://www.w3.org/TR/aria-roadmap/"&gt;ARIA roles and states&lt;/a&gt; to provide semantics for assistive technologies (such as screen readers)
 &lt;/li&gt;

 &lt;li&gt;
     widgets have been designed to work in Windows high-contrast mode
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thank you IBM and Mozilla for supporting Dojo accessibility.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>FSOSS 2007 DHTML Accessibility Talk</title>
<id>http://bitstructures.com/2007/10/fsoss2007-accessible-dhtml</id>
<link href="http://bitstructures.com/2007/10/fsoss2007-accessible-dhtml" />
<published>2007-10-27T14:21:35-05:00</published>
<updated>2007-10-27T14:21:35-05:00</updated>
<content type="html">
&lt;p&gt;I had a great time this week at the Seneca &lt;a href="http://fsoss.senecac.on.ca/2007/"&gt;Free Software &amp; Open Source Symposium (FSOSS).&lt;/a&gt; On Friday, &lt;a href="http://atrc.utoronto.ca/index.php?option=com_content&amp;task=view&amp;id=116&amp;Itemid=116"&gt;David Bolter&lt;/a&gt; and I gave a talk on DHTML accessibility. Here are the slides:
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://static.bitstructures.com/fsoss2007-accessible-dhtml/atrcFsoss2007.pdf"&gt;&lt;img src="http://static.bitstructures.com/fsoss2007-accessible-dhtml/atrcFsoss2007.png" alt="Accessible DHTML Simon Bates David Bolter ATRC"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;(the &lt;a href="http://static.bitstructures.com/fsoss2007-accessible-dhtml/atrcFsoss2007.ppt"&gt;FSOSS slides are also available in PowerPoint format&lt;/a&gt;)
&lt;/p&gt;
&lt;p&gt;As part of our talk we showed how to build a simple accessible DHTML menu. We started out with a visual, mouse-based menu and added keyboard support, assistive technology support with ARIA, and high-contrast support.
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://static.bitstructures.com/fsoss2007-accessible-dhtml/menu1-visual-mouse.html"&gt;menu1&lt;/a&gt;: visual, mouse-based menu
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://static.bitstructures.com/fsoss2007-accessible-dhtml/menu2-keyboard.html"&gt;menu2&lt;/a&gt;: adding keyboard support
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://static.bitstructures.com/fsoss2007-accessible-dhtml/menu3-aria.html"&gt;menu3&lt;/a&gt;: adding assistive technology support with ARIA
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://static.bitstructures.com/fsoss2007-accessible-dhtml/menu4-high-contrast.html"&gt;menu4&lt;/a&gt;: adding high contrast focus indication
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://static.bitstructures.com/fsoss2007-accessible-dhtml/util.js"&gt;util.js&lt;/a&gt;: some utility functions used in the menu
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I'd like to thank David Humphrey for inviting us to speak and for doing such a great job organising the symposium.
&lt;/p&gt;

</content>
</entry>


<entry>
<title>xUnit Test Patterns @ XPToronto</title>
<id>http://bitstructures.com/2007/09/xunit-xptoronto</id>
<link href="http://bitstructures.com/2007/09/xunit-xptoronto" />
<published>2007-09-19T19:57:48-05:00</published>
<updated>2007-09-19T19:57:48-05:00</updated>
<content type="html">
&lt;p&gt;Alistair McKinnell and Jason Cheong-Kee-You gave an excellent talk on xUnit Test Patterns at XPToronto last night. The presentation included a discussion of &lt;a href="http://xunitpatterns.com/Philosophy%20Of%20Test%20Automation.html"&gt;Gerard Meszaros's test philosophy framework:&lt;/a&gt; 
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     Test First or Last?
 &lt;/li&gt;

 &lt;li&gt;
     Tests or Examples?
 &lt;/li&gt;

 &lt;li&gt;
     Test-by-Test or All-At-Once?
 &lt;/li&gt;

 &lt;li&gt;
     Outside-In or Inside-Out?
 &lt;/li&gt;

 &lt;li&gt;
     State or Behavior Verification?
 &lt;/li&gt;

 &lt;li&gt;
     Fixture Design Up Front or Test-by-Test?
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For illustration, Alistair and Jason worked through the development of a set of JUnit tests in a session of pair programming. They worked: Test First, Test-by-Test, Inside-Out, Behavior Verification.
&lt;/p&gt;

</content>
</entry>

</feed>
