<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>programming-languages &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/programming-languages/</link>
	<description>Feed of posts on WordPress.com tagged "programming-languages"</description>
	<pubDate>Fri, 04 Dec 2009 12:59:55 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[We call it OPA]]></title>
<link>http://dutherenverseauborddelatable.wordpress.com/2009/11/28/we-call-it-opa/</link>
<pubDate>Sat, 28 Nov 2009 19:15:55 +0000</pubDate>
<dc:creator>yoric</dc:creator>
<guid>http://dutherenverseauborddelatable.wordpress.com/2009/11/28/we-call-it-opa/</guid>
<description><![CDATA[Web applications are nice. They&#8217;re useful, they&#8217;re cross-platform, users need no install]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;">Web applications are nice. They&#8217;re useful, they&#8217;re cross-platform, users need no installation, no upgrades, no maintenance, not even the computing or storage power to which they are used. As weird as it may sound, I&#8217;ve even seen announcements for web applications supposed to run your games on distant high-end computers so that you can actually play on low-end computers. Go web application!</p>
<p style="text-align:justify;">Of course, there are a few downsides to web applications. Firstly, they require a web connexion. Secondly, they are largely composed of <em>plumbing</em>. Finally, ensuring their security is a constant fight.</p>
<p><!--more--></p>
<h3>How many pipes do you need?</h3>
<p style="text-align:justify;">If you have ever developed a web application, you know what I mean by plumbing: just writing an online TODO list &#8212; the equivalent of maybe twenty minutes of work in Visual Basic, in Python, Java or Objective-C &#8212; requires mixing an insane amount of languages, to define your user interface (HTML, JavaScript, CSS), to define your storage (DDL, DML, DCL, plus possibly an ORM language), to get your server and your client to communicate (XML, more JavaScript, PHP or one of its competitors, as well as some HTTP and a little MIME configuration), to launch your application (whichever configuration languages are used by your server). Of course, if your application is a bit more complex and requires something like compatibility with smartphones, or like distant storage, or distributed computing, or backups, or modularity (in the world of the web, it&#8217;s called &#8220;web services&#8221;)&#8230; well, you will probably require a few additional languages.</p>
<p style="text-align:justify;">All of this is just <em>plumbing</em>. Only once you have written it can you concentrate on the core of the application. And once the application is written, the pain is just starting, because chances are that your application can be attacked by hijacking the link between your user interface and the core (cross-site scripting) or between the core and the storage (SQL injection) or by keeping the user interface and replacing the application core (man-in-the-middle attacks) or by replacing the user interface by a malicious client or by taking the place of a currently connected user to steal some of its credentials (rebinding) or by taking advantage of low-level bugs (buffer over/underflows), etc.</p>
<p style="text-align:justify;">None of this is a show-stopper, of course &#8212; just take a look at the web and you will see thousands of web applications. Just like the complexity of Software Development Kits in the early days of Windows, MacOS or X didn&#8217;t stop adventurous hackers from developing desktop applications. But of course, if twenty-five years of desktop application development have taught us one thing, it is that the life of developers can be made easier. Nowadays, a few generations of SDKs later, Windows developers have .Net, C# and Visual Studio, Macintosh developers have Cocoa, Objective-C and XCode, while X-based developers have the libraries of Gnome/KDE, Python and a variety of programming environments. The growing popularity (and libraries) of Haskell, F#, OCaml, Scala and other functional programming languages could mean that one of the next generations of SDKs will increase safety and security.</p>
<p style="text-align:justify;">The web hasn&#8217;t quite reached that stage yet. Even the state-of-the-art in web frameworks only provides features slightly more advanced than early Windows/Mac/X SDKs: low-level bindings for low-level mechanisms, designed to ensure low-level properties. Or, rephrased differently, in the current state of web development, GMail, Google Maps or Facebook are still considered complicated applications, although they are conceptually quite simple and should therefore be equally simple to implement.</p>
<p style="text-align:justify;">We can do better. How? By removing the need for plumbing. By providing automated mechanisms for ensuring high-level security properties. By providing language support for common patterns.</p>
<h3>Enter OPA</h3>
<p style="text-align:justify;">Let me introduce OPA. OPA, or One Pot Application, is a complete development platform for web applications and web services. Development in OPA requires no plumbing. Applications developed with OPA are automatically checked for safety and security before they are executed. Applications developed with OPA are automatically (and provably) immune to cross-site scripting, to SQL injections and to most existing forms of attacks. And OPA provides language support for storage, communication between client and server (Ajax and Comet), concurrency, distribution, mobility, etc.</p>
<p style="text-align:justify;">With OPA, we intend to skip several generations of SDKs and provide right now a high-level and modern programming platform. OPA has been 6 years in the making: 4 years of sketches, mockups and prototypes as part of academic research projects and 2 years of actual implementation at <a href="http://www.mlstate.com">MLstate</a>. A few days ago, OPA has officially entered <em>demonstrable</em> status. Not quite ready for prime time, but definitely usable for development. Do you want to write an online note-taking application? That&#8217;s about 20 lines of code, from scratch. A minimal chat? About 30 lines. A multi-channel, distributed chat? About 80 lines. A minesweeper? About 100. We&#8217;re using it to develop utilities, content management systems, tools for administrations and games.</p>
<p style="text-align:justify;">Pre-alpha builds of OPA have been distributed to selected partners. A public version will be made available within a few weeks, as well as commercial applications developed with OPA. In the meantime, we are busy improving the syntax, completing the standard library, making error messages intelligible, fixing the bugs and extending the range of safety and security checks.</p>
<p style="text-align:justify;">Interested? Well, few details are public at this time. However, you can take a look at <a href="http://vidiowiki.com/watch/t53c29y/">a video</a> recorded during ICFP presenting OPA and MLstate.</p>
<p style="text-align:justify;">Stay tuned.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Developing an ActiveMQ C++ JMS Client for Mac OS X]]></title>
<link>http://jeboyer.wordpress.com/2009/11/28/developing-a-activemq-c-jms-client-for-mac-os-x/</link>
<pubDate>Sat, 28 Nov 2009 15:50:03 +0000</pubDate>
<dc:creator>jeboyer</dc:creator>
<guid>http://jeboyer.wordpress.com/2009/11/28/developing-a-activemq-c-jms-client-for-mac-os-x/</guid>
<description><![CDATA[I&#8217;m switching gears in this post to discuss my experience with installing and integrating Apac]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="clear:both;">I&#8217;m switching gears in this post to discuss my experience with installing and integrating <a href="http://activemq.apache.org/">Apache ActiveMQ&#8217;s</a> C++ client library with Objective-C. <strong>ActiveMQ</strong> is an open-source message broker, for Windows and UNIX, from the <a href="http://www.apache.org/">Apache Software Foundation</a>.</p>
<p style="clear:both;">Topics covered:</p>
<ul style="clear:both;">
<li>Intro to ActiveMQ</li>
<li>Installing ActiveMQ C++ Client Libraries</li>
<li>Integrating ActiveMQ C++ with Objective-C</li>
</ul>
<p style="clear:both;">In previous posts, I cover iPhone development topics for a prototype I&#8217;m working on. Yet, my iPhone app is only one client in a larger <a href="http://en.wikipedia.org/wiki/Software_as_a_service">software as a service (SaaS)</a> prototype. The plan is to have the SaaS system support clients across other popular mobile platforms and desktop operating systems such as <a href="http://en.wikipedia.org/wiki/Mac_OS_X">Mac OS X</a> and <a href="http://en.wikipedia.org/wiki/Microsoft_Windows">Windows</a>.</p>
<p style="clear:both;">In this heterogeneous computing environment, some of my components need to reliably send and receive messages. So, adding a <a href="http://en.wikipedia.org/wiki/Message_broker">message broker</a> to the mix makes sense. However, for a prototype, buying a commercial product such as IBM&#8217;s WebSphere MQ is out-of-the-question. Consequently, I chose <a href="http://activemq.apache.org/">Apache ActiveMQ</a>.</p>
<blockquote>
<p style="clear:both;"><strong>Apache ActiveMQ</strong> is an open source message broker which fully implements the Java Message Service 1.1 (JMS). It provides &#8220;Enterprise Features&#8221; like clustering, multiple message stores, and availability to use any database as a JMS persistence provider besides VM, cache, and journal persistency.</p>
<p>Apart from Java, ActiveMQ can be also used from .NET, C/C++ or Delphi or from scripting languages like Perl, Python, PHP and Ruby via various &#8220;Cross Language Clients&#8221; together with connecting to many protocols and platforms.</p>
<p style="clear:both;">Apache ActiveMQ. (2009, November 26). In Wikipedia, The Free Encyclopedia. Retrieved 23:00, November 26, 2009, from http://en.wikipedia.org/w/index.php?title=Apache_ActiveMQ&#38;oldid=328100430</p>
</blockquote>
<p style="clear:both;">Installing ActiveMQ is easy. Writing Java clients is straightforward. However, I have a native Mac OS X client (written in Objective-C) that needs to process messages. Fortunately, ActiveMQ has a C++ client library or <a href="http://activemq.apache.org/cms/">CMS</a>, which stands for <strong>C++ Messaging Service;</strong> and since Xcode supports <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCPlusPlus.html">Objective C++</a> (mixing Objective-C and C++) I have a solution for integrating my client with ActiveMQ.</p>
<p style="clear:both;">Installing CMS on a UNIX-based system is not as easy as installing the ActiveMQ server. There are some hoops to jump through.</p>
<ol style="clear:both;">
<li>Download CMS <a href="http://activemq.apache.org/cms/download.html">here</a>.</li>
<li>Follow the README instructions and note that the package is dependent on number of tools and libraries:
<ul style="clear:both;">
<li><em>autoconf</em> version &#62;= 2.61</li>
<li><em>automake</em> version &#62;= 1.10</li>
<li><em>libtool</em> version &#62;= 1.5.24</li>
<li><em>APR version</em> &#62;= 1.3</li>
<li><em>APR-Util</em> version &#62;= 1.3</li>
<li><em>CPPUnit</em> version &#62;= 1.10.2*</li>
<li><em>libuuid</em> version &#62;= ?*</li>
</ul>
</li>
</ol>
<p style="clear:both;">On Mac OS X 10.6.x, I already had <em>autoconf</em>, <em>automake</em>, and <em>libtool</em>. But, I had to install the latter four packages before installing CMS. Each installation follows the same set of standard command lines, check the requisite README for variations:</p>
<ul style="clear:both;">
<li><em>./configure </em></li>
<li><em>make</em></li>
<li><em>make [test or check]</em></li>
<li><em>make install</em></li>
</ul>
<p style="clear:both;">After installing everything, the CMS libraries will be in <em>usr/local/lib</em> and ready to use in Xcode.</p>
<p style="clear:both;">Moving to client development, I had the simple CMS consumer example running straightaway. However, once I began to mix in my Objective-C code, my build was wrought with pre-complier errors of the form: <em>expected &#8216;;&#8217;, &#8216;,&#8217; or &#8216;)&#8217; before &#8216;&#62;&#8217; token</em>.</p>
<p style="clear:both;">Answers to this issue on the web were illusive. But, I knew the root cause was the inclusion of <em>&#60;Foundation/Foundation.h&#62; </em>with my C++. Fiddling with build settings was futile. My workaround, remove all references to <em>Foundation.h</em> and explicitly add only the headers the implementation needs. For example: <em>&#60;Foundation/NSString.h&#62;, &#60;Foundation/NSDate.h&#62;, &#60;Foundation/NSDateFormatter.h&#62;</em><em>&#8230; </em>Works like a charm, but tedious. I wish Xcode had a command analogous to <strong>Organize Imports</strong> in Eclipse.</p>
<p style="clear:both;">In any case, my ActiveMQ Objective C++ client is now working nicely. I hope this info helps some other Xcoder out there.</p>
<p><br class="final-break" style="clear:both;" /></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Optimising Mandelbrot]]></title>
<link>http://developmentjungle.wordpress.com/2009/11/24/optimising-mandelbrot/</link>
<pubDate>Tue, 24 Nov 2009 22:55:31 +0000</pubDate>
<dc:creator>alex</dc:creator>
<guid>http://developmentjungle.wordpress.com/2009/11/24/optimising-mandelbrot/</guid>
<description><![CDATA[In my previous post I showed how I created a Mandelbrot fractal renderer in Clojure, however its per]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img src="http://developmentjungle.wordpress.com/files/2009/11/clojure-mandelbrot-set-preview.png" alt="" title="Clojure Mandelbrot Set" width="222" height="155" class="alignright size-full wp-image-15" />In my previous post I showed how I created a <a href="/2009/11/14/rendering-the-mandelbrot-set-in-clojure/">Mandelbrot fractal renderer in Clojure</a>, however its performance left a lot to be desired. Optimising code is actually a very good way to learn more about a new language as it teaches you what is going on under the hood. In this post, I will go through the steps I took to drastically improve the application&#8217;s performance.</p>
<h2>Inspecting the Code</h2>
<p>The first step when optimising code (after <a href="http://c2.com/cgi/wiki?PrematureOptimization"><em>not</em> optimising</a> of course) is to inspect the code&#8217;s logic and find quick fixes to any obvious potential performance areas. The logic of the Mandelbrot code however is fairly easy to reason about as we have built it up from the mathematical formula. Also, looking for obvious performance issues is difficult in a language you are trying to learn, so it&#8217;s time to break out the tools.<br />
<!--more--></p>
<h2>Profiling</h2>
<p>First of all, let&#8217;s see how long it takes to render our fractal with the current implementation:</p>
<pre class="brush: javafx;">
user=&#62; (time (my-mandelbrot))
&#34;Elapsed time: 29340.692742 msecs&#34;
nil
</pre>
<p>Note, I have undone the premature optimisation I made last time and made the rendering single threaded by replacing <code>pmap</code> with <code>map</code>. This is important when profiling as it ensures we can properly determine which parts of the code are taking the longest. On a quad core cpu, I found that using <code>pmap</code> gave only a 2x speed increase which shows there is quite a lot of overhead in Clojure when processing on multiple threads.</p>
<p>Now at this stage, we have no idea what is taking so long so let&#8217;s run the app through a profiler. As Clojure is hosted on the JVM, it allows us to take advantage of many tools that would normally be used for Java applications. I attached the <a href="https://visualvm.dev.java.net/">VisualVM</a> profiling tool (which now comes with Java 6) to my application and then called <code>my-mandelbrot</code> again from the REPL. This is what I got after running for a few minutes:</p>
<p><img class="aligncenter size-full wp-image-55" title="VisualVM profile of render" src="http://developmentjungle.wordpress.com/files/2009/11/profile-render.png" alt="" width="623" height="298" /></p>
<p>What strikes you when digging through a Clojure call tree is just how deep it can go. It can also be difficult to relate the Java method calls we see back to the original Clojure code. Here I have expanded the calls made within the <code>render</code> function. You can see the two main consumers of CPU time are calls to <code>count</code> and <code>vec</code>. This is surprising as if you have a look at the original <code>render</code> function code, there&#8217;s not a call to either the <code>count</code> or <code>vec</code> functions to be seen:</p>
<pre class="brush: javafx;">
(defn render [xstart ystart xsize ysize width height max-iters wr]
  (dorun
    (map (fn [pixel]
            (let [[x y] pixel]
              (.setPixel wr x y
                (int-array (coord-colour
                  (get-coord (double x) (double y) xstart ystart xsize ysize width height)
                  max-iters)))))
           (get-pixels width height))))
</pre>
<p>In fact, <code>count</code> is called from within the <code>coord-colour</code> function:</p>
<pre class="brush: javafx;">
(defn coord-colour
  &#34;Returns a colour for which to draw the given coordinate. If the coordinate
  is within the mandelbrot set, black is returned. Otherwise, a colour within
  a gradient is given based on the number of iterations of the mandelbrot set
  that have been evaluated.&#34;
  [[xcoord ycoord] max-iters]
  (let [num-iters (count (take max-iters (take-while #(&#60;= (mag %) 4) (mandelformula xcoord ycoord))))]
    (if (= max-iters num-iters)
      *set-colour*
      (iter-colour num-iters max-iters))))
</pre>
<p>The call to <code>vec</code> is deeper still within the calls to <code>iter-colour</code> and <code>grad-colour</code>:</p>
<pre class="brush: javafx;">
(defn grad-colour
  &#34;Returns the colour that is the given fraction of the way between
  the first and second colours given. Returns as a vector of three
  integers between 0 and 255.&#34;
  [colA colB frac]
  (vec (map #(+ (* frac (- %2 %1)) %1) colA colB)))

(defn iter-colour
  &#34;Returns the colour needed to paint a point with the given number
  of iterations&#34;
  [num-iters max-iters]
  (grad-colour *grad-colour-a* *grad-colour-b*
    (/ (double num-iters) max-iters)))
</pre>
<p>The reason we see the <code>count</code> and <code>vec</code> calls at the level of the <code>render</code> function is that Clojure (or perhaps the hotspot) appears to inline certain function calls into the calling function. You can see further evidence of this in the above screenshot if you have a look at the <code>divide</code>, <code>add</code> and <code>multiply</code> methods. These are the operations performed by the <code>get-coord</code> function:</p>
<pre class="brush: javafx;">
(defn get-coord
  &#34;Returns the coordinates of the given pixel in the complex plane&#34;
  [x y xstart ystart xsize ysize width height]
  [(+ xstart (* (/ x width) xsize))
   (+ ystart (* (/ y height) ysize))])
</pre>
<p>You should also see that at the time of the snapshot I took above, the number of invocations of each of the mathematical operations was around 67k which is twice the number of invocations of the <code>count</code> function which makes sense as you can see they are called once for each of the x and y coordinates.</p>
<p>Let&#8217;s dig deeper into the <code>count</code> function.</p>
<p><a href="http://developmentjungle.wordpress.com/files/2009/11/profile-count.png"><img class="aligncenter size-full wp-image-57" title="VisualVM profile of count (click to enlarge)" src="http://developmentjungle.wordpress.com/files/2009/11/profile-count-crop.png" alt="" width="632" height="381" /></a></p>
<p>As you expand the call tree, and if you ignore the <code>clojure.lang</code> methods, you&#8217;ll see calls to <code>take</code>, <code>take-while</code>, <code>iterate</code> and finally <code>mandelformula</code>. Here&#8217;s another mystery of the Clojure call stack: we have a call to <code>iterate</code> before the call to <code>mandelformula</code> and yet in our code we can see iterate is called <em>within</em> the <code>mandelformula</code> function.</p>
<pre class="brush: javafx;">
(defn mandelformula [xcoord ycoord]
  &#34;Returns an infinite sequence of vectors containing the values of
  successive iterations of the mandelbrot formula, given a point on
  the complex plane.&#34;
  (iterate
    #(vec (map + (mandel %) [xcoord ycoord]))
    [xcoord ycoord]))
</pre>
<p>As far as I can tell, the reason for this is that <code>mandelformula</code> returns a lazy sequence which is not actually evaluated until it is needed. So <code>iterate</code> is used to get the next value in the sequence, while <code>mandelformula</code> actually does the job of calculating what the next value should be.</p>
<p><a href="http://developmentjungle.wordpress.com/files/2009/11/profile-mandelformula.png"><img class="aligncenter size-full wp-image-59" title="Visual VM profile of mandelformula (click to enlarge)" src="http://developmentjungle.wordpress.com/files/2009/11/profile-mandelformula-crop.png" alt="" width="659" height="396" /></a></p>
<p>Drilling down into the <code>mandelformula</code> function we open up a whole can of method calls and it gets suddenly very difficult to map back to the original Clojure code. However we can see there seem to be a large number of sequences created and calls to methods in the <code>clojure.lang.Numbers</code> class taking <code>Objects</code> as their parameters. If we could get the formula to only use primitive types, this could potentially remove a lot of object creation and garbage collection. However, before we start re-working the code, let&#8217;s look at another profiling technique available to us in Clojure.</p>
<h2>Using Clojure Contrib&#8217;s Profile Macros</h2>
<p><a href="http://stuartsierra.com/">Stuart Sierra</a> has made a vast number of contributions to Clojure including the <a href="http://richhickey.github.com/clojure-contrib/profile-api.html">profile</a> library which provides two macros <code>prof</code> and <code>profile</code> to measure the execution time of any block of code. Clojure&#8217;s macro system makes what would normally be a cumbersome task in other languages extremely easy. Let&#8217;s put profiling in our <code>coord-colour</code> function:</p>
<pre class="brush: javafx; highlight: [3,4];">
(defn coord-colour
  [[xcoord ycoord] max-iters]
  (let [num-iters (prof :mandel (count (take max-iters (take-while #(&#60;= (mag %) 4) (mandelformula xcoord ycoord)))))]
    (prof :colour (if (= max-iters num-iters)
      *set-colour*
      (iter-colour num-iters max-iters)))))
</pre>
<p>We simply wrap the block of code we want to profile around a call to the <code>prof</code> macro and specify a keyword to identify that block of code. Calling the <code>profile</code> macro will then summarise the time taken to evaluate each call to those <code>prof</code> blocks and print a bunch of statistics.</p>
<pre class="brush: javafx;">
user=&#62; (time (profile (my-mandelbrot)))
  Name      mean       min       max     count       sum
colour      4875      1117   1091200    300000  1462510112
mandel     71729      2514 100182286    300000 21518722246
&#34;Elapsed time: 31456.673404 msecs&#34;
</pre>
<p>Here we can see that the total time taken by the <code>mandel</code> section of the <code>coord-colour</code> function is around 21 seconds (the values above are in nanoseconds) which gives it 68% of the total running time. The time taken to calculate the gradient colour is about 5% of the total running time. These are quite different statistics from what we saw with VisualVM which gave figures of 60% for the <code>count</code> function and 20% for the calls to <code>vec</code>. The discrepancy is most likely due to the fact that the program did not run to completion when I profiled it with VisualVM. The time taken by the <code>count</code> function depends very much on the number of iterations it executes and during the first 25% of the render, most of its calls finish within 4-5 iterations.</p>
<p>In any case, now that we know the source of the slow performance, let&#8217;s turn our attention to optimisation.</p>
<h2>Back to Primitives</h2>
<p>If we want to eliminate boxed numbers while calculating each term of the Mandelbrot formula, then unfortunately that means we will also have to stop being lazy. It&#8217;s not possible to create a lazy sequence of primitives (just yet). This means we will need to calculate all the terms of the Mandelbrot formula in a single function before returning the number of iterations taken.</p>
<pre class="brush: javafx;">
(defn mandelformula [x0 y0 max-iters]
  &#34;Applies the mandelbrot formula until max-iters iterations
  are reached, or the magnitude of Z exceeds 2&#34;
  (let [x0 (double x0)
        y0 (double y0)
        max-iters (int max-iters)]
    (loop [x (double x0)
           y (double y0)
           n (int 0)]
      (if (== n max-iters)
        n
        (let [mag (+ (* x x) (* y y))]
          (if (&#62;= mag (double 4))
            n
            (let [new-x (+ x0 (- (* x x) (* y y)))
                  new-y (+ y0 (* (double 2) (* x y)))]
              (recur new-x new-y (inc n)))))))))
</pre>
<p>Here is the newly improved function. Note how I explicitly <a href="http://clojure.org/java_interop#toc37">coerce</a> the function parameters to doubles using a <code>let</code>. The intermediate values for each iteration are now defined in a <code>loop</code> and again explicitly coerced. It can be tricky in Clojure to force primitives &#8211; there&#8217;s no static type checking as in Java of course &#8211; but Clojure will throw an exception if you try to pass non-primitive values to a loop that uses coerced parameters. This helps detect the times when Clojure magically autoboxes your primitives behind your back. (One place where I tripped up was thinking that mathematical operators that take multiple arguments would return a primitive when passed primitives, in fact, (* (int 1) (int 2) (int 3)) will return an Integer whereas (* (int 1) (int 2)) returns an <code>int</code>. This is why the calculation of <code>new-y</code> above involves two calls to *).</p>
<p>In the above function, I&#8217;m taking care of calculating all the terms of the mandelbrot formula up to the point where <code>z</code> &#62; 2 or <code>max-iters</code> is reached. This is a bit more than the original <code>mandelformula</code> function so the <code>coord-colour</code> function simplifies to:</p>
<pre class="brush: javafx;">
(defn coord-colour
  &#34;Returns a colour for which to draw the given coordinate. If the coordinate
  is within the mandelbrot set, black is returned. Otherwise, a colour within
  a gradient is given based on the number of iterations of the mandelbrot set
  that have been evaluated.&#34;
  [[xcoord ycoord] max-iters]
  (let [num-iters (mandelformula xcoord ycoord max-iters)]
    (if (= max-iters num-iters)
      *set-colour*
      (iter-colour num-iters max-iters)
      )))
</pre>
<p>Let&#8217;s see what kind of performance we get now.</p>
<pre class="brush: javafx;">
user=&#62; (time (profile (my-mandelbrot)))
  Name      mean       min       max     count       sum
colour      5179      1117   1593220    300000  1553876060
mandel      1787      1396    137448    300000  536248035
&#34;Elapsed time: 10177.274766 msecs&#34;
</pre>
<p>Wow, that&#8217;s a 40x speed improvement for the <code>mandel</code> part of our code. This shows how significant keeping object allocations to a minimum can be. However, the two parts of the code we&#8217;re profiling only make up about 2 seconds out of a total of 10 seconds of runtime. Let&#8217;s move our profiling to the <code>render</code> function:</p>
<pre class="brush: javafx; highlight: [5,6,7];">
(defn render [xstart ystart xsize ysize width height max-iters wr]
  (dorun
    (map (fn [pixel]
            (let [[x y] pixel]
              (prof :setPixel (.setPixel wr x y
                (prof :int-array (int-array
                  (prof :coord-colour (coord-colour
                    (get-coord (double x) (double y) xstart ystart xsize ysize width height)
                    max-iters))))))))
           (get-pixels width height))))
</pre>
<p>And run the render again:</p>
<pre class="brush: javafx;">
user=&#62; (time (profile (my-mandelbrot)))
        Name      mean       min       max     count       sum
coord-colour      6632      3073   1690997    300000  1989613029
   int-array     11402      7263   1706641    300000  3420617714
    setPixel     30688     21790   2191620    300000  9206612546
&#34;Elapsed time: 11283.777407 msecs&#34;
</pre>
<p>You can see that <code>setPixel</code> is most costly function, but this is not really a surprise given the other two calls are nested within it. However, even taking the runtime of the nested calls into account, the <code>.setPixel</code> call is taking nearly 6 out of the total 11 seconds (the reason we have an extra 1s of runtime after this run is most likely due to the overhead of profiling another block of code). </p>
<h2>Removing Reflection</h2>
<p>We can see that <code>.setPixel</code> is called on a binding called <code>wr</code> but Clojure (nor us) has no idea what type wr might be. In fact Clojure has to use reflection to determine which method <code>.setPixel</code> refers to. Let&#8217;s turn on reflection warning and load the program again:</p>
<pre class="brush: javafx;">
Reflection warning, D:\dev\clojure\...\mandelbrot.clj:87 - call to setPixel can't be resolved.
Reflection warning, D:\dev\clojure\...\mandelbrot.clj:87 - call to setPixel can't be resolved.
Reflection warning, D:\dev\clojure\...\mandelbrot.clj:99 - call to drawImage can't be resolved.
Reflection warning, D:\dev\clojure\...\mandelbrot.clj:105 - call to setPreferredSize can't be resolved.
Reflection warning, D:\dev\clojure\...\mandelbrot.clj:106 - call to add can't be resolved.
Reflection warning, D:\dev\clojure\...\mandelbrot.clj:117 - reference to field getRaster can't be resolved.
Reflection warning, D:\dev\clojure\...\mandelbrot.clj:122 - reference to field repaint can't be resolved.
1:1 user=&#62;
</pre>
<p>We can see that with reflection warning turned on, Clojure complains that it cannot resolve the call to <code>setPixel</code>. We can fix this of course with a type hint, however we must also remember to coerce the parameters into the types expected by the <code>setPixel</code> method:</p>
<pre class="brush: javafx; highlight: [1,5];">
(defn render [xstart ystart xsize ysize width height max-iters #^WritableRaster wr]
  (dorun
    (map (fn [pixel]
            (let [[x y] pixel]
              (prof :setPixel (.setPixel wr (int x) (int y)
                (prof :int-array (int-array
                  (prof :coord-colour (coord-colour
                    (get-coord (double x) (double y) xstart ystart xsize ysize width height)
                    max-iters))))))))
           (get-pixels width height))))
</pre>
<p>Running the program again we notice the reflection warning has gone (the others remain but we don&#8217;t care about them as their calls are not made within a loop), and we get a fairly significant speed up:</p>
<pre class="brush: javafx;">
user=&#62; (time (profile (my-mandelbrot)))
        Name      mean       min       max     count       sum
coord-colour      6770      3072  108868865    300000  2031060305
   int-array     12263      6704  221714492    300000  3679041832
    setPixel     16247     10057  221746898    300000  4874399625
&#34;Elapsed time: 6739.067116 msecs&#34;
</pre>
<p>This now means that the <code>setPixel</code>, <code>int-array</code> and <code>coord-colour</code> sections now take 17%, 25% and 30% of the total elapsed time respectively. These proportions seem pretty even so it&#8217;s possible that our profiling representing a significant portion of that elapsed time. Let&#8217;s run again, this time without making the call to the <code>profile</code> macro:</p>
<pre class="brush: javafx;">
user=&#62; (time (my-mandelbrot))
&#34;Elapsed time: 1668.624085 msecs&#34;
</pre>
<p>That&#8217;s quite a big drop and it shows how significant the overhead of profiling can be but I&#8217;m hoping that this can be reduced with optimisations to the profiling macros themselves in the future. </p>
<p>We saw earlier how the section of code for calculating a colour gradient was taking about 75% of the time of the <code>mandelformula</code> function. It&#8217;s possible this function could be sped up with more primitive type arithmetic but let&#8217;s try a different, more functional method of optimisation.</p>
<h2>Memoization</h2>
<p>The <code>iter-colour</code> function takes a number between 1 and max-iter and returns a corresponding colour. The fact that there is only a small, fixed number of possible inputs to the function and the output is always the same for a given input, makes it a perfect candidate for <a href="http://clojure.org/api#toc370">memoization</a>. We can simply redefine the function as a memoized version of itself:</p>
<pre class="brush: javafx;">
user=&#62; (def iter-colour (memoize iter-colour ))
#'user/iter-colour
user=&#62; (time (my-mandelbrot))
&#34;Elapsed time: 954.501759 msecs&#34;
</pre>
<p>We have now managed to improve overall performance by over 30 times. It&#8217;s possible we could repeat these techniques such as inlining the get-pixels function or making the get-coord function use primitives to get a further performance boost. However, as cgrand says, <a href="http://clj-me.cgrand.net/2009/11/18/an-optimization-job-is-never-done/">an optimisation job is never done</a> and for now I believe the performance is &#8220;good enough&#8221;.</p>
<p>The full optimised code can be found <a href="http://github.com/alexspurling/clojure-projects/blob/master/Mandelbrot/src/fast-mandelbrot.clj">on github</a>. Please feel free to submit your own performance optimisations to improve the code even further <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Conclusion</h2>
<p>We&#8217;ve seen how to use profiling tools to peer beneath Clojure&#8217;s dynamic lispy surface and used this knowledge to dramatically improve the performance of our fractal renderer by taking advantage of function inlining, primitive coersions, elimination of reflection and memoization. Hopefully these techniques will be useful to you when improving the performance of your own Clojure programs!</p>
<h3>References</h3>
<p>Inspiration on how to write a Mandelbrot fractal renderer the &#8216;right&#8217; way: <a href="http://briancarper.net/tag/mandelbrot">http://briancarper.net/tag/mandelbrot</a><br />
Performance tips on Clojure: <a href="http://devlog.bigmonachus.org/2009/03/performance-tips-for-clojure.html">http://devlog.bigmonachus.org/2009/03/performance-tips-for-clojure.html</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Power of Abstraction]]></title>
<link>http://kareemyusuf.wordpress.com/2009/11/23/power-of-abstraction/</link>
<pubDate>Mon, 23 Nov 2009 21:44:29 +0000</pubDate>
<dc:creator>kareemyusuf</dc:creator>
<guid>http://kareemyusuf.wordpress.com/2009/11/23/power-of-abstraction/</guid>
<description><![CDATA[Every programmer is familiar with the command Print &#8220;Hello World&#8221; or some variation depe]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="clear:both;">Every programmer is familiar with the command <strong>Print &#8220;Hello World&#8221;</strong> or some variation depending upon language used (this one being Python).<br />
When we step back to think about what that single line of code represents, in terms of all the processing that a computer undertakes, from interpreting the command to instructing the right peripherals to result in &#8220;Hello World&#8221; appearing [typically] on the computer screen, we grasp in that instance the power of abstraction.</p>
<p style="clear:both;">IT is all about abstraction, with many advances ultimately being about introducing higher levels of abstraction or offering a new perspective on an existing level of abstraction.</p>
<p style="clear:both;">As we consider cloud computing, abstractions abound, whether we think of it in terms of infrastructure, platforms or applications we are seeing entities that we readily recognize being abstracted as a set of services.</p>
<p style="clear:both;">More exciting is the change in context we can expect as our knowledge around cloud computing matures. Specifically in the realm of PaaS, I see us moving from a container-centric perspective to an application-centric perspective. Currently the container is king, we think about setting up app servers to host our applications, with clouds the app will eventually become king, were we think of running an application in the cloud, and focus more on how we want the app to behave, rather than the topology of components (web servers, app servers, databases etc) required to enable the application to behave the way we want. In this near future that is all abstracted by the cloud.<br />
While we will see and already seeing this future materialize in public cloud offerings, the impact on enterprise data centers that will host private clouds, and the approach enterprises will take to developing and running applications will be much more profound.</p>
<p style="clear:both;">I&#8217;ve seen the future and the forecast is cloudy.</p>
<p><br class="final-break" style="clear:both;" /></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Go]]></title>
<link>http://nickdsnyder.wordpress.com/2009/11/22/go/</link>
<pubDate>Sun, 22 Nov 2009 00:24:54 +0000</pubDate>
<dc:creator>nickdsnyder</dc:creator>
<guid>http://nickdsnyder.wordpress.com/2009/11/22/go/</guid>
<description><![CDATA[Google recently announced their new computer language &#8220;Go&#8221;, which I will admit repulsed ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Google recently announced their new computer language &#8220;Go&#8221;, which I will admit repulsed me on first impression (you write a new language and THAT is what code looks like?). Perhaps it is more efficient to type and compile, but code is read more than it is written. It is not sexy like Python, but it IS new programming language so I felt obligated to suppress my gag reflex and learn more (<a href="http://golang.org/" target="_blank">http://golang.org/</a>). After reading the tutorials, FAQs, and watching the tech talk I began to understand the the &#8220;why&#8221; of Go (concurrency + fast compiles), which reduced my &#8220;eww&#8221; reaction.</p>
<p>Interesting features</p>
<ul>
<li>It is a compile time error import a package that you don&#8217;t use (builds are fast and minimal)</li>
<li>All needed packages must be explicitly imported (dependencies are explicit)</li>
<li>goroutines/channels make writing code that executes concurrently easy</li>
<li>garbage collected (because multi-threaded memory management is hard)</li>
<li>Did I mention fast compiles? (perhaps I can forgive some of the syntax if that is what it takes)</li>
</ul>
<p>I am very intrigued by goroutines and channels since I have not worked with any languages that have features like these (although Go is not the first language to have these features). I hope to write my first Go program that uses these features soon.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Missed Opportunity]]></title>
<link>http://kittenthebad.wordpress.com/2009/11/21/missed-opportunity/</link>
<pubDate>Sat, 21 Nov 2009 23:26:02 +0000</pubDate>
<dc:creator>Cate</dc:creator>
<guid>http://kittenthebad.wordpress.com/2009/11/21/missed-opportunity/</guid>
<description><![CDATA[I&#8217;m spending a lot more time teaching other people to code than I am actually coding at the mo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;m spending a lot more time teaching other people to code than I am actually coding at the moment.</p>
<p><strong>Whilst I like teaching, this is not at all in line with how I want to be spending my time.</strong></p>
<p>I TA a mandatory computer course in the management school, and I have a friend taking another mandatory programming course for Engineers. The course I TA teaches VB, and the Engineering course teaches C.</p>
<p>These students aren&#8217;t stupid, the students learning VB only have to ask you whether you use VB (<em>of course not, does any self-respecting programmer?</em>) and they know they aren&#8217;t learning anything that can&#8217;t be done using the built in functions in Excel. The students learning C notice that their TA&#8217;s (and the prof) keep accidentally giving them Java code. According to O&#8217;Reilly, Java has been overtaking C++ as a teaching language for <a href="http://www.oreillynet.com/pub/a/oreilly/java/news/teachjava_0101.html">over a decade</a>. Why are these courses so behind?</p>
<p>I think this is a missed opportunity. Students taking Computer Science have signed up for a degree of torment-by-compiler. <strong>These students have not</strong>. Instead of a course that they hate why not take the opportunity to create a course that excites them about the potential of programming? Instead of alienating them about the whole concept you motivate them with the reasons and real world examples for why programming is a <em>useful</em> skill to have?</p>
<p>For instance: mashup creation, simple scripting, what an API is (and how to make calls to it), web apps.</p>
<p>Yes, it requires more creativity in course creation. Yes, it may require the people teaching these courses and the TAs to learn more skills. Maybe before it didn&#8217;t make a big difference to send a bunch of students into different fields with a hatred for programming. In the new reality though, an understanding of programming and why it is useful would potentially give them a big head start.</p>
<p>What do you think?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Computing is still in the dark ages]]></title>
<link>http://bytebaker.com/2009/11/18/computing-is-still-in-the-dark-ages/</link>
<pubDate>Wed, 18 Nov 2009 14:09:12 +0000</pubDate>
<dc:creator>Shrutarshi Basu</dc:creator>
<guid>http://bytebaker.com/2009/11/18/computing-is-still-in-the-dark-ages/</guid>
<description><![CDATA[Despite all the talk of Web 2.0 and the shiny multicore machines with their gigabytes of RAM and bil]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Despite all the talk of Web 2.0 and the shiny multicore machines with their gigabytes of RAM and billions of cycles per second, I sometimes can&#8217;t help feel that we are still very much in the dark ages of computing. This time around my dark gloomy feelings have been brought about by this <a href="http://xent.com/pipermail/fork/Week-of-Mon-20091109/054578.html">message to a mailing list</a> which in turn was sparked off by the announcement of the <a href="http://golang.org/">Go Programming Language</a>. As a computer user and a programmer I feel that the actual use of computers is far below their potential.</p>
<p>As the years go by, it seems like we keep on piling layer on top of layer while the results aren&#8217;t proportional to what we have to learn to get things done. Now, I&#8217;m not proposing that we all start writing down-to-the-metal code or force everyone to become a programmer, but things are starting to look like a mess. Web programming is an interesting development, but it adds yet another layer on top of the existing kernel, operating system, libraries and GUI toolkits. Add to that the fact all browsers are still a bit different from each other and you can start to understand why I&#8217;ve yet to make a serious foray into web programming.</p>
<p>But even without the web and the many formats and barely interoperating systems out there, there&#8217;s enough on the desktop to get you depressed. Start with the fact that there are currently three major operating systems out there and if you want to write a program that runs on all three of them, you don&#8217;t have an easy task. You either embrace three different toolkits and programming methodologies and maintain 3 very different codebases, or you use something like Java which works on all three, but screams non-native on each one. Even though there are languages like Python that run on all of three, it really puts me off that there is still no top-notch multiplatform GUI library. <a href="http://www.wxwidgets.org">wxWidgets</a> tries pretty hard, but if you look at the <a href="http://www.wxwidgets.org/about/screensh.htm">screenshots</a> you can pretty easily that they don&#8217;t look quite right. It&#8217;s not very surprising that lots of smart developers are flocking to the web, where things in comparison are a lot smoother.</p>
<p>There is also the fact that programming languages, like all other pieces of major software, suck more than others. I still stand by what I said in my last post, that <a href="http://bytebaker.com/2009/11/16/its-a-great-time-to-be-a-language-buff/">it&#8217;s an exciting time for language enthusiasts</a>, but I also feel that there are some <a href="http://www.lazycoder.com/weblog/2009/11/17/we-need-a-language-for-programmers/">lessons we really need to learn</a>. I&#8217;m starting to have concerns that there may not be any true general purpose language, simply because there are so many different types of problems to be solved. I think we need to start creating broader categories: a set of systems languages similar to C going in the direction of D and Go. A set of hyper-optimizing VM-based languages designed for long-running, parallel server applications (the current JVM is a good example). A set of languages for writing end-user apps that are significantly high-level, but are still compiled to pretty fast native code (maybe not C or even optimized VM fast, but better than todays Python or Ruby). I&#8217;m thinking Python in its <a href="http://bytebaker.com/2009/09/24/why-unladen-swallow-is-important-to-pythons-future/">Unladen Swallow</a> incarnation might fill this gap.</p>
<p>As a programmer, the state of tools that we have to use is really quite depressing. Tools like Emacs and Vi are powerful and all, but let&#8217;s face it: we could really be having much more powerful IDE technology. We should be having full blown incremental compilation with autocompletion and support for rendering documentation for every major language out there. We should also have seamless version control with granularity down to the undo level. Every change I make should be saved and I should be able to visually browse all these changes, see what they are and restore to an older state (or commit them if I want to). We have the raw computing power needed to do all this, but yet we remain stuck doing mostly batch-style edit-compile-debug cycles and mucking around in plain text. Eclipse with its incremental compiler makes things much easier, but there&#8217;s so much more we could be using our machines for.</p>
<p>As a user, what irritates me is the amount of manual labor we still have to do on a daily basis. We still have to carefully name and place files so that we can file them later. I have to manually hit the save button (see version control bit above). Even with the Internet collaboration is a mess with most people throwing around emails with increasingly larger attachments. Add to that the fact that most email clients are pretty dumb pieces of software. <a href="http://wave.google.com">Google Wave</a> is a step in the right direction, if enough people get around to actually using it (and if it can integrate to some extent at least with the desktop). Also I think the web and the desktop need to be brought closer together. Ideally I would be able to sit down on any computer with a live Internet connection and have my full custom work environment (or at least the most important parts of it).</p>
<p>I&#8217;m fully aware that none of the things I&#8217;ve mentioned are trivial. In fact, they&#8217;re probably very hard projects that will take expert teams a good few years to complete. One day I would like to seriously work on some of the programmer-related issues, especially the IDE part. I love Emacs, but there are some parts of Eclipse I really like too. For the time being I&#8217;m going to have to make do with what I have, but I&#8217;ll be sure to keep an eye for interesting things and movements in the right direction.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Mais um pouco sobre herança prototípica]]></title>
<link>http://daltojr.wordpress.com/2009/11/18/mais-um-pouco-sobre-heranca-prototipica/</link>
<pubDate>Wed, 18 Nov 2009 04:23:06 +0000</pubDate>
<dc:creator>Dalto</dc:creator>
<guid>http://daltojr.wordpress.com/2009/11/18/mais-um-pouco-sobre-heranca-prototipica/</guid>
<description><![CDATA[Vamos continuar com as minhas divagações sobre herança prototípica. Continuarei citando mais vantage]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Vamos continuar com as minhas divagações sobre herança prototípica. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Continuarei citando mais vantagens e desvantagens entre a herança prototípica em relação a baseada em classes. Num outro post, quando sobrar um tempinho, vou falar sobre as maneiras de simular a flexibilidade da herança prototípica em Ruby por meio do uso de módulos como mixins, metaprogramação e do método Class#new que aceita um bloco como parâmetro.</p>
<p><strong>Vantagens</strong></p>
<p>Algumas vantagens que não foram citadas no primeiro post:</p>
<ul>
<li><strong>Relacionamentos simplificados entre objetos:</strong> para entender como os objetos se relacionam em um sistema baseado em classes devemos saber que podem existir dois tipo de relações entre eles. A primeira, citada no paper como &#8216;is_a&#8217;, indica se um objeto é instância de uma classe. A segunda, &#8216;kind_of&#8217;, indica se a classe objeto é subclasse de outra. Quando se tem herança prototípica, a única relação entre dois objetos é &#8216;inherits_from&#8217; que indica se ele foi clonado de outro.</li>
<li><strong>Criação por cópia:</strong> instanciar um objeto a partir de uma classe é como construir uma casa a partir de uma planta. Clonar um objeto a partir de outro seria então uma metáfora mais simples para instanciação.</li>
<li><strong>Exemplos de módulos pré-existentes:</strong> Protótipos são mais contretos do que classes por que eles são modelos existentes com comportamento definido, que pode ser observado. Eles são exemplos do comportamento que será clonado por outros objetos. Classes são descrições do que os objetos instanciados por elas virão a ser. Há uma diferença entre ser um exemplo que se pode interagir e uma descrição estática.</li>
</ul>
<p><strong>Desvantagens</strong></p>
<p>As principais desvantagens são relacionadas à organização do código. Como saber se um objeto só existe para ser protótipo de outros? Esse problema é um sistema grande pode dar uma baita dor de cabeça. Uma saída, ainda que bem precária (na minha humilde opinião <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  para isto pode ser usar convenções para nomes de variáveis.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Can direct manipulation lower the barriers to computer programming and promote transfer of training?]]></title>
<link>http://computinged.wordpress.com/2009/11/16/can-direct-manipulation-lower-the-barriers-to-computer-programming-and-promote-transfer-of-training/</link>
<pubDate>Mon, 16 Nov 2009 21:28:12 +0000</pubDate>
<dc:creator>Mark Guzdial</dc:creator>
<guid>http://computinged.wordpress.com/2009/11/16/can-direct-manipulation-lower-the-barriers-to-computer-programming-and-promote-transfer-of-training/</guid>
<description><![CDATA[Chris Hundhausen has a really important paper in the latest issue of ACM TOCHI: Can direct manipulat]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Chris Hundhausen has a really important paper in the latest issue of ACM TOCHI<a href="http://portal.acm.org/citation.cfm?id=1592440.1592442&#38;coll=ACM&#38;dl=ACM&#38;CFID=63303219&#38;CFTOKEN=92700947">: Can direct manipulation lower the barriers to computer programming and promote transfer of training?</a>.</p>
<p>We&#8217;ve known for a couple decades now that programmers read and understand visual programs no better than textual programs &#8212; Thomas Green, Marian Petre, and Tom Moher settled that question a long time ago.  However, everybody experiences that <em>starting</em> with a visual programming language is easier than a textual language.  But does it transfer?  If you want students to eventually program in text, does starting out with Alice or Squeak or Etoys <em>hurt? </em>Given Chris found: &#8220;We found that the direct manipulation interface promoted significantly better initial programming outcomes, positive transfer to the textual interface, and significant differences in programming processes. Our results show that direct manipulation interfaces can provide novices with a &#8216;way in&#8217; to traditional textual programming.&#8221;  I think that this is big news for computing educators.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Vala for GNOME developers]]></title>
<link>http://al3omdah.wordpress.com/2009/11/16/vala-for-gnome-developers/</link>
<pubDate>Mon, 16 Nov 2009 16:24:36 +0000</pubDate>
<dc:creator>Emad Al-Bloushi</dc:creator>
<guid>http://al3omdah.wordpress.com/2009/11/16/vala-for-gnome-developers/</guid>
<description><![CDATA[Here you are now a new open source programming language called Vala that has been invented by GNOME ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img src="http://www.gnome.org/css/gnome.png" alt="GNOME" />Here you are now a new <a href="http://en.wikipedia.org/wiki/Open_source">open source</a> <a href="http://en.wikipedia.org/wiki/Programming_language">programming language</a> called <a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> that has been invented by <a href="http://en.wikipedia.org/wiki/GNOME">GNOME</a> organization to be one of the best choices for <a href="http://en.wikipedia.org/wiki/GNOME">GNOME</a> <a href="http://en.wikipedia.org/wiki/Software_developer">developers</a> so here you are a list of features that I have discovered in <a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> :</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> is an <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">object oriented language</a> that mostly influenced by <a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29">C#</a> and <a href="http://en.wikipedia.org/wiki/Java">Java</a>.
<li>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> works perfectly in a <a href="http://en.wikipedia.org/wiki/Cross_platform">cross-platform</a> environments such as ( <a href="http://en.wikipedia.org/wiki/Linux">Linux</a> , <a href="http://en.wikipedia.org/wiki/Unix">Unix</a> , <a href="http://en.wikipedia.org/wiki/Mac_OS_X">Mac OS  X</a> , <a href="http://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</a> and more ).</li>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> has been designed to allow access to existing <a href="http://en.wikipedia.org/wiki/C_language">C</a> libraries and especially built for <a href="http://en.wikipedia.org/wiki/Gobject">GObject</a>-based libraries.</li>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> has a convenient library <a href="http://en.wikipedia.org/wiki/Language_binding">binding</a> process.</li>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> has a fabulous speed because the compiler produces <a href="http://en.wikipedia.org/wiki/C_language">C</a> source and header files from the source code files as if you&#8217;ve written your library or application directly in <a href="http://en.wikipedia.org/wiki/C_language">C</a> !</li>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> gives the <a href="http://en.wikipedia.org/wiki/Software_developer">developers</a> freedom to use built in assisted <a href="http://en.wikipedia.org/wiki/Memory_management">memory management</a> or their own <a href="http://en.wikipedia.org/wiki/Memory_management">memory management</a> techniques.</li>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> supports <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8 encoding</a>.</li>
<li><a href="http://en.wikipedia.org/wiki/Vala_%28programming_language%29">Vala</a> supports portability to implement new <a href="http://en.wikipedia.org/wiki/Open_source">open source</a> technologies.</li>
</ul>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[It's a great time to be a language buff]]></title>
<link>http://bytebaker.com/2009/11/16/its-a-great-time-to-be-a-language-buff/</link>
<pubDate>Mon, 16 Nov 2009 13:22:22 +0000</pubDate>
<dc:creator>Shrutarshi Basu</dc:creator>
<guid>http://bytebaker.com/2009/11/16/its-a-great-time-to-be-a-language-buff/</guid>
<description><![CDATA[I make no secret of the fact that I have a very strong interest in programming languages. So I was n]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I make no secret of the fact that I have a very strong interest in programming languages. So I was naturally very interested when news of the Go Programming Language hit the intertubes. Go is an interesting language. It pulls together some very powerful features with a familiar, but clean syntax and has lightning fast compile times. It certainly takes a place on my to-learn list along with Haskell and Scala. But even as Go becomes the latest hot piece of language news, it dawned on me that over the past few years we&#8217;ve seen a slew of interesting languages offering compelling alternatives to the industry &#8220;mainstream&#8221;.</p>
<p>I guess it all started with the rise of scripting languages like Python, PHP, Ruby and the poster boy of scripting: Perl. Personally, these languages with their dynamic typing, &#8220;batteries included&#8221; design and interesting syntax provided a breath of fresh air from the likes of C++ and Java. Not that C++ and Java are necessarily bad languages, but they aren&#8217;t the most interesting of modern languages. In the early years of this decade  computers were just getting fast enough to write large scale software in scripting languages. Things have changed a lot since then.</p>
<p>Dynamic languages aren&#8217;t just reserved for small scripts. Software like Ruby on Rails has proved that you can write really robust back end infrastructure with them. The languages for their part have kept on growing, adding features and making changes that keep them interesting and downright fun to use. Python 3.0 was a brave decision to make a break from backwards compatibility in order to do interesting things and it goes to show that these languages are far from ossifying or degrading.</p>
<p>Then there is JavaScript which was supposed to die a slow death by attrition as web programmers moved to Flash or Silverlight. But we all know that didn&#8217;t happen. JavaScript has stayed in the background since the rise of Netscape, but it&#8217;s only recently with advances in browser technology and growing standards support that it has really come into its own. I&#8217;ve only played with it a little, but it&#8217;s a fun little language which makes me feel a lot of the same emotions I felt when discovering Python for the first time. Thanks to efforts like Rhino, you can even use JavaScript on the client side for non-web related programming.</p>
<p>Of course, if you want to do really interesting things with these languages, then performance is not optional. Within the last year or two there&#8217;s been a strong push in both academia and industry to find ways to make these languages faster and safer. Google in particular seems to be in the thick of it. Chrome&#8217;s V8 JavaScript engine is probably the fastest client side JavaScript environment and their still experimental Unladen Swallow project has already made headway in improving Python performance. V8 has already enabled some amazing projects and I&#8217;m waiting to see what Unladen Swallow will do.</p>
<p>While we&#8217;re on the topic of performance, mentioning the Java Virtual Machine is  a must. The language itself seems to have fallen from grace lately, but the JVM is home to some of the most powerful compiler technology on the planet. It&#8217;s no wonder then that the JVM has become the target for a bunch of interesting languages. There are the ports of popular languages &#8212; JRuby,  Jython and Rhino. But the more interesting ones are the JVM-centric ones. Scala is really interesting in that it was born of an academic research project but is becoming the strongest contender to Java&#8217;s position of premier JVM language. Clojure is another language that I don&#8217;t think many people saw coming. It brings the power of LISP to a modern JVM unleashing a wide range of possibilities. It has it&#8217;s detractors, but it&#8217;s certainly done a fair bit to make Lisp a well known name again.</p>
<p>Academia has always been a hot bed when it comes to language design. It&#8217;s produced wonders like Lisp and Prolog and is making waves again with creations like Haskell (whose goal is ostensibly to avoid popularity at all costs) and the ML group of languages. These powerful functional languages with wonderful type inference are a language aficionado&#8217;s dream come true in many ways and they still have years of innovation ahead of them.</p>
<p>Almost as a corollary to the theoretically grounded functional languages, systems languages have been getting some love too. D and now Go are both languages that acknowledge that C and C++ have both had their heyday and it&#8217;s time to realize that systems programming does not have to be synonymous with bit twiddling. D has gotten some flak recently for not evolving very cleanly over the last few years, but something is better than nothing. Also a real shift towards eliminating manual memory management is a welcome addition.</p>
<p>As someone who intends to seriously study language design and the related concepts in the years to come, it&#8217;s a really great time to be in getting involved in learning about languages. At the moment I&#8217;m trying to teach myself Common Lisp and I have a Scala book sitting on the shelf too. One fo these days, I plan on sitting down and making a little toy language to get used to the idea of creating a language. Till then, it&#8217;s going to be really interesting just watching how things work out in an increasingly multilingual world.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Some Cocoa Touch Tips, Not Tricks]]></title>
<link>http://jeboyer.wordpress.com/2009/11/15/some-cocoa-touch-tips-not-tricks/</link>
<pubDate>Mon, 16 Nov 2009 00:55:33 +0000</pubDate>
<dc:creator>jeboyer</dc:creator>
<guid>http://jeboyer.wordpress.com/2009/11/15/some-cocoa-touch-tips-not-tricks/</guid>
<description><![CDATA[I&#8217;ve made significant progress on my prototype iPhone app since my last post. I&#8217;m contin]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="clear:both;">I&#8217;ve made significant progress on my prototype iPhone app since my last post. I&#8217;m continuing to learn something new during each coding session. This post contains my learning nuggets and a few code snippets that I hope you&#8217;ll find useful.</p>
<h4>Table View Development</h4>
<p style="clear:both;">I&#8217;m developing a productivity app, so it makes heavy use of <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIKit_Framework/index.html" target="_self">UIKit&#8217;s</a> <a href="http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html">UITableView</a> classes. Here&#8217;s a few key things to remember as you develop your <a href="http://developer.apple.com/iphone/library/DOCUMENTATION/UIKit/Reference/UITableViewController_Class/Reference/Reference.html">UITableViewController</a>.</p>
<ol>
<li>Set a table cell&#8217;s text elements from your model in the<em>cellForRowAtIndexPath </em>method</li>
<li>Set a cell&#8217;s row height by implementing the <em>heightForRowAtIndexPath</em> method</li>
<li>Change the appearance of a cell&#8217;s label text (<em>textLabel</em> and <em>detailedTextLabel</em>) by setting the corresponding property.</li>
<p><!-- HTML generated using hilite.me --></p>
<div style="overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;">
<pre style="margin:0;">cell.textLabel.font <span style="color:#666666;">=</span> [UIFont <span style="color:#002070;font-weight:bold;">systemFontOfSize:</span>[UIFont labelFontSize]];
cell.textLabel.textColor <span style="color:#666666;">=</span> [UIColor grayColor];</pre>
</div>
<li style="margin-top:20px;">Respond to row selections in the <em>didSelectRowAtIndexPath </em>method. The code for inclusive and exclusive selection is in Apple&#8217;s iPhone Table View Programming guide <a href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageSelections/ManageSelections.html#//apple_ref/doc/uid/TP40007451-CH9-SW7" target="_self">here</a>.</li>
</ol>
<h4>Manipulating Dates</h4>
<p>Displaying dates requires the use of the <a href="http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSDateFormatter_Class/Reference/Reference.html" target="_self">NSDateFormatter</a> class.</p>
<ol>
<li>Avoid learning the hard way, case matters in your date <a href="http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns" target="_self">format strings</a>, e.g., <em>yyyy-MM-dd</em>. Here&#8217;s a good <a href="http://cocoawithlove.com/2009/05/simple-methods-for-date-formatting-and.html" target="_self">post</a> that covers the problem.</li>
<li>Computing dates (or what Apple refers to as <a href="http://developer.apple.com/iphone/library/DOCUMENTATION/Cocoa/Conceptual/DatesAndTimes/Articles/dtCalendricalCalculations.html" target="_self">calendrical calculations</a>) is a bit too verbose from me. Here&#8217;s how to calculate the top of the hour.</li>
</ol>
<p><!-- HTML generated using hilite.me --></p>
<div style="overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;">
<pre style="margin:0;">NSDate <span style="color:#666666;">*</span>today <span style="color:#666666;">=</span> [NSDate date];
NSCalendar <span style="color:#666666;">*</span>gregorian <span style="color:#666666;">=</span> [[NSCalendar alloc] <span style="color:#002070;font-weight:bold;">initWithCalendarIdentifier:</span>NSGregorianCalendar];

NSDateComponents <span style="color:#666666;">*</span>minutesComponent <span style="color:#666666;">=</span> [gregorian <span style="color:#002070;font-weight:bold;">components:</span>NSMinuteCalendarUnit <span style="color:#002070;font-weight:bold;">fromDate:</span>today];
NSDateComponents <span style="color:#666666;">*</span>secondsComponent <span style="color:#666666;">=</span> [gregorian <span style="color:#002070;font-weight:bold;">components:</span>NSSecondCalendarUnit <span style="color:#002070;font-weight:bold;">fromDate:</span>today];

NSDateComponents <span style="color:#666666;">*</span>componentsToSubtract <span style="color:#666666;">=</span> [[NSDateComponents alloc] init];
[componentsToSubtract <span style="color:#002070;font-weight:bold;">setMinute:</span><span style="color:#40a070;">0</span> <span style="color:#666666;">-</span> [minutesComponent minute] ];
[componentsToSubtract <span style="color:#002070;font-weight:bold;">setSecond:</span><span style="color:#40a070;">0</span> <span style="color:#666666;">-</span> [secondsComponent second] ];

NSDate <span style="color:#666666;">*</span>topOftheHour <span style="color:#666666;">=</span> [gregorian <span style="color:#002070;font-weight:bold;">dateByAddingComponents:</span>componentsToSubtract <span style="color:#002070;font-weight:bold;">toDate:</span>today <span style="color:#002070;font-weight:bold;">options:</span><span style="color:#40a070;">0</span>];</pre>
</div>
<h4>Internet Access</h4>
<p>For applications accessing internet resources, here&#8217;s a few tidbits:</p>
<ul>
<li>To indicate network activity, it&#8217;s easy to add spinner or <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIActivityIndicatorView_Class/Reference/UIActivityIndicatorView.html#//apple_ref/doc/uid/TP40006830-CH3-DontLinkElementID_1">UIActivityIndicatorView</a> to a view. However, if the main thread is too busy, it will not appear.</li>
<li>The result of a URL connection (or <em>NSURLConnection</em>) is a binary <em>NSData</em> object, convert it to a string by invoking <em>initWithData</em> in <a href="http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/uid/20000154-initWithData_encoding_" target="_self">NSString</a>.</li>
<li>Parsing <a href="http://www.json.org/" target="_self">JSON</a> objects is a breeze with the <a href="http://code.google.com/p/json-framework/" target="_self">JSON Framework for Objective-C</a>. By the way, for server-side Java, check out <a href="http://flexjson.sourceforge.net/" target="_self">Flexjson</a>, works like a charm.</li>
</ul>
<h4>Parsing Newlines</h4>
<p>Is parsing newlines as simple as searching for &#8220;\n&#8221;? No, take a gander at this code from Apple&#8217;s <a href="http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/Strings/Articles/stringsParagraphBreaks.html#//apple_ref/doc/uid/TP40005016" target="_self">documentation</a>:<br />
<!-- HTML generated using hilite.me --></p>
<div style="overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;">
<pre style="margin:0;"><span style="color:#666666;">-</span> (NSMutableArray <span style="color:#666666;">*</span>) <span style="color:#002070;font-weight:bold;">parseRawString:</span> (NSString <span style="color:#666666;">*</span>) rawString  {
	<span style="color:#902000;">int</span> <span style="color:#902000;">unsigned</span> length <span style="color:#666666;">=</span> [rawString length];
	<span style="color:#902000;">int</span> <span style="color:#902000;">unsigned</span> paraStart <span style="color:#666666;">=</span> <span style="color:#40a070;">0</span>, paraEnd <span style="color:#666666;">=</span> <span style="color:#40a070;">0</span>, contentsEnd <span style="color:#666666;">=</span> <span style="color:#40a070;">0</span>;
	NSMutableArray <span style="color:#666666;">*</span>array <span style="color:#666666;">=</span> [NSMutableArray array];
	NSRange currentRange;
	<span style="color:#007020;font-weight:bold;">while</span> (paraEnd <span style="color:#666666;">&#60;</span> length) {
	      [rawString <span style="color:#002070;font-weight:bold;">getParagraphStart:</span><span style="color:#666666;">&#38;</span>paraStart <span style="color:#002070;font-weight:bold;">end:</span><span style="color:#666666;">&#38;</span>paraEnd <span style="color:#002070;font-weight:bold;">contentsEnd:</span><span style="color:#666666;">&#38;</span>contentsEnd <span style="color:#002070;font-weight:bold;">forRange:</span>NSMakeRange(paraEnd, <span style="color:#40a070;">0</span>)];
	      currentRange <span style="color:#666666;">=</span> NSMakeRange(paraStart, contentsEnd <span style="color:#666666;">-</span> paraStart);
	      [array <span style="color:#002070;font-weight:bold;">addObject:</span>[rawString <span style="color:#002070;font-weight:bold;">substringWithRange:</span>currentRange]];
	}
	<span style="color:#007020;font-weight:bold;">return</span> array;
}</pre>
</div>
<p>Lastly, Google search and <a href="http://stackoverflow.com/" target="_self">stackoverflow</a> are your friends. If you get stuck, Google it, you&#8217;ll most likely find the answer in <a href="http://stackoverflow.com/" target="_self">stackoverflow</a> or the <a href="http://www.iphonedevsdk.com/" target="_self">iPhone Dev SDK</a> forum. (<em>However, always read Apple&#8217;s iPhone programming guides first</em>).</p>
<p>Well,that&#8217;s all I have for now, happy programming!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Rendering the Mandelbrot Set in Clojure]]></title>
<link>http://developmentjungle.wordpress.com/2009/11/14/rendering-the-mandelbrot-set-in-clojure/</link>
<pubDate>Sat, 14 Nov 2009 20:08:11 +0000</pubDate>
<dc:creator>alex</dc:creator>
<guid>http://developmentjungle.wordpress.com/2009/11/14/rendering-the-mandelbrot-set-in-clojure/</guid>
<description><![CDATA[Clojure is a functional language that brings dynamic types and lisp syntax to the JVM. It has a numb]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img class="alignright size-full wp-image-15" title="Clojure Mandelbrot Set" src="http://developmentjungle.wordpress.com/files/2009/11/clojure-mandelbrot-set-preview.png" alt="Clojure Mandelbrot Set" width="222" height="155" /><a href="http://www.clojure.org">Clojure</a> is a functional language that brings dynamic types and lisp syntax to the JVM. It has a number of features that make it interesting which will be the subject of another post but for now, let&#8217;s dive right into some code.</p>
<h2>The Mandelbrot Set</h2>
<p>The <a href="http://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot set</a> is an example of a fractal which is basically something that can be described using a simple formula and yet exhibit fascinating levels of detail and beauty. I thought it would be  a good application to get me started learning Clojure.<br />
<!--more--><br />
The Mandelbrot formula is:</p>
<p><strong>Z = Z<sup>2</sup> + C</strong></p>
<p>Where <strong>Z</strong> is a complex number and <strong>C</strong> is a constant. To find out whether or not <strong>C</strong> is in the set, we apply the formula iteratively until the magnitude of <strong>Z</strong> becomes larger than 2, or we reach a certain number of maximum iterations.</p>
<p>Most 2D fractals are described mathematically using complex numbers which are just like regular (real) numbers but with an added 2nd dimension. They can be represented by two regular numbers so another way to describe the formula above might be:</p>
<p><strong>[x, y] = [x, y]<sup>2</sup> + [a, b]</strong></p>
<p>Where <strong>[a, b]</strong> is equivalent to <strong>C</strong> and represents the coordinates on the complex plane we&#8217;re interested in. By applying the formula we can find out whether or not <strong>C</strong> is in the Mandelbrot set. If it is, we draw it with a black pixel, otherwise with some other colour depending the number of iterations taken by the formula.</p>
<h2>Defining a Functional Mandelbrot Set</h2>
<p>Let&#8217;s try to write this in Clojure code. First of all, how do you square a complex number? First let&#8217;s represent <strong>Z</strong> as a vector of regular numbers <strong>[x, y]</strong>. To square them we just apply the formula:</p>
<p><strong>[x, y]<sup>2</sup> = [x<sup>2</sup> - y<sup>2</sup>, 2xy]</strong></p>
<p><strong> </strong>In Clojure, it looks like this:</p>
<pre class="brush: javafx;">
(defn mandel [[x y]]
  [(- (* x x) (* y y)) (* 2 x y)])
</pre>
<p>But this represents just half of the Mandelbrot formula, we need to add that constant<strong> C</strong> and also somehow call our <code>mandel</code> function iteratively. Normally, in an imperative language, this would be easy. We just assign C to our starting value, then calculate Z in a for loop. In Clojure, it&#8217;s a bit different:</p>
<pre class="brush: javafx;">
(defn mandelformula [xcoord ycoord]
  (iterate
    #(vec (map + (mandel %) [xcoord ycoord]))
    [xcoord ycoord]))
</pre>
<p>This function uses the <code><a href="http://clojure.org/api#toc318">iterate</a></code> function to create successive calls to the <code>mandel</code> function passing our initial starting value <strong>[xcoord, ycoord]</strong> which represents <strong>C</strong> in the original formula. The <code>mandel</code> function is actually wrapped in an anonymous function which adds the return value to the initial value hence giving us the <strong>Z</strong><strong><sup>2</sup></strong><strong> + C</strong>. The reason we have to use <code><a href="http://clojure.org/api#toc356">map</a><code> is that we cannot directly add the two vectors together. The individual <strong>x</strong> and <strong>y</strong> values must be added separately and then constructed back into a vector with the <code>vec</code> function.</p>
<p>That's quite a dense piece of code but I think represents the mathematical version of the formula fairly well. It's certainly not the fastest implementation but the goal of functional programming is to favour correctness and readability rather than performance. The great thing about this implementation is that that <code>iterate</code> function returns a lazy infinite sequence. This is very much like the mathematical definition of the formula given at the start; it says nothing about how many times we're actually going to keep applying the formula.</p>
<p>The next part of the definition of the set says that we need to apply the formula to a given point until either the magnitude of <strong>Z</strong> becomes greater than 2, or we reach a given number of iterations.</p>
<pre class="brush: javafx;">
(defn mag [[x y]]
 (+ (* x x) (* y y)))

(take 50 (take-while #(&#60;= (mag %) 4) (mandelformula xcoord ycoord)))
</pre>
<p>Firstly, we define the function <code>mag</code> which returns the magnitude (actually, the magnitude squared) of the given vector pair. Next we use this function with the <code><a href="http://clojure.org/api#toc562">take-while</a></code> function so we'll only evaluate the terms of the mandelbrot formula while the value of each term is less than or equal to 4 (we've squared 2 to avoid having to perform an expensive square root in the <code>mag</code> function). <code>take-while</code> returns another lazy sequence (which might also be infinite) so we use <code><a href="http://clojure.org/api#toc560">take</a></code> to restrict the number of terms evaluated to 50.</p>
<p>Now we're pretty much done with all the maths stuff. All we need to do is count the number of terms calculated and from that number, calculate a colour.</p>
<pre class="brush: javafx;">
(defn coord-colour
  [[xcoord ycoord] max-iters]
  (let [num-iters (count (take max-iters (take-while #(&#60;= (mag %) 4) (mandelformula xcoord ycoord))))]
    (if (= max-iters num-iters)
    *set-colour*
    (iter-colour num-iters max-iters))))
</pre>
<p>This function takes a coordinate, a defined number of maximum iterations and returns the colour that the coordinate should be rendered with by applying the Mandelbrot formula. You can see that we're assigning <strong>num-iters</strong> to the count of the terms returned by our sequence calculated earlier. We then compare <strong>num-iters</strong> with <strong>max-iters</strong>, if they are equal, then the given coordinate is likely to be in the Mandelbrot set so we return <strong>*set-colour*</strong>. If <strong>num-iters</strong> is less than <strong>max-iters</strong> then the coordinate cannot be within the set so we pass the values to another function <code>iter-colour</code> which applies a gradient to the colours.</p>
<h2>Calculating a Colour Gradient</h2>
<p>First of all we define three vectors representing the colours we want to draw with as RGB values.</p>
<pre class="brush: javafx;">
;; Colours used to draw the set
(def *grad-colour-a* [255, 255, 0]) ;yellow
(def *grad-colour-b* [0, 0, 255]) ;blue
(def *set-colour* [0, 0, 0]) ;black
</pre>
<p>We want to calculate a gradient colour such that if <strong>num-iters</strong> is 0, we return yellow, if it is equal to <strong>max-iters</strong> we return blue and if it is somewhere in between, we return a mix between the two colours.</p>
<pre class="brush: javafx;">
(defn grad-colour
  &#34;Returns the colour that is the given fraction of the way between
  the first and second colours given. Returns as a vector of three
  integers between 0 and 255.&#34;
  [colA colB frac]
  (vec (map #(+ (* frac (- %2 %1)) %1) colA colB)))

(defn iter-colour
  &#34;Returns the colour needed to paint a point with the given number
  of iterations&#34;
  [num-iters max-iters]
  (grad-colour *grad-colour-a* *grad-colour-b*
    (/ (double num-iters) max-iters)))
</pre>
<p>The <code>iter-colour</code> function calculates the number of iterations as a fraction of the maximum number of iterations to give a value between 0 and 1 and passes this along with the two colours to the <code>grad-colour</code> function. This function simply calculates the difference between each of the R, G and B values of the two colours and weights it by multiplying by <strong>frac</strong>. Again, similar to how we calculate the sum of a vector in the <code>mandelformula</code> function, we use <code>map</code> to apply this calculation to each of the three values in the two vectors.</p>
<h2>Surfing the Complex Plane</h2>
<p>Now we have all we need to calculate the colour of a given coordinate on the complex plane, we're close to being able to render a fractal in Clojure! But how do we go from the pixels you find on your screen to the mathematical coordinates of the complex plane? Clearly, we need another function.</p>
<pre class="brush: javafx;">
(defn get-coord
  &#34;Returns the coordinates of the given pixel in the complex plane&#34;
  [x y xstart ystart xsize ysize width height]
  [(+ xstart (* (/ x width) xsize))
  (+ ystart (* (/ y height) ysize))])
</pre>
<p>This function takes the x and y <code>pixel</code> coordinates and returns the corresponding <code>complex</code> coordinates. The other parameters are the complex coordinate of the top-left of our screen (<strong>xstart</strong> and <strong>ystart</strong>), the complex dimensions of the area we're drawing (<strong>xsize</strong> and <strong>ysize</strong>) and the dimensions of the area we are drawing in pixels (<strong>width</strong> and <strong>height</strong>).</p>
<p>Now all we need is a way to get all the pixels in our drawing area as vectors to pass on to the this function.</p>
<pre class="brush: javafx;">
(defn get-pixels [width height]
  (for [y (range height) x (range width)]
    [x y]))
</pre>
<p>This function returns a lazy sequence of pixel coordinates for the given width and height. We just need to map the <code>get-coord</code> function onto this sequence and we'll have a lazy sequence of <em>all</em> the complex coordinates in our drawing area. Then all that's left is to get the colour of each of those complex coordinates (according the mandelbrot formula) and assign the colour to the corresponding pixel.</p>
<pre class="brush: javafx;">
(defn render [xstart ystart xsize ysize width height max-iters wr]
  (dorun
    (pmap (fn [pixel]
            (let [[x y] pixel]
              (.setPixel wr x y
                (int-array (coord-colour
                  (get-coord (double x) (double y) xstart ystart xsize ysize width height)
                  max-iters)))))
          (get-pixels width height))))
</pre>
<p>Here we are in the heart of the fractal renderer. Note that we use <code><a href="http://clojure.org/api#toc429">pmap</a></code> to process the sequence of pixels which works just like <code>map</code> but runs across multiple threads which allows us to make the most of multi-core system and render each pixel in parallel. Also, we must use <code><a href="http://clojure.org/api#toc220">dorun</a></code> because <code>get-pixels</code> returns a lazy sequence, so <code>pmap</code> is forced to actually process each pixel (rather than return a lazy sequence as it would do normally). Finally, the colour returned by each call to <code>coord-colour</code> is converted into a Java int[] array so that it can be passed to the <code>.setPixel</code> function of <strong>wr</strong> which is an instance of a <code>WritableRaster</code>.</p>
<p>Note also how we <code>coerce</code> the pixel values of <strong>x</strong> and <strong>y</strong> into doubles. This is because by default, Clojure will use arbitrary precision using Java's BigDecimal class which would incur a huge performance hit when it came to applying the formula. Coercing to double ensures we use either double primitives or boxed Double objects.</p>
<h2>Setting up the Swing Stuff</h2>
<p>All the remaining code is to initialise the Java Swing components needed to display the image generated.</p>
<pre class="brush: javafx;">
(defn get-img [width height]
  (BufferedImage. width height (BufferedImage/TYPE_INT_RGB)))

(defn get-panel [width height img]
  (proxy [JPanel] [] (paint [g] (.drawImage g img 0 0 (Color/red) nil))))

(defn construct-frame [width height panel]
  &#34;Creates and displays a JFrame of the given dimensions with
  the panel added to it&#34;
  (let [frame (JFrame.)]
    (.setPreferredSize panel (Dimension. width height))
    (doto frame
      (.add panel)
      .pack
      (.setLocationRelativeTo nil)
      .show)))

(defn mandelbrot [xstart ystart xsize ysize width height max-iters]
  &#34;Returns a function to render the mandelbrot set with the
  given parameters on a frame&#34;
  (let [img (get-img width height)
        panel (get-panel width height img)
        wr (.getRaster img)]
    (construct-frame width height panel)
    (fn []
      (do
        (render xstart ystart xsize ysize width height max-iters wr)
        (.repaint panel)))))
</pre>
<p>We have defined a number of functions for creating the Swing components and also a function for putting them all together called <code>mandelbrot</code>. Notice, rather than call <code>render</code> immediately, the <code>mandelbrot</code> creates and returns an anonymous function instead. This function is actually a <code>closure</code> which means we can call it repeatedly without having to keep passing in the parameters for the window size and number of iterations. When running a program in a REPL, being able to call individual parts of your code can be very handy.</p>
<p>Finally, we assign the function to a var, and then call it!</p>
<pre class="brush: javafx;">
(def my-mandelbrot (mandelbrot -2 -1.25 3 2.5 1200 1000 50))

(future (my-mandelbrot))
</pre>
<p>We wrap the call to <code>my-mandelbrot</code> in a <code><a href="http://clojure.org/api#toc268">future</a></code> which returns immediately and then executes the function passed to it in a separate thread. The reason for this is that rendering the fractal can take a significant amount of time. Using a <code>future</code> allows you to continue to use the REPL while the rendering happens in the background which can be helpful for debugging or general development. After about 30 seconds or so, you'll see something like this:</p>
<p><img class="aligncenter size-full wp-image-17" title="Clojure Mandelbrot Set" src="http://developmentjungle.wordpress.com/files/2009/11/clojure-mandelbrot-set.png" alt="Mandelbrot Set rendered in Clojure" width="608" height="534" /></p>
<h2>Conclusion</h2>
<p>We've seen how to create a working fractal rendering program by building on mathematical formulas and making use of Clojure features such as lazy, infinite sequences, parallel processing and closures to do it. These features allow us to keep the code close to the problem domain and hopefully, improve its readability and correctness. In the <a href="/2009/11/24/optimising-mandelbrot/">next post</a> we'll see how to profile the renderer and <em>drastically</em> improve its performance.</p>
<p>The full source code can be found <a href="http://github.com/alexspurling/clojure-projects/blob/master/Mandelbrot/src/mandelbrot.clj">here on github</a>.</p>
<p>Stay tuned for more Clojure goodness in the future!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Improving on Constructors]]></title>
<link>http://tangentvector.wordpress.com/2009/11/13/improving-on-constructors/</link>
<pubDate>Sat, 14 Nov 2009 05:42:26 +0000</pubDate>
<dc:creator>tangentvector</dc:creator>
<guid>http://tangentvector.wordpress.com/2009/11/13/improving-on-constructors/</guid>
<description><![CDATA[Constructors, as they appear in mainstream object-oriented languages, have numerous issues. Directly]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Constructors, as they appear in mainstream object-oriented languages, have numerous issues. Directly allocating objects with constructors creates coupling, and since most languages cannot abstract over constructors, we must resort to techniques like Factory patterns or Dependency Injection to provide the abstraction.</p>
<p>These issues seem to be well understood (or at least well documented), so I thought I&#8217;d bring up a less dangerous but no less annoying issue: when I try to code in a mostly-functional style, the approach to construction in C++, Java and C# forces me to write way too much boilerplate.</p>
<p>For an example, Imagine I am defining some C# classes to represent a simple lambda-calculus AST:</p>
<pre><code>
class Exp { ... }
class Abs : Exp { ... }
class App : Exp { ... }
class Var : Exp { ... }
</code></pre>
<h2>Immutable Objects</h2>
<p>I&#8217;d like to work with objects that are immutable once constructed. That means that I will not expose their fields, and will expose only &#8220;getter&#8221; properties. If I&#8217;d like each <code>Exp</code> to have some information on its range in the source code (using a value type <code>SourceRange</code>) I might write a canonical <code>Exp</code> as:</p>
<pre><code>
public class Exp
{
    public Exp( SourceRange range )
    {
        _range = range;
    }

    public SourceRange Range { get { return _range; } }

    private SourceRange _range;
}
</code></pre>
<p>For an immutable class with a single attribute, I&#8217;ve had to write a surprising amount of boilerplate. I&#8217;ve had to write the type of the attribute (<code>SourceRange</code>) three times, and variations on the name of the attribute (<code>range</code>, <code>Range</code>, <code>_range</code>) six times.</p>
<p>If I were using Scala, though, I could express the original intent quite compactly:</p>
<pre><code>
public class Exp( val Range : SourceRange )
{}
</code></pre>
<p>This notation defines both a parameter to the default constructor of <code>Exp</code> and a read-only property <code>Range</code> that gives access to the value passed into the constructor.</p>
<h2>Derived Classes</h2>
<p>So it appears that Scala can eliminate our boilerplate in <code>Exp</code>, but what happens in our derived classes? Starting with a canonical C# encoding again, here is <code>Abs</code>:</p>
<pre><code>
public class Abs : Exp
{
    public Abs( SourceRange range,
                string name,
                Exp body )
        : base( range )
    {
        _name = name;
        _body = body;
    }

    public string Name { get { return _name; } }
    public Exp Body { get { return _body; } }

    private string _name;
    private Exp _body;
}
</code></pre>
<p>The boilerplate for the new properties is the same as before. What is new, though, is that we are forced to re-state the attributes of the base class in our new constructor. While this seems like a relatively small annoyance at first, we end up having to repeat this boilerplate in each subclass we add. If the base class has a non-trivial number of attributes, this obviously gets proportionally worse.</p>
<p>In this case Scala doesn&#8217;t provide a solution to avoid this kind of boilerplate:</p>
<pre><code>
public class Abs( range : SourceRange,
                  val name : String,
                  val body : Exp )
    extends Exp(range)
{}
</code></pre>
<h2>Extending the Base Class</h2>
<p>So what&#8217;s so bad about this per-subclass boilerplate? The dogmatic answer is that it is a violation of <a href="http://c2.com/cgi/wiki?OnceAndOnlyOnce">Once and Only Once</a>. A more pragmatic answer arises if we need to alter or extend the base class.</p>
<p>Suppose we decide to add a <code>Type</code> attribute to <code>Exp</code>. This attribute might have a default value (e.g. <code>null</code>), so existing call sites that create expressions do not need to be updated. How much code do we have to edit to achieve this?</p>
<p>Adding the a new field and property to <code>Exp</code> is relatively easy, as is adding a new <code>Exp</code> constructor with an additional parameter. In addition, though, we&#8217;d have to update every subclass of <code>Exp</code> to include another constructor with the new parameter.</p>
<p>This is a serious compromise in modularity. If we are creating a class library used by other programmers or other organizations then we may not even have access to all subclasses. This means there are certain edits that we cannot make to the base class.</p>
<h2>A Possible Compromise</h2>
<p>If we sacrificed the goal of having immutable objects, we could use C# auto-generated properties to avoid the per-subclass boilerplate:</p>
<pre><code>
public class Exp
{
    public SourceRange Range { get; set; }
}

public class Abs : Exp
{
    public string Name { get; set; }
    public Exp Body { get; set; }
}
</code></pre>
<p>With this approach we would then use the property-based initialization syntax when constructing an instance:</p>
<pre><code>
var abs = new Abs{ Range = new SourceRange(...),
                   Name = "x",
                   Body = ... };
</code></pre>
<p>Adding a <code>Type</code> property to <code>Exp</code> could then be accomplished without affecting every subclass. Clients who create expressions could freely include the new parameter in their initializer lists.</p>
<p>There are two big downsides to this approach, though. The first is that we have sacrificed the immutability of our objects &#8211; every property has both a getter and a setter. The second is that clients can now create uninitialized or partially-initialized objects by forgetting to include any of the &#8220;required&#8221; attributes in their initializer.</p>
<p>You can decide for yourself whether that is an appropriate solution. I for one find it distasteful, and dislike that newer .NET technologies like WPF and XAML seem to be encouraging this style.</p>
<h2>Doing Better</h2>
<p>Ideally we&#8217;d have a solution that combines the declarative style and guaranteed initialization of the Scala approach with the easy extensibility of the C# automatic-property approach. It turns out that CLOS (the Common Lisp Object System) and its descendent Dylan already use a solution along these lines.</p>
<p>Casting our example into idiomatic Dylan, we would have:</p>
<pre><code>
define class &#60;exp&#62;
    constant slot range :: &#60;source-range&#62;, required-init-keyword: range:;
end class;

define class &#60;abs&#62; (&#60;exp&#62;)
    constant slot name :: &#60;string&#62;, required-init-keyword: name:;
    constant slot body :: &#60;exp&#62;, required-init-keyword: body:;
end class;
</code></pre>
<p>A user could then create an expression using the standard <code>make</code> function (the Dylan equivalent of the <code>new</code> operator in other languages):</p>
<pre><code>
let abs = make(&#60;abs&#62;,
               range: someRange,
               name: "x",
               body: ... );
</code></pre>
<p>Because Dylan and CLOS are dynamic languages, failure to provide all required parameters yields a runtime rather than compile-time error. Except for this, however, the Dylan approach provides exactly the combination of benefits described above.</p>
<h2>Conclusion</h2>
<p>Object initialization is a thorny issue in many modern object-orientated languages. In order to gain the benefits of both safety and extensibility, we should be willing to look at a wide variety of languages for inspiration.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[In Defense of OldSpeak]]></title>
<link>http://tangentvector.wordpress.com/2009/11/13/in-defense-of-oldspeak/</link>
<pubDate>Fri, 13 Nov 2009 23:40:53 +0000</pubDate>
<dc:creator>tangentvector</dc:creator>
<guid>http://tangentvector.wordpress.com/2009/11/13/in-defense-of-oldspeak/</guid>
<description><![CDATA[My last post tried to make a case in favor of static typing based on the fact that it allows us to d]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>My last post tried to make a case in favor of static typing based on the fact that it allows us to do overload resolution. At the time I hadn&#8217;t read <a href="http://gbracha.blogspot.com/2009/09/systemic-overload.html">this post</a> on Gilad Bracha&#8217;s Newspeak blog. In the thread on another post, he summarized the sprit of this essay when he <a href="http://gbracha.blogspot.com/2007/12/some-months-ago-i-wrote-couple-of-posts.html?showComment=1199219460000#c6609315035131440623">commented</a> that:</p>
<blockquote><p>&#8220;Static type based overloading is a truly bad idea, with no redeeming value whatsoever&#8221;</p></blockquote>
<p>I&#8217;m not going to claim that I know language design better than Bracha. I will, however, disagree with this extreme position on overloading. If you haven&#8217;t read Bracha&#8217;s <a href="http://gbracha.blogspot.com/2009/09/systemic-overload.html">essay</a>, please do so before you proceed&#8230;</p>
<p>Let&#8217;s first touch on the examples that Bracha used to illustrate his case. Some of these examples relate to legacy issues in Java, and are thus not inherent to languages with overloading. I&#8217;ll happily dismiss them since I don&#8217;t have to deal with Java.</p>
<p>The rest involve overloads with the following two properties:</p>
<ol>
<li>The methods are all defined within a single class</li>
<li>The methods are specialized on types that are related by inheritance</li>
</ol>
<p>I claim that it is the <strong>combination</strong> of these two properties that is the crux of the argument. If the types involved are not related by inheritance, the &#8220;gotcha&#8221; aspect of figuring out which overload will be called goes away. And because the methods are all defined in one class (by one programmer?) we can trivialize the cost associated with renaming one of the overloads, or of planning to avoid the situation altogether.</p>
<p>For this limited case  &#8211; &#8220;(1) and (2)&#8221; &#8211; I actually buy the argument. Static overloading in this case doesn&#8217;t do what you want. But what Bracha neglects to mention is that a pure object-oriented message send doesn&#8217;t achieve the desired result either! What you want in this case is dispatch on the run-time types of multiple arguments, aka multiple dispatch, aka multimethods.</p>
<p>There are legitimate concerns with multimethods (which Bracha notes) as expressed in e.g. CLOS and Dylan. There are, however, <a href="http://www.cs.ucla.edu/~todd/research/ecoop99.html">other approaches</a> that are more suitable for a new language. That is a discussion for another day.</p>
<p>Having ceded the argument in the &#8220;(1) and (2)&#8221; case, in favor of multimethods, that leaves us with the remaining cases, which Bracha didn&#8217;t directly address.</p>
<p>The &#8220;(1) but not (2)&#8221; case is harmless &#8211; there is no chance of ambiguity in dispatch. Multimethods subsume this case for overloading anyway, so I don&#8217;t think it is particularly useful to discuss.</p>
<p>The remaining cases must all deal with methods that weren&#8217;t defined within a single class. We might also presume, then, that we should consider the possibility that the methods involved were defined by different programmers, working at different organizations.</p>
<p>Suppose programmer A defines their <code>Widget</code> class version 1.0. Programmer B decides to use it as the base class for their <code>SuperWidget</code>. <code>SuperWidget</code> has extended <code>Widget</code> by adding a new message &#8220;<code>doSomethingSuper</code>&#8221; with semantics that are tied into B&#8217;s product.</p>
<p>Unbeknownst to B, though, A has been upgrading <code>Widget</code> for version 1.1 by adding their own &#8220;<code>doSomethingSuper</code>&#8221; method, with completely different semantics (after all, B doesn&#8217;t know about A&#8217;s product). If B tries to upgrade to the new version of <code>Widget</code>, then what happens?</p>
<p>In a language like Python or SmallTalk, <code>SuperWidget</code> will accidentally override the base class definition of &#8220;<code>doSomethingSuper</code>&#8220;. Now clients that try to use a <code>SuperWidget</code> as a <code>Widget</code> 1.1 will fail because <code>SuperWidget</code> responds to a message with an unexpected behavior.</p>
<p>If you try this same scenario out in C# and the Microsoft CLR, you&#8217;ll find that previously-compiled versions of <code>SuperWidget</code> keep working with <code>Widget</code> 1.1, and clients that use it as a <code>Widget</code> will have no problems. If you recompile <code>SuperWidget</code> after the upgrade, you will be told that your &#8220;<code>doSomethingSuper</code>&#8221; method might introduce an ambiguity &#8211; you will be forced to decorate it explicitly as either an <code>override</code> of the base-class method, or a <code>new</code> method that <strong>just happens</strong> to have the same name.</p>
<p>The secret that makes this technique work is &#8211; you guessed it &#8211; static overload resolution. This is exactly the <strong>opposite</strong> of Bracha&#8217;s claim about static overloading in his essay:</p>
<blockquote><p>&#8220;This means that existing code breaks when you recompile, or does the wrong thing if you don&#8217;t&#8221;</p></blockquote>
<p>In this case, however, it is the overloading-free languages which inhibit the modular extensibility of the system, and static overloading that makes it possible for another language to avoid the problem.</p>
<p>Overloading is generally not something we pursue, even when our languages support it. Instead, we simply recognize that it is something that arises inevitably when we develop large software systems that aggregate and extend components developed by other programmers and other organizations. The space of useful identifiers is just to small to avoid all conflicts.</p>
<p>Given this fact, I choose to use tools that recognize the inevitability of name conflicts and give me mechanisms for resolving them.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Google introduces new programming language: Go]]></title>
<link>http://mashimo.wordpress.com/2009/11/12/google-introduces-new-programming-language-go/</link>
<pubDate>Thu, 12 Nov 2009 15:59:44 +0000</pubDate>
<dc:creator>mashimo</dc:creator>
<guid>http://mashimo.wordpress.com/2009/11/12/google-introduces-new-programming-language-go/</guid>
<description><![CDATA[Google appears to have just made public a new experimental language, called Go (weird, the name does]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Google appears to have just <a href="http://google-opensource.blogspot.com/2009/11/hey-ho-lets-go.html">made public a new experimental language, called Go</a> (weird, the name does not look a great choice from a search engine point of view &#8230;)</p>
<p>It is similar to the C language but with garbage collection and some elements of modern scripting languages as Python, including array slices and a map type with constructor syntax that looks like Python&#8217;s dictionary concept.</p>
<p>According to Google, Go offers an expressive type system, fast compilation, good performance, and built-in language features that simplify threaded programming and concurrency.</p>
<p>For example, parallelism: the language introduces the concept of &#8220;goroutines&#8221; which are executed concurrently. Any function can be executed as a goroutine by prefixing the function call with the &#8220;go&#8221; keyword. The language provides a &#8220;channel&#8221; mechanism that can be used to safely pass data in and out of goroutines.</p>
<p>My two cents: it will not replace C or C++ and will not be useful for embedded developers (Go has garbage collection and lacks pointer arithmetic, while C has explicit memory management and pointer arithmetic); so where is it aimed for? Just adding concurrency development to a C-like language? Or is an alternative to scripting languages but then, why?</p>
<p>Personally, I subscribe what Alex Iskold said:</p>
<blockquote><p>I am a fan of Java and Object-Orientation, so new procedural languages sound like a thing of the past to me.</p></blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[What makes programmers happy? Students? Standards vs. Flexibility]]></title>
<link>http://computinged.wordpress.com/2009/11/11/what-makes-programmers-happy-students-standards-vs-flexibility/</link>
<pubDate>Wed, 11 Nov 2009 14:12:21 +0000</pubDate>
<dc:creator>Mark Guzdial</dc:creator>
<guid>http://computinged.wordpress.com/2009/11/11/what-makes-programmers-happy-students-standards-vs-flexibility/</guid>
<description><![CDATA[I think the fundamental thing that set Rails apart was a culture of putting the programmer first. Th]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><blockquote><p>I think the fundamental thing that set Rails apart was a culture of putting the programmer first. The idea that Web programming should be fun and that programmers should be enjoying themselves.</p>
<p>The culture bred ideas like Convention over Configuration, where we standardized all the things that programmers do most of the time for most applications anyway.</p></blockquote>
<p>via <a href="http://www.cio.com.au/article/322622/open_source_identity_ruby_rails_creator_david_heinemeier_hansson?pp=2">Open source identity: Ruby on Rails creator David Heinemeier Hansson &#8211; frameworks, open source, open source identity, ruby &#8211; CIO</a>.</p>
<p>What makes programmers happy?  The Ruby on Rails creator says that it is, in part, creating standards (&#8220;Conventions&#8221;) that do things for the students.  Another school of thought is that programmers want flexibility.  These seem to be contrasting perspectives to me.  I suppose that the middle ground is that programmers want things that they don&#8217;t want to do already done for them, and they want flexibility with the things that they want to do.  My bet is that those things (what programmers want to deal with, and what they don&#8217;t want to deal with) vary from domain-to-domain, maybe even programmer-to-programmer.  Hard to design for.</p>
<p>What do we want for students?  Do we want lots of things done for them, or provide them with small pieces (like Lego blocks) that they can put together in a wide variety of different patterns?  Do they want standards or do they want flexibility?  What do we as teachers want for them?  Should we have structures that are in place, so that students can&#8217;t build <em>anything</em> but what they do build is supported (I&#8217;m thinking Alice and Scratch here, as examples)?  Or should we give them maximal flexibility so that they can assemble things and come to understand from the bottom-up (I&#8217;m thinking Pascal and the hardware-first approach of Patt and Patel)?</p>
<p>Bigger question: Should the answers to these things be different?  Is the balance of standards and flexibility that works for programmers what we also want for students?  I&#8217;m not suggesting the exact same tools are right for both novices and for experienced programmers, but I am wondering if the <strong><em>balance</em></strong> between what&#8217;s provided and what&#8217;s flexible might be similar.</p>
<p>Marlene Scardamalia and Carl Bereiter of the University of Toronto&#8217;s Ontario Institute for Studies in Education (OISE) have been arguing for years for &#8220;<a href="http://www.questia.com/googleScholar.qst;jsessionid=K6Fc8vdRrxLgvdHDFVMfw2vx8vHK3DFhf6CpQDyYLGnpYQ0r7N9l!-1625679565!2066618780?docId=95228057">higher levels of agency</a>&#8221; for children.  Think about what you do when you have a question: You go find a source (a website, a book, or an expert) and ask your questions to learn the answer.  Think about what we do with children in most classrooms: You find children who don&#8217;t know the questions or answers, put them in front of teachers who know both the questions and the answers, then the teacher asks the children questions.  Scardamalia and Bereiter want to find ways to put children in the former situation.</p>
<p>What would Scardamalia and Bereiter want to see for computing education?  I suggest that the analogy is that we think about students as <em>wanting</em> to build something, and we&#8217;re about giving them the tools to build that something with as much support and as little irrelevant detail as possible. But how do we get students to learn what&#8217;s useful and important for them, that they might not realize they need or that might not arise when they build yet-another-video-game?  That&#8217;s the real challenge of placing more agency in the hands of the students &#8212; how do you get them to use that agency wisely?</p>
<p>&#160;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[The Origins of APL - 1974 Video]]></title>
<link>http://computinged.wordpress.com/2009/11/10/the-origins-of-apl-1974-video/</link>
<pubDate>Tue, 10 Nov 2009 18:18:46 +0000</pubDate>
<dc:creator>Mark Guzdial</dc:creator>
<guid>http://computinged.wordpress.com/2009/11/10/the-origins-of-apl-1974-video/</guid>
<description><![CDATA[A really interesting interview with Kenneth Iverson and others on the development of APL.  What]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>A really interesting interview with Kenneth Iverson and others on the development of APL.  What&#8217;s striking is that APL was invented as a human-to-human communication tool, used mostly in classrooms, which was years later turned into a programming language:<a href="http://vids.myspace.com/index.cfm?fuseaction=vids.individual&#38;videoid=60771080"> The Origins of APL &#8211; 1974 Video by Catherine &#8211; MySpace Video</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Epic Games Releases Unreal Engine 3 for FREE]]></title>
<link>http://jadendreamer.wordpress.com/2009/11/09/epic-games-releases-unreal-engine-3-for-free/</link>
<pubDate>Mon, 09 Nov 2009 20:43:51 +0000</pubDate>
<dc:creator>Jade</dc:creator>
<guid>http://jadendreamer.wordpress.com/2009/11/09/epic-games-releases-unreal-engine-3-for-free/</guid>
<description><![CDATA[Talk about a diamond in the rough! Unreal Engine has been at the forefront of 3D games for years and]]></description>
<content:encoded><![CDATA[Talk about a diamond in the rough! Unreal Engine has been at the forefront of 3D games for years and]]></content:encoded>
</item>
<item>
<title><![CDATA[Tales from OOPSLA at today's CSci tea]]></title>
<link>http://ummcsci.wordpress.com/2009/11/04/tales-from-oopsla-at-todays-csci-tea/</link>
<pubDate>Wed, 04 Nov 2009 14:23:33 +0000</pubDate>
<dc:creator>mcphee</dc:creator>
<guid>http://ummcsci.wordpress.com/2009/11/04/tales-from-oopsla-at-todays-csci-tea/</guid>
<description><![CDATA[Elena and two students, Kevin Arhelger and Fernando Trinciente, spent last week at OOPSLA (Object-or]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Elena and two students, Kevin Arhelger and Fernando Trinciente, spent last week at <a href="http://www.oopsla.org/oopsla2009/">OOPSLA</a> (Object-oriented programming systems, languages, and applications &#8211; one of the largest and most influential programming languages conferences in the world).  As well as presenting some very cool work on optimizing Java generics (which we hope to have more on here later), they also got to see some very exciting talks by some of the big names in the field, and rumor has it that they&#8217;ll be sharing stories at today&#8217;s CSci tea (4:30pm in the lab tea room).  This is a great opportunity to hear about the cutting edge thoughts of some of the Cool Kids in Computing, so definitely swing by!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Frank Zappa says Programming is Art]]></title>
<link>http://computinged.wordpress.com/2009/11/03/frank-zappa-says-programming-is-art/</link>
<pubDate>Tue, 03 Nov 2009 07:15:11 +0000</pubDate>
<dc:creator>Mark Guzdial</dc:creator>
<guid>http://computinged.wordpress.com/2009/11/03/frank-zappa-says-programming-is-art/</guid>
<description><![CDATA[I saw this in a storefront in Luzern, Switzerland yesterday: It was the quote that caught my eye, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I saw this in a storefront in Luzern, Switzerland yesterday:<br />
</p>
<p>It was the quote that caught my eye, &#8220;Art is making something out of nothing and selling it.&#8221;  I found it attributed to Frank Zappa.  Programming is pretty much &#8220;making something out of nothing and selling it,&#8221; which says that Frank Zappa and Donald Knuth agree &#8212; programming is art.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[What programming language does site X use?]]></title>
<link>http://hacksushi.com/2009/11/12/what-programming-language-does-site-x-use/</link>
<pubDate>Thu, 12 Nov 2009 01:21:05 +0000</pubDate>
<dc:creator>DJ Burdick</dc:creator>
<guid>http://hacksushi.com/2009/11/12/what-programming-language-does-site-x-use/</guid>
<description><![CDATA[I was running through some sites I like recently to see which programming languages they use. Most o]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://techburner.wordpress.com/files/2009/11/django-rails-php.jpg"><img class="alignnone size-full wp-image-373" title="django-rails-php" src="http://techburner.wordpress.com/files/2009/11/django-rails-php.jpg" alt="django-rails-php" width="480" height="140" /></a></p>
<p>I was running through some sites I like recently to see which programming languages they use. Most of the new sites I respect seem to be using RoR or Django, but it&#8217;s crazy how strong php is on some of the biggest sites out there. For those who hate its mess, I&#8217;m sorry to say that php is not going away anytime soon.</p>
<p>If you&#8217;ve got others feel free to add them in the comments.</p>
<p>(random order)</p>
<p>mint.com &#8211; java<br />
twitter &#8211; RoR<br />
facebook &#8211; php, C++<br />
last.fm &#8211; php, java, C++ (client)<br />
ilike &#8211; RoR<br />
google &#8211; python for web interactions<br />
yelp &#8211; python<br />
posterous &#8211; RoR, Java<br />
playdom &#8211; php, java<br />
zynga &#8211; php<br />
slide &#8211; python<br />
dropbox &#8211; python<br />
digg &#8211; php<br />
amazon &#8211; java/c++<br />
youtube &#8211; python (started in php)<br />
flickr &#8211; php<br />
imdb &#8211; perl<br />
hi5 &#8211; java?<br />
friendster &#8211; php<br />
ning &#8211; php<br />
hulu &#8211; RoR<br />
netflix &#8211; java, C++<br />
wikipedia &#8211; php<br />
wordpress &#8211; php</p>
<p>If you&#8217;re interested in general popularity visit the <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">TIOBE site</a></p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
