<?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>overwatering &#187; web</title>
	<atom:link href="http://www.overwatering.org/blog/category/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.overwatering.org/blog</link>
	<description>Random musings on fish, books and occasionally programming.</description>
	<lastBuildDate>Mon, 07 Nov 2011 07:06:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Lessons from a Pure JavaScript Project: CoffeeScript</title>
		<link>http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project-coffeescript/</link>
		<comments>http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project-coffeescript/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 06:18:30 +0000</pubDate>
		<dc:creator>giles</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[jasmine]]></category>

		<guid isPermaLink="false">http://www.overwatering.org/blog/?p=396</guid>
		<description><![CDATA[This is the second post in a series on observations and questions from implementing a single page pure JavaScript web application for a recent project. For background and the other posts in this series, see the introduction

Before joining this project I spent two weeks on another project helping them make a technology decision. This other [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second post in a series on observations and questions from implementing a single page pure JavaScript web application for a recent project. For background and the other posts in this series, see the <a href="http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project/">introduction</a></p>

<p>Before joining this project I spent two weeks on another project helping them make a technology decision. This other project had a requirement for a sophisticated web UI. The choices were Flash or JavaScript. After helping with some spikes the team decided to use JavaScript. As this would be the first time anyone on the team would be using JavaScript, I made some recommendations. One of these was not to use <a href="http://jashkenas.github.com/coffee-script/">CoffeeScript</a>.</p>

<p>I was wrong.</p>

<p>It was a new project with a team of people who weren&#8217;t very familiar with JavaScript and certainly had not written a large JavaScript application. I felt that CoffeeScript would be another new thing for what until very recently had been a Java team. It would be better to first learn JavaScript; understand that and then learn how CoffeeScript can make the language better.</p>

<p>After that short consulting gig, I started on this project on the following Monday. This was another sophisticated JavaScript UI application. But it was already about two months into development. This project had already decided not to use CoffeeScript, for similar reasons as I&#8217;d gone through on the previous Friday. It was like jumping forward in time two months. More than anything else, with the amount of JavaScript code we had, the syntax was just agony. It simply made the code harder to read. This may sound like a small detail, but I believe very strongly that code needs to be readable by humans above everything else. JavaScript&#8217;s syntax is simply woefully inappropriate for the style of programming the language is otherwise very tuned for.</p>

<p>As I mentioned above, we used <code>underscore.js</code> pretty heavily. This encourages a lot of anonymous functions passed as parameters, something that reads very nicely in Ruby. In JavaScript, a simple loop to lowercase every string in an array reads pretty painfully.</p>

<pre><code>var keyNames = _.map(recipientNames, function(name) {
  return name.toLowerCase();
});
</code></pre>

<p>By the way, the glyph <code>});</code> is henceforth known as the coffee-break.</p>

<p>The absolute bare minimum for a lambda is <code>function() { return; }</code>. That&#8217;s 19 characters! 19! Here&#8217;s the same code in CoffeeScript:</p>

<pre><code>keyNames = _.map recipientNames, (name) -&gt; name.toLowerCase()
</code></pre>

<p>That is one plausible line. Yes please, can I have some more? This may seem like a small detail on its own. It&#8217;s just syntax, you say. You may disagree with my opinion that syntax is critical. Allow me to offer another example from this project. A couple of us are Ruby programmers, and fans of the very declarative style of test that is possible in RSpec, using <code>let</code>.</p>

<pre><code>describe "an account" do
  let(:subject) { Account.new(:balance =&gt; balance) }
  describe "positive balance" do
    let(:balance) { 100 }
    it "should allow withdrawals" …
  end
end
</code></pre>

<p>The JavaScript unit testing library of choice, <a href="http://pivotal.github.com/jasmine/">Jasmine</a> doesn&#8217;t (yet) include any equivalent of this. So I whipped something up pretty quickly to allow the equivalent:</p>

<pre><code>describe("an account", function() {
  define({subject: function(ctxt) { return createAccount({balance: ctxt.balance()}); }}, function(ctxt) {
    describe("positive balance", function() {
      define(ctxt, {balance: function() { return 100; }}, function(ctxt) {
        it("should allow withdrawals", function() { …; });
      });
    });
  });
});
</code></pre>

<p>There are two problems here. Firstly, JavaScript doesn&#8217;t have <code>instance_eval</code> or <code>method_missing</code> so you can&#8217;t decorate a lexical scope before passing it downwards, hence explicitly passing down the <code>ctxt</code> parameter. Actually, while the lack of <code>method_missing</code> is a real pain, I think <code>instance_eval</code> is no great loss and I would happily write much, much code in a language that doesn&#8217;t allow libraries to mess with name bindings quite so liberally.</p>

<p>Secondly, the sheer noise of the JavaScript syntax is incredibly painful. Here is the equivalent, translated directly into CoffeeScript.</p>

<pre><code>describe "an account", -&gt;
  define
    subject: (ctxt) -&gt; createAccount balance: ctxt.balance()
  , (ctxt) -&gt;
    describe "positive balance", -&gt;
      define ctxt,
        balance: -&gt; 100
      , (ctxt) -&gt;
        it "should allow withdrawals", -&gt; … 
</code></pre>

<p>The most interesting thing from this conversion, to me, is that it shows that the double-nesting of <code>define</code>s and <code>describe</code>s is actually pretty unclear. In my copious spare time I&#8217;m working on a better implementation of that <code>define()</code> function, in the hope of getting it added to Jasmine. If I&#8217;d been staring at that second version throughout the project I would have started down that path earlier.</p>

<p>But the better syntax is not everything; the other features in CoffeeScript, like list comprehensions and default arguments are Good Things and would have been very nice to have.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project-coffeescript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons from a Pure JavaScript Project</title>
		<link>http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project/</link>
		<comments>http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 05:59:01 +0000</pubDate>
		<dc:creator>giles</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[jasmine]]></category>

		<guid isPermaLink="false">http://www.overwatering.org/blog/?p=394</guid>
		<description><![CDATA[Our team is wrapping up the first release of a pure JavaScript, single page web application. No one on the team has ever built one of these before and it seems they are becoming the new hotness, so I thought it would be useful to attempt to write down some observations and questions. Hopefully, you [...]]]></description>
			<content:encoded><![CDATA[<p>Our team is wrapping up the first release of a pure JavaScript, single page web application. No one on the team has ever built one of these before and it seems they are becoming the new hotness, so I thought it would be useful to attempt to write down some observations and questions. Hopefully, you can learn something and I can be pointed in the direction of doing it better next time.</p>

<p>The application is a mobile web app for a customer who already has a number of native apps for iPhone and Android. All these apps use an existing set of services to access the core data. Our app used <a href="http://jquerymobile.com/">JQuery Mobile</a> and <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> as the only libraries. For testing, we used <a href="http://pivotal.github.com/jasmine/">Jasmine</a> and <a href="http://cukes.info/">cucumber</a>.</p>

<p>Originally, I wanted to post this as a single post, but it go long. Very long. Looking back on our project, there were four things I&#8217;d like to try doing differently.</p>

<ul>
<li><p><a href="http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project-coffeescript/">We didn&#8217;t use CoffeeScript</a> for what felt like very good reasons at the time. In hindsight, this was a mistake.</p></li>
<li><p>Writing functional tests for a pure JavaScript application is a different problem requiring different solutions than a typical web application.</p></li>
<li><p>Your JavaScript application is going to end up as a very sophisticated GUI application, with more complex state and flow management than most typical web applications. Consider your use of models and controllers very seriously.</p></li>
<li><p>Web applications have long had to deal with the Back and Refresh browser buttons. A single page JavaScript application adds some new wrinkles. But I think that HTML 5 also includes some neat solutions.</p></li>
</ul>

<p>As I get my posts written, I&#8217;ll update the above with links.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overwatering.org/blog/2011/10/lessons-from-a-pure-javascript-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links in Tweets</title>
		<link>http://www.overwatering.org/blog/2009/04/links-in-tweets/</link>
		<comments>http://www.overwatering.org/blog/2009/04/links-in-tweets/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 03:43:54 +0000</pubDate>
		<dc:creator>giles</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.overwatering.org/blog/?p=149</guid>
		<description><![CDATA[There is currently some discussion about the dangers of URL shorteners. Joshua Schachter points out that shortened URLs damage the web &#8211; the &#8216;hypertext as engine of application state&#8217; part of it. David Weiss points out the security concerns &#8211; phishing and a single compromisable point.

In this conversation most people point out that URL shorteners [...]]]></description>
			<content:encoded><![CDATA[<p>There is currently some discussion about the dangers of URL shorteners. <a href="http://joshua.schachter.org/2009/04/on-url-shorteners.html">Joshua Schachter</a> points out that shortened URLs damage the web &#8211; the &#8216;hypertext as engine of application state&#8217; part of it. <a href="http://unweary.com/2009/04/the-security-implications-of-url-shortening-services.html">David Weiss</a> points out the security concerns &#8211; phishing and a single compromisable point.</p>

<p>In this conversation most people point out that URL shorteners have proliferated because of the popularity of <a href="http://twitter.com">Twitter</a>. <a href="http://www.kottke.org/09/04/url-shorteners-suck">Kottke</a> has now proposed that Twitter run a URL shortener of their own. Which seems eminently sensible, given the current state.</p>

<p>I&#8217;ve got a different suggestion: Twitter should actually let me use the <code>&lt;a&gt;</code> anchor tag in my tweets. Just like I&#8217;ve been doing in HTML for as long as the web has been around. That is, the URL in your tweet should not contribute to the number of characters in your tweet, and it should also not be visible. Instead it should be attached to a word, phrase or perhaps the entire tweet. This should be optional: without markup URLs pasted into tweets should maintain the status quo.</p>

<p>Of course, no other forms of HTML markup should be supported: linking would be enough. The Twitter web site and desktop and custom phone clients would have no problem rendering a link. Only SMS clients would have a problem, and for these perhaps the fallback is to shorten the URL using Twitter&#8217;s own URL shortener and insert that into the tweet. SMS clients may not be that <a href="http://www.neoformix.com/2008/TwitterClientUsage.html">common</a> for much longer.</p>

<p>Assuming Twitter allows specific parts of the tweet to be marked up, then I suggest <a href="http://daringfireball.net/projects/markdown/">Markdown</a> syntax for the link. <a href="https://twitter.com/gga/status/1454868052">This recent tweet</a> would have been typed out as:</p>

<pre><code>I unplugged every landline phone in our office
because of [marketers](http://sethgodin.typepad.com/seths_blog/2009/04/poisoning-the-well.html) (via @misswired)
</code></pre>

<p>Which would have appeared as:</p>

<blockquote>
  <p>I unplugged every landline phone in our office because of <a href="http://sethgodin.typepad.com/seths_blog/2009/04/poisoning-the-well.html">marketers</a> (via <a href="http://twitter.com/misswired">@misswired</a>)</p>
</blockquote>

<p>Which is what I was actually trying to say.</p>

<p>Of course allowing link markup like this is going to be very popular with spammers. Two counters:</p>

<ol>
<li>Twitter should include <code>rel="nofollow"</code> on links when rendering &#8211; as they already do.</li>
<li>Don&#8217;t allow targeted markup like this, instead allow the entire Tweet to be marked up &#8211; only one link per tweet. The disadvantage with this is that sometimes I want more than one link, and the appropriate rendering is not obvious.</li>
</ol>

<p>Both targeted markup and one-link-per-tweet have advantages and disadvantages, I&#8217;ll leave it up to Twitter to choose between them. But please, give me back my <code>&lt;a&gt;</code> anchors.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overwatering.org/blog/2009/04/links-in-tweets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

