<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>HardLikeSoftware &#187; ajax</title>
	<atom:link href="http://hardlikesoftware.com/weblog/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://hardlikesoftware.com/weblog</link>
	<description>The writings of John Snyders, mostly about software.</description>
	<lastBuildDate>Wed, 14 Sep 2011 04:57:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Angular, Bindings and Templates</title>
		<link>http://hardlikesoftware.com/weblog/2010/09/19/angular-bindings-and-templates/</link>
		<comments>http://hardlikesoftware.com/weblog/2010/09/19/angular-bindings-and-templates/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 01:53:00 +0000</pubDate>
		<dc:creator>John Snyders</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://hardlikesoftware.com/weblog/?p=97</guid>
		<description><![CDATA[I recently watched a video about a cool new technology called &#60;angular/&#62;. It looks like a great way to create web applications. It caught my attention because I saw in it some parallels with some of my recent writings and what I am currently working on.
The video was very good but in the beginning Misko [...]]]></description>
			<content:encoded><![CDATA[<p>I recently watched a <a href="http://www.youtube.com/watch?v=0iQCLlu1dko">video</a> about a cool new technology called <a href="http://angularjs.org">&lt;angular/&gt;</a>. It looks like a great way to create web applications. It caught my attention because I saw in it some parallels with some of my recent <a href="/weblog/2009/05/14/a-declaritive-language-for-web-applications/">writings</a> and what I am currently <a href="/weblog/2010/09/06/implementing-a-domain-specific-language/">working on</a>.</p>
<p>The video was very good but in the beginning Misko Hevery struggled a bit to describe it and at the end admitted the biggest problem was explaining to people what &lt;angular/&gt; is. To me it is clearly a language, and an extensible one at that. It is (or at least contains) as he describes an HTML compiler. Doesn&#8217;t a compiler imply some language to compile. The source is clearly more than just HTML so it must be more than just an HTML compiler. I wonder if there is some reason he avoids calling it a language. The fact that it can be extended to handle new behaviors, widgets, etc. just makes it a better language. Is there some fear that calling it a language would put people off? It doesn&#8217;t bother me since I previously said that higher level languages will provide the <a href="/weblog/2009/04/20/writtten-language-already-the-best-tool-for-software/"> biggest productivity gains</a>. </p>
<p>The parallels I was talking about are:</p>
<ul>
<li>Its a declarative language</li>
<li>The language is designed to be extended</li>
<li>It has two way data binding</li>
</ul>
<p>Two way data binding is a very important aspect in simplifying the creation of web apps. The first time I ever saw data binding was back in the the late &#8217;80s. I was visiting a friend that was working on a <a href="http://en.wikipedia.org/wiki/Maser">maser</a>, which is cool (literally) in its own right, but what caught my eye, as he showed me around his lab, was some software running on an old Mac. That software was LabView. The fact that a line drawn between a sensor and a gauge meant that any time the senor value changed the gauge was updated really impressed me. More recently I noticed that data binding is built in to the JavaFX language. I haven&#8217;t written any programs in LabView or JavaFX so I&#8217;m not sure if the bindings can be bidirectional but I&#8217;m pretty sure at least in JavaFX that bidirectional changes can be accomplished.</p>
<p>It is the two way data bindings that most notably distinguish &lt;angular/&gt; from template languages. I used to be a big fan of template languages, and StringTemplate was my favorite. Lately I have found them to be less useful. One reason is that in my recent work I have found that procedural logic far outweighs the amount of template text. The bigger reason is that most template languages don&#8217;t automatically protect you from <a href="/weblog/2008/02/15/script-injection-and-stringtemplate/">script injection (XSS)</a>. There are many JavaScript template languages available now and I don&#8217;t have a need for any of them. But &lt;angular/&gt; is different &mdash; it is not a template language and it looks like it protects against script injection by default.</p>
<p>&lt;angular/&gt; is new but it looks very promising.</p>
]]></content:encoded>
			<wfw:commentRss>http://hardlikesoftware.com/weblog/2010/09/19/angular-bindings-and-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Sprites vs. High Contrast Mode</title>
		<link>http://hardlikesoftware.com/weblog/2009/11/04/css-sprites-vs-high-contrast-mode/</link>
		<comments>http://hardlikesoftware.com/weblog/2009/11/04/css-sprites-vs-high-contrast-mode/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 03:12:14 +0000</pubDate>
		<dc:creator>John Snyders</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://hardlikesoftware.com/weblog/2009/11/04/css-sprites-vs-high-contrast-mode/</guid>
		<description><![CDATA[Using positioned background images (a.k.a CSS Sprites) has a number of benefits: 

Performance. One of the performance recommendations made by Yahoo&#8217;s performance team is to reduce HTTP requests. One way to do this is using the CSS Sprite technique &#8212; combining many images into a single background image.
Skin-ability. With the img tag the image URL [...]]]></description>
			<content:encoded><![CDATA[<p>Using positioned background images (a.k.a <a href="http://www.alistapart.com/articles/sprites/">CSS Sprites</a>) has a number of benefits: </p>
<ul>
<li>Performance. One of the <a href="http://developer.yahoo.com/performance/rules.html">performance recommendations</a> made by Yahoo&#8217;s performance team is to reduce HTTP requests. One way to do this is using the CSS Sprite technique &mdash; combining many images into a single background image.</li>
<li>Skin-ability. With the img tag the image URL is in HTML markup where it is hard to change. With CSS Sprites the image URL is in a CSS file making it more convenient to change. Sure you can change the contents of the original file but there are reasons for changing the URL. It is not as easy to move the images to a different server or group them in different image files when the URL is not in CSS.</li>
</ul>
<p>However there are drawbacks. The biggest is accessibility, specifically high contrast mode. In high contrast mode all background images and colors are ignored &mdash; replaced with high contrast colors such as white on black or black on white. The other issue is that background images are not always printed.</p>
<p>The prevailing accessibility advice is to not use background images for functional images. The underlying problem is that there is no way in HTML/CSS to identify a background image as being functional. They are all considered decorative. It is also true that not all img tag images are functional but again there is no way to distinguish them for the purpose of high contrast mode. So high contrast mode makes a reasonable assumption that background images are decoration to be removed and img images are functional and must be shown. From here on I&#8217;ll call functional images icons. They either convey important information or are interactive (like a toolbar button for example).</p>
<p>I have seen recommendations that functional background images should be replaced with text when high contrast mode is detected. This does not seem right to me at all. A desktop app does not change its toolbar button icons to text in high contrast mode. The assumption is that icons are already designed to have reasonable contrast.</p>
<p>It also just feels right to me that the icon URLs should come from CSS.</p>
<p>Since I care about performance and accessibility I&#8217;m not happy with this conflict. I want a solution that puts the icon URL in CSS, works in high contrast mode and allows me to combine icons into a single image file. Here is what I came up with.<br />
<span id="more-88"></span><br />
My typical markup for an icon is something like this:</p>
<pre class='code'>
    &lt;button>&lt;span class="icon edit">&lt;/span>&lt;/button>
    &lt;button>&lt;span class="icon delete">&lt;/span>&lt;/button>
</pre>
<p>The basic style is:</p>
<pre class='code'>
span.icon {
    display: -moz-inline-box;
    display: inline-block;
    width: 16px;
    height: 16px;
}
button span.icon.edit {
    background: transparent url(images/toolbar.png) no-repeat 0px -32px;
}
button span.icon.delete {
    background: transparent url(images/toolbar.png) no-repeat 0px -16px;
}
</pre>
<p>This creates a button with an edit icon assuming that toolbar.png is a sprite image with the edit icon at offset 0, 32 etc. I left out extras like a title tooltip and hover and active states for the button icon to keep things simple. This works nicely until high contrast mode is turned on. </p>
<p>You can use the same sprite image in an img element and position it relative to a fixed size parent that has overflow:hidden to achieve similar functionality to a background image.</p>
<p>For example:</p>
<pre class='code'>
    &lt;button>&lt;span class="icon edit">&lt;img alt="" src="images/toolbar.png">&lt;/span>&lt;/button>
    ...
</pre>
<p>The style to make this work is:</p>
<pre class='code'>
span.icon {
    display: -moz-inline-box;
    display: inline-block;
    width: 16px;
    height: 16px;
    overflow: hidden;
    position: relative;
}
button span.icon.edit img {
    position: relative;
    left: 0px;
    top: -32px;
}
...
</pre>
<p>This works in high contrast mode (as well as normal mode) and has multiple icons in a single image but the image URL is in the markup not in the stylesheet. What I want to do is use JavaScript to take the image URL from CSS and dynamically add the img element as a child of the icon span. The html mark up and stylesheet will be the same as the first example above except that the stylesheet will have these additional styles:</p>
<pre class='code'>
span.icon.edit img {
    top: -32px;
    left: 0px;
}
span.icon.delete img {
    top: -16px;
    left: 0px;
}
</pre>
<p>These additional rules are not too much extra work considering you will usually have additional rules to adjust the position on hover and active states anyway.</p>
<p>My first attempt tried to get the URL from the current styles using jQuery like so: $(&#8230;).css(&#8220;background-image&#8221;). The trouble is that in high contrast mode the effective current background image is &#8220;none&#8221; even though the CSS file does have a background image. This makes sense &mdash; the program should &#8220;see&#8221; what the user sees. The solution is to get the actual background image directly from the CSS rules. This takes a little fiddling to get it to work cross browser. Some browsers return the full URL and some return exactly what is in the CSS file. Some times its wrapped in quotes. </p>
<p>This <a href="/projects/HCMtest.html">test page</a> shows an example of the traditional CSS Sprite technique as well as my jQuery enhanced high contrast mode compatible version. All the styles and JavaScript are in the html file to make it easy to see how it works. It also contains code to detect high contrast mode. One option is to only make the dynamic change if high contrast mode is detected but that is not the approach I took in the test page.</p>
<p>View the page with high contrast mode turned on and off to see the difference. Note: not all browsers or operating systems support high contrast mode. Firefox and IE on Windows do. It is also important that the dynamic changes work even in browsers that don&#8217;t support it (by work I mean that the icons look right and are functional, not that high contrast mode magically starts working in browsers that don&#8217;t support it). I tested on Windows with IE8, FF3.5, Safari 3.2 and 4.0, Opera 10 and Chrome and found that they all worked. I also tested on Linux with FF3 and found no problems. I don&#8217;t have a Mac to test with. I tested with IE6 and found that it did not work. More investigation is needed but IE6 is not a high priority for me right now. I need to test with IE7 but don&#8217;t have it handy right now. </p>
<p>Feedback on how it works in other browsers and operating systems would be very helpful.</p>
<p>I did not do any performance testing. The assumption is that moving the image from the background to an img tag will not cause the image to be requested from the server. The Firebug Net tab indicates that it is fetched just once. The page seems to render fast enough with no flashing. More testing is needed but I think the principal is sound. The script could use some improvement to be more robust especially for much older browsers so they at least fall back to using the CSS sprites as is. I bet there are other cases of relative URLs to test for as well.</p>
<p>Keep in mind that the test page is meant to demonstrate just this technique. It has a bunch of other accessibility no-nos such as the disclose icons are not focusable, keyboard accessible, and have no screen reader accessible label text. </p>
]]></content:encoded>
			<wfw:commentRss>http://hardlikesoftware.com/weblog/2009/11/04/css-sprites-vs-high-contrast-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE8 has strange rules for showing focus</title>
		<link>http://hardlikesoftware.com/weblog/2009/09/04/ie8-has-strange-rules-for-showing-focus/</link>
		<comments>http://hardlikesoftware.com/weblog/2009/09/04/ie8-has-strange-rules-for-showing-focus/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 03:07:27 +0000</pubDate>
		<dc:creator>John Snyders</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://hardlikesoftware.com/weblog/2009/09/04/ie8-has-strange-rules-for-showing-focus/</guid>
		<description><![CDATA[While working on some accessible UI widgets I found strange behavior in IE8 related to when it does or doesn&#8217;t show the focus outline around an element that has focus.
When you use the focus method to set focus to a focusable element the expectation is that, in the absence of css rules to the contrary, [...]]]></description>
			<content:encoded><![CDATA[<p>While working on some accessible UI widgets I found strange behavior in IE8 related to when it does or doesn&#8217;t show the focus outline around an element that has focus.</p>
<p>When you use the focus method to set focus to a focusable element the expectation is that, in the absence of css rules to the contrary, the browser will show a focus outline around the element using its default style.  This is what happens in Firefox, Chrome, and Safari. (Opera has its own set of focus problems which I didn&#8217;t investigate fully.)</p>
<p>There are a number of elements that are naturally focusable, such as inputs and anchors. In addition any element with a tabindex attribute equal to -1 is focusable. If the tabindex is non-negative then it is focusable and in the tab order. My test case uses list elements with tabindex of -1 or 0. I suspect that the same is true of other elements using tabindex.</p>
<p>Older versions of IE (I tested IE6 and I believe IE7 works the same in this regard) had some strange additional requirements beyond just calling focus. The outline would not be shown if the focus method was used to give focus to an element with a tabindex of -1. So before setting focus you would have to set the tabIndex to zero (or a positive number). </p>
<p><code>elem.tabIndex = 0;<br />
elem.focus();<br />
</code></p>
<p>Also if you click on an element with tabindex of -1 no outline is shown unless the className is updated (even if the value doesn&#8217;t change). Perhaps other style changes would work as well.</p>
<p>IE8 adds some new bizarre behavior. First if css is used to set an explicit outline style on the elements (either directly or inherited) then the old IE quirks mentioned above go away as well as the new IE8 problem described below. Setting your own outline style for focus isn&#8217;t a good idea unless you are giving your whole web app a focus style makeover. I think it is best to stick with the default styles since it is what the user is probably used to. There is also the problem of old browser like IE6 not supporting the outline style.</p>
<p>If the className of the element receiving focus is updated in the onfocus handler while the tabIndex is -1 then no focus outline is shown. Assuming that the tabIndex is -1 and addClass is a function that adds a class to the className, one would expect the following two lines of code could be executed in either order.</p>
<p><code>addClass(elem, "myfocus");<br />
elem.tabIndex = 0;<br />
</code></p>
<p>In IE8 setting the tabIndex to zero must be done first or the outline is not shown. This is exactly what tripped me up. If I just happened to write the statements in the opposite order I would never have discovered these oddities.</p>
<p>Note that in all cases focus is actually set correctly it is just the visual indication of focus that is wrong &#8211; but thats the important part of focus.</p>
<p>I created a <a href="/projects/IE8FocusTest.html">test page</a> that allows playing around with these rules. It is also an example of how focus can be managed with a roving tabindex.  If you play with this page in different browsers you will notice that in Firefox (versions 2 &#8211; 3.5) , Chrome, and Safari 4 (I tested on Windows) it doesn&#8217;t matter what options are checked, the behavior is correct. In IE you can play with the options to see which combinations work.</p>
<p>I wonder if this is intentional in IE8 or is something that will get fixed in a point release.</p>
]]></content:encoded>
			<wfw:commentRss>http://hardlikesoftware.com/weblog/2009/09/04/ie8-has-strange-rules-for-showing-focus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>APIs, UIs, and REST</title>
		<link>http://hardlikesoftware.com/weblog/2009/04/30/apis-uis-and-rest/</link>
		<comments>http://hardlikesoftware.com/weblog/2009/04/30/apis-uis-and-rest/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 04:31:27 +0000</pubDate>
		<dc:creator>John Snyders</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://hardlikesoftware.com/weblog/2009/04/30/apis-uis-and-rest/</guid>
		<description><![CDATA[When you read about REST these days it is usually in the context of APIs. You&#8217;ll even find REST being discussed in Web Service and SOA circles. A REST API makes an application&#8217;s data and functionality available to other programs according to the principal of REST. 
Sometimes you see the term REST API and sometime [...]]]></description>
			<content:encoded><![CDATA[<p>When you read about <acronym title="Representational State Transfer"><a class="gloss" href="/weblog/glossary#REST" title="Representational State Transfer">REST</a></acronym> these days it is usually in the context of <acronym title="Application Programming Interface">APIs</acronym>. You&#8217;ll even find REST being discussed in Web Service and <acronym title="Service Oriented Architecture">SOA</acronym> circles. A REST API makes an application&#8217;s data and functionality available to other programs according to the principal of REST. </p>
<p>Sometimes you see the term REST API and sometime REST Service (or RESTful Web Service). I don&#8217;t like the REST Service term because I think it gets confused with the <acronym title="Simple Object Access Protocol">SOAP</acronym> and <acronym title="Remote Procedure Call">RPC</acronym> styles. REST API is also a strange term. When we think of APIs the most familiar is the local call to a function, method, subroutine or procedure.  The remote procedure call tries the best it can to preserve the same semantics when the caller and callee are not on the same machine. When we think of a remote API it is easy to assume RPC. With REST the focus is on the resources. Other aspects of the interface such as the set of method are fixed and uniform. I use REST API to mean a RESTful application data layer that can be consumed by another program. </p>
<p>REST is an architectural style for hypermedia systems with the World Wide Web being the primary example, and the only instance of immediate  concern. For all the talk of APIs the web is still mainly about UI. Its a hypermedia system for humans.</p>
<p>REST doesn&#8217;t care if it is a human or a program that is the client of your resources. So why all the focus on APIs? Other than general information about REST I have not found practical specific advice for implementing RESTful web applications. The best I have found is this <a title="RESTful Web Apps (PDF version)" href="http://www.google.com/url?sa=t&#038;source=web&#038;ct=res&#038;cd=7&#038;url=http%3A%2F%2Fwww.softwaresummit.com%2F2008%2Fspeakers%2Fpresentations%2FAllamarajuRESTfulWebApps.pdf&#038;ei=tHLuSeG8LJPflQfn1Pgu&#038;usg=AFQjCNG8SHpqfBl4Ak-U0cGCNr4fslhWUQ">slide</a> deck — I wish I saw the talk.</p>
<p>An information only web site (one with static HTML and no forms) is likely to be RESTful even if only by accident. As web sites allow richer interaction between the user and the site and among users of the site it gets easier to stray from the principals of REST. Some of the issues that come up are:</p>
<ul>
<li>The HTML form element doesn&#8217;t support PUT and DELETE</li>
<li>You need somewhere to put conversational (i.e. session) state and REST says no cookies</li>
<li>You need to authenticate users but can&#8217;t accept the <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=155252">limitations</a> of HTTP authentication</li>
</ul>
<p>Is it these issues that caused REST to retreat to the realm of APIs?</p>
<p>Now ajax can help solve these problems so its reasonable to think about making your web app UI RESTful. <abbr title="XMLHttpRequest"><a class="gloss" href="/weblog/glossary#XHR" title="XMLHttpRequest">XHR</a></abbr> does support PUT and DELETE (as well as GET and POST). There are a few options for maintaining state on the client: </p>
<ul>
<li>A single page app can keep state in JavaScript objects</li>
<li>Gears or HTML 5 client storage can store session state and more</li>
<li>HTML 5 session history can handle specific issues with the back button</li>
</ul>
<p>Authentication is still an issue and the solution to <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">CSRF</a> requires server side session state. I need to think more about these.</p>
<p>Lets assume all the issues with your web app UI being fully RESTful are solved. Now you want to also provide your application&#8217;s functionality/data to other arbitrary clients. Do you do this as a completely independent effort? It makes sense to me that the UI should be using the same RESTful data layer API that other clients would use. </p>
<p>Now you have two related but separate planes of URLs; UI URLs and data URLs. You will find yourself in the same situation by following the principals of <a href="http://hardlikesoftware.com/weblog/2009/03/29/comments-on-life-above-the-service-tier/" title="Service-Oriented Front-End Architecture">SOFEA</a> if you try to make the UI and data layer RESTful.</p>
<p>While looking at a list or table of accounts the UI URL might be something like myapp.com/ui#accounts (the hash is used because I&#8217;m assuming a single page app) and the URL for the resource supplying the account collection might be myapp.com/api/accounts. The names of accounts in the list include links to details about each account. Clearly, for bookmarking, the UI URL needs to include the account identifier. The UI URL for an account detail view might be myapp.com/ui#accountdetails;083249. The data URL could be myapp.com/api/accounts/083249.</p>
<p>If your RESTful data layer follows the principal of &#8220;hypermedia as the engine of application state&#8221; then the /api/accounts representation should have (in some form or another) the URLs to each account in the collection. The accounts list UI also needs to know the the UI URL for account details. </p>
<p>To click a link and get from the accounts list to an account detail vew there are two things that must be done. First the accounts list UI must know how to take the account id number and add it to the account details UI URL. There is nothing in the uniform REST interface that tells the UI how to do this. In fact programs should not pick apart URLs (there seems to be some <a href="http://rest.blueoxen.net/cgi-bin/wiki.pl?GenerativeNaming">debate</a> about if it is OK for programs to assemble URLs) . </p>
<p>Second the account details UI needs to know the data URL to use for the specific account. Here are some ways it could happen:</p>
<ol>
<li>The details page could know how to create data URLs taking the account number from its own URL and sticking it in the right place. I think the article <a href="http://www.infoq.com/articles/subbu-allamaraju-rest">&#8220;Describing RESTful Applications&#8221;</a> is saying this isn&#8217;t OK.</li>
<li>The accounts list page could put the data URL somewhere in memory (or other client storage if it isn&#8217;t a single page app) so that the account details page can retrieve and use it. But this wouldn&#8217;t work for bookmarking.</li>
<li>The UI URL could have the full data layer URL encoded in it like so: myapp.com/ui#accountdetails;/api/accounts/083249. This solves the bookmarking problem but something just doesn&#8217;t feel right about this URL. If nothing else its long and repetitive.</li>
</ol>
<p>Articles on RESTful APIs (including the above linked &#8220;Describing RESTful Applications&#8221;), put a lot of emphasis on loose coupling between servers &mdash; the things providing the API &mdash; and clients. There seems to be an underlying assumption that generic or arbitrary clients exist.</p>
<p>In my past experience of building desktop applications the UI has detailed knowledge of the underlying data. In traditional MVC architecture (if there is such a thing) the views know about the model (the views can call methods of the model to get or set data) but the model has no direct access to the views. Some sort of publish subscribe event notification is used by the model to let the views know about changes. The main motivation is to allow multiple different views for the same data. What does this have to do with web apps? Most web apps don&#8217;t need change notifications in the form of server push. The point here is that the UI is tightly coupled to the model but the model has no direct dependency on the UI. The model is there to serve the needs of the UI but is not impacted by its implementation. The UI can change independent of the model. If the UI needs some particular new data then it will be added to a resource or if appropriate a new type of resource will be created. If a resource changes, it&#8217;s URL renamed or is removed it will likely break existing UI. To me this is the nature of applications. This is why the first option above (the details page knowing how to create the data URL) seems OK to me. </p>
<p>It may be better if the data resource described how to create the URL. It could provide the full URL for the benefit of the assumed generic clients and in addition provide a pattern plus the identifying parts. For example: rel = details, url = /api/accounts/083249, pattern = /api/accounts/*, id = 083249. The trouble is that the description is most efficiently given in the data resource providing the link (/api/accounts) but it is needed by the UI account details page. </p>
<p>It is pointless to have an API, RESTful or otherwise, without some client but is the arbitrary client a myth? I think it depends on the generality of the API. Clearly the <a href="http://aws.amazon.com/s3/">Amazon S3</a> service is very general and can be used by many different kinds of clients. If the data resources come about as part of building a specific web application then they are probably very specific to that UI. While other clients are possible they would probably end up being similar to the original web app or require changes to the data resources. This is a case of different UIs having different needs of its data model. </p>
<p>Is there a general client &mdash; one that can consume in a useful way my REST API as well as yours? For this to work the client and services would have to have a shared understanding of some content type. For the client to provide a UI the content type would need to declare the UI. There is such a client and content type. Its the web browser and HTML. Now we have come full circle and can see the problems. HTML has not kept up with the demands of rich efficient user interactions and does not allow separation of the view and model.  HTML 5 and XForms may be addressing these issues. (I have only read parts of the HTML 5 Draft and its been a long time since I read XForms.) Should HTML be providing a rich set of built in functionality or a minimal set that can be composed with scripting to accomplish the desired rich interaction? Going back to my <a href="http://hardlikesoftware.com/weblog/2009/04/19/html-is-the-assembly-language-of-the-web/">HTML is the assembly language of the web</a> analogy, do we want a <a href="http://en.wikipedia.org/wiki/Complex_instruction_set_computer">CISC</a> or <a href="http://en.wikipedia.org/wiki/Reduced_instruction_set_computer">RISC</a> architecture?</p>
<p>How are you creating RESTful web apps today?</p>
]]></content:encoded>
			<wfw:commentRss>http://hardlikesoftware.com/weblog/2009/04/30/apis-uis-and-rest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Comments on &#8220;Life above the Service Tier&#8221;</title>
		<link>http://hardlikesoftware.com/weblog/2009/03/29/comments-on-life-above-the-service-tier/</link>
		<comments>http://hardlikesoftware.com/weblog/2009/03/29/comments-on-life-above-the-service-tier/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 01:37:09 +0000</pubDate>
		<dc:creator>John Snyders</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://hardlikesoftware.com/weblog/2009/03/29/comments-on-life-above-the-service-tier/</guid>
		<description><![CDATA[I have read Life above the Service Tier a few times now. Its a very good paper, one that really changes your perspective, but I wish it was better. If you work on web applications and you haven&#8217;t read this paper I recommend that you go read it now &#8212; but do come back.
I agree [...]]]></description>
			<content:encoded><![CDATA[<p>I have read <a href="http://wisdomofganesh.googlegroups.com/web/Life%20above%20the%20Service%20Tier%20v1_0.pdf?gda=Nv7wYlUAAAA7JDdZD1a-BDzD5sYQ744svpECuJPYIMF88qoPNmMCY2G1qiJ7UbTIup-M2XPURDSvSDIn6_qL-1shZ2EKZVD1L0v2IQgNlBgFgkB5kjcnzc6FzIN9stoJdub5wM938eo">Life above the Service Tier</a> a few times now. Its a very good paper, one that really changes your perspective, but I wish it was better. If you work on web applications and you haven&#8217;t read this paper I recommend that you go read it now &mdash; but do come back.</p>
<p>I agree with the overall reasoning and the conclusion. </p>
<blockquote><p>So one obvious way to correct the thin client architecture is to implement a true MVC framework on the client side&#8230; That means that all &#8220;Presentation Flows&#8221; must occur within the currently ­loaded web page&#8230; So one workable model is the Single Page Application (SPA).
</p></blockquote>
<p>First let me get some minor complaints out of the way.</p>
<p><span id="more-78"></span></p>
<p>The paper tries to be fair to <a href="http://en.wikipedia.org/wiki/REST">REST</a> but it gets some things wrong. The mapping of CRUD verbs  on to HTTP methods is as follows:</p>
<ul>
<li>Create is done with PUT or POST depending on the relation between the entity to create and the URI.</li>
<li>Retrieve as well as search and find is done with GET. Search should not be done with POST.</li>
<li>Update is done with PUT</li>
<li>Delete is done with DELETE</li>
</ul>
<p>It has a definite bias against JSON based on it not having a schema. But there is a proposed <a href="http://json-schema.org/">JSON Schema</a> and the author seems to have updated his <a href="http://wisdomofganesh.blogspot.com/2008/11/json-schema-is-game-changer.html">view</a> on this matter. It seems contradictory to me to say REST is valid but XML is the only representation that is acceptable. What would be wrong with microformats in HTML or CSV for example? Any well defined format should be OK &mdash; thats the whole point of constrained content types. Using the X in AJAX as justification for using XML shows outdated thinking. Current usage of ajax is not as an acronym but a term referring to an architectural style for web apps leveraging a wide range of technologies.</p>
<p>The description of the POST-Redirect-GET pattern is very good but I don&#8217;t agree with the conclusion: &#8220;Although ingenious, the POSTRedirectGET pattern is mere bandaid over the fractured web architecture.&#8221; I consider the POST-Redirect-GET pattern (I call it redirect after post) to be the way the web is intended to work and I&#8217;m still baffled that its use is not wide spread.</p>
<p>The superficial differences between thin and rich clients should be updated. The offline distinction of rich clients starts to go away thanks to <a href="http://code.google.com/apis/gears/">Gears</a> and related features of HTML5. The footprint of thin clients is going up as they use more and more JavaScript libraries.</p>
<p>I think the claim that Front Controller is an anti-pattern should be backed up. Give more background on what Front Controller and MVC patterns are and justify why Front Controller is an anti-pattern. Not having this rigor makes it harder to believe the conclusions. The <a href="http://en.wikipedia.org/wiki/Design_Patterns_(book)">Design Patterns</a> book does not list MVC as a pattern but does note that it is made up of other patterns including Observer, Composite, and Strategy. I think the most important part of MVC is the decoupling of the model and view. The main pattern involved in this separation is Observer. But the Observer pattern, where views get notifications when the data changes, doesn&#8217;t work well across the web. So there must be some other benefit to the separation of model and view. This paper describes the benefits in terms of Presentation Flow and Data Interchange separation. Laying the blame on Front Controller doesn&#8217;t seem fair. As far as I know Front Controller doesn&#8217;t say anything about the combination or separation of model and view. It is simply about combining common precessing in one place and dispatching to command processors for specific processing. It made sense given the state of web app architecture at the time. Perhaps Front Control means <a href="http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html">Model 2</a> in the context of this paper. I never did understand how server side framework&#8217;s, such as Struts, can claim to be an MVC architecture or more generally I don&#8217;t agree that Model 2 is MVC.</p>
<p>The two more fundamental issues I have with the paper are:</p>
<ul>
<li>The insistence on a schema for the model.</li>
<li>Too many implementation issues left unanswered.</li>
</ul>
<p>I&#8217;ll discuss these in order.</p>
<p>My background and experience is in creating web applications. Functionality, usability and performance are the most important factors (along with time to market) driving the design. I have not had any direct experience with <a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">SOA</a>. One aspect of SOA is loose coupling between systems. The loose coupling motivates a strong contract. In my experience the presentation layer (a.k.a UI) of an application has tight coupling with its model. For this reason I don&#8217;t have a problem with the data that flows between the UI and model not having a schema. At some point the underlying data will likely have a schema or some formal description, for example a database schema. Way back when I worked on desktop apps there was the notion of an intermediate model between the view and the underlying data store. Now this intermediate model is delivered as a REST resource and it is in direct support of the presentation layer. It satisfies the needs of the presentation layer &mdash; not the other way around. A simple change to the UI can result in a need to rewrite the contract with the data model. The overhead in maintaining the contract must be considered. </p>
<p>So I could be all wrong about this. My experience could be too limited and there are cases where you want a firm contract between the presentation and the data. If so then SOA makes a lot of sense. I&#8217;m not trying to say anything negative about SOA. It seems to me that the insistence on schema is more a motivation for SOA than anything else. Without it I would still draw the same conclusion, as <a href="http://www.tiddlywiki.com/">others</a> have done, that a single page app (i.e. move the controller to the client) is a good idea. Is the principal of statelessness from REST enough motivation in itself to draw the conclusion that the controller needs to move to the browser?</p>
<p>The paper ends with a list of principals for the SOFEA model and an example but a number of tough issues and details are left out. Some of these issues apply to ajax techniques in general. In the traditional web app architecture you can always choose not to use a particular ajax technique if it causes a problem but when your application architecture requires ajax at a fundamental level these issues must be addressed.</p>
<p>The first two issues are about accessibility. A single page app (SPA) relies on JavaScript. What about users who disable JavaScript or browsers that don&#8217;t provide JavaScript. Is it reasonable in this day and age for web apps to require JavaScript or should you try to make your app accessible to as many user agents as possible? What about the principals of unobtrusive JavaScript (UJS), is it easier to apply when the app uses multiple pages (traditional server controlled presentation flow) rather than a single page. </p>
<p>A SPA also makes dynamic changes to the DOM which causes trouble for assistive technologies. Is it a matter of assistive technologies needing to catch up? Do we wait for WAI-ARIA to come to the rescue? If you are designing for the future or your users are on the cutting edge (or you don&#8217;t have users with disabilities) then this may be a non issue. If your app has strong accessibility requirements including legacy software support then a SPA is out of the question.</p>
<p>Is this architecture appropriate for all kinds of web apps or not? In which cases does it apply? For example does it apply to web sites. This brings up the old debate about the distinction between web apps and web sites.</p>
<p>Does putting a controller inside a web page break the way the web is supposed to work. There are issues with bookmarking, and the back button that must be addressed. </p>
<p>What if the app is too big to fit in a single page? Sure you can grab bits of the HTML structure as needed but how will this impact search engine spiders? </p>
<p>There are many implementation details to solve in creating a MVC framework in the browser. The paper bemoans the proliferation of web frameworks but this architecture and ajax in general have enough challenges to ensure that there will be an equal or greater number of client side frameworks. How do we keep from making the same mistakes that were made server side? For example some client side libraries for templating are sprouting up and they seem to be making the same lack of model view separation mistake that server side template engines made. In a previous <a href="http://hardlikesoftware.com/weblog/2008/02/15/script-injection-and-stringtemplate/">post</a> I asked &#8220;Is there a need for a JavaScript implementation of StringTemplate?&#8221; I think the answer is a clear yes. However, templating is just one way to get the data back into the view. Another option is directly injecting each data value into the DOM. What are the pros and cons of each method?</p>
<p>Is SPA the only way to move the controller and state to the client? The paper also mentions frames as a potential solution. Would local storage such as Gears work with multiple pages each making a separate request for its data satisfy the principals of SOFEA? The conversational state is kept in local storage. Separating the data from the view and having multiple pages has the disadvantage of increasing the number of requests at least until the view pages get cached. This means it is even more important to give the static view pages a far future expiration date.</p>
<p>Another issue is localization of text strings. In traditional web apps this was done as part of the same templating that merged the data in with the markup. This seemed reasonable at the time but text translation is very different from data access. The application data is likely to change frequently whereas the text translations rarely ever change. Would the principals of SOFEA recommend that text localization be done on the client side as well? As far as I can tell it makes no recommendation in this area. As long as the data and view are separate it shouldn&#8217;t care if the translation is done on the server.  But running the otherwise static view markup through a template engine just to do text localization seems silly. Why not pre-translate the view and store it on the server?</p>
<p>I&#8217;ll stop now before I ware out my question mark key.  Wait, one more: How are you solving these issues?</p>
]]></content:encoded>
			<wfw:commentRss>http://hardlikesoftware.com/weblog/2009/03/29/comments-on-life-above-the-service-tier/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Time to get serious about JavaScript</title>
		<link>http://hardlikesoftware.com/weblog/2008/08/22/time-to-get-serious-about-javascript/</link>
		<comments>http://hardlikesoftware.com/weblog/2008/08/22/time-to-get-serious-about-javascript/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 01:34:36 +0000</pubDate>
		<dc:creator>John Snyders</dc:creator>
				<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://hardlikesoftware.com/weblog/2008/08/22/time-to-get-serious-about-javascript/</guid>
		<description><![CDATA[[This originally appeared on my dev2dev blog 16-Nov-2007]
Making web applications today means incorporating some amount of ajax and that means using JavaScript. Here are some pointers for bringing good engineering practices to JavaScript.

Making web applications today means incorporating some amount of ajax and that means using JavaScript. Yes there are some other options like GWT [...]]]></description>
			<content:encoded><![CDATA[<p>[This originally appeared on my dev2dev blog 16-Nov-2007]<br />
Making web applications today means incorporating some amount of ajax and that means using JavaScript. Here are some pointers for bringing good engineering practices to JavaScript.<br />
<span id="more-54"></span><br />
Making web applications today means incorporating some amount of ajax and that means using JavaScript. Yes there are some other options like GWT or Flash but I&#8217;ll assume for whatever reason we have decided to take the ajax path. </p>
<p>JavaScript has suffered some prejudice but that is starting to change. It really is a likable language once you get to know it. Back when JavaScript was used for simple things like validating fields developers wrote quick and dirty JavaScript or copied from others that had done the same. Rather than write in a JavaScript style they carried over the style of whatever language they were using. </p>
<p>The realization that doing web apps means doing JavaScript made it clear to me that I need to learn JavaScript well and that JavaScript code deserves the same engineering practices used for server side code &#8211; use coding conventions, document it, check it, test it, and &#8220;build&#8221; it.</p>
<p>Even if you plan on using drop in widgets at some point you will need to do some debugging or glue different things together. You&#8217;ll need to learn the new style of JavaScript programming in order to read the source for the libraries you are using.</p>
<p>I&#8217;m in the process of relearning JavaScript. To this end I have found <a href="http://javascript.crockford.com/">Douglas Crockford&#8217;s</a> site and the <a href="http://developer.mozilla.org/en/docs/JavaScript">Mozilla developer</a> site very useful.</p>
<p>I agree with these <a href="http://javascript.crockford.com/code.html">coding conventions</a> except I add the type attribute to the script element because it is a simple thing to do to appease the HTML validators. Adjust the indent and bracket style to your taste &#8211; just be consistent.</p>
<p>There is a JavaDoc equivalent for JavaScript called <a href="http://jsdoctoolkit.org/">JSDoc</a> (there are other implementations). I have only started to try it out. Getting this formal is more important if you are making a reusable library. But isn&#8217;t it the hope of all code to be reused?</p>
<p>Using JSLint can help catch errors and should be used. In the next post I&#8217;ll describe how I got it integrated with Ant.</p>
<p>There is a testing framework called (no surprise) <a href="http://www.jsunit.net/">jsunit</a>. So far I have only used its core for asserts. If not this then build your own test framework.</p>
<p>JavaScript source should be organized into meaningful modules (files) and have plenty of comments and whitespace. The browser doesn&#8217;t need the comments so it is a waste of bandwidth to send them. It also doesn&#8217;t care if your variable name is 1 character or 20. There are a few minifiers that will make the JavaScript files smaller. It is also more efficient for the browser to get one file rather than many. JavaScript files should be aggregated into just a few files and then minified. This is what I meant by &#8220;build&#8221; it.</p>
<p>How are you treating JavaScript seriously?</p>
]]></content:encoded>
			<wfw:commentRss>http://hardlikesoftware.com/weblog/2008/08/22/time-to-get-serious-about-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

