<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matt Crinklaw-Vogt on Medium]]></title>
        <description><![CDATA[Stories by Matt Crinklaw-Vogt on Medium]]></description>
        <link>https://medium.com/@tantaman?source=rss-8935d0167b24------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JYA-L9rLTtb82LSz.jpeg</url>
            <title>Stories by Matt Crinklaw-Vogt on Medium</title>
            <link>https://medium.com/@tantaman?source=rss-8935d0167b24------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:45:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tantaman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Typed Literals ARE Constants!]]></title>
            <link>https://medium.com/@tantaman/typed-literals-are-constants-c6f9e32017a0?source=rss-8935d0167b24------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6f9e32017a0</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Matt Crinklaw-Vogt]]></dc:creator>
            <pubDate>Tue, 23 Oct 2018 18:57:27 GMT</pubDate>
            <atom:updated>2018-10-23T18:57:27.339Z</atom:updated>
            <content:encoded><![CDATA[<pre>(option 1) display.setLayout(Layouts.FIXED);<br>(option 2) display.setLayout(&#39;FIXED&#39;);</pre><p><strong>Are both lines of code above using constants?</strong></p><p>I keep getting push-back that the first line is better practice than the second line. When reviewers see something that looks like the second line they say “define that in a constant.”</p><p>I’d understand their complaints if the method being called was not typed, but it is.</p><pre>type Layout = &#39;FIXED&#39; | &#39;FLOW&#39; | &#39;GRID&#39;;<br>function setLayout(layout: Layout): void;</pre><p>When the thing being called is typed as above, then there is no need, no purpose, and no advantage in defining these string literals in constants. Said another way, Layouts.FIXED and &#39;FIXED&#39; are equivalent. They’re just spelled differently.</p><p>To prove that they’re equivalent, run through the exercise of renaming FIXED to STATIC. The consequences (code changes you need to make) are the same in both situations.</p><p>In option (1) you need to run through and change all references to Layouts.FIXED toLayouts.STATIC.</p><p>In option (2) you need to run through and change all references from &#39;FIXED&#39; to &#39;STATIC&#39; .</p><p>But one may say in option (2) you don’t know where to go to change these literals. That would be incorrect. Since the use of these literals is typed you’ll get compile time errors that call out every point where &#39;FIXED&#39; needs to changed to &#39;STATIC&#39; — the same as you would if you used option (1).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6f9e32017a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Almighty Function]]></title>
            <link>https://medium.com/software-development/the-almighty-function-58ef5ef11488?source=rss-8935d0167b24------2</link>
            <guid isPermaLink="false">https://medium.com/p/58ef5ef11488</guid>
            <dc:creator><![CDATA[Matt Crinklaw-Vogt]]></dc:creator>
            <pubDate>Sat, 04 Jan 2014 05:40:58 GMT</pubDate>
            <atom:updated>2014-01-04T05:40:58.972Z</atom:updated>
            <content:encoded><![CDATA[<h4>Objects are a poor man’s closures. Closures are a poor man’s objects.</h4><p>Some people say everything is an object. I used to too but these days I think everything is actually a function.</p><ol><li>A map? Isn’t that just a function from one value to another?</li><li>An array? Well that can be thought of as a map which can be thought of as a function.</li><li>An object? Those are just partial functions that return functions or values.</li></ol><p>Lets take a closer look. Here is a<strong> pair implemented as a function</strong>. It is implemented in Javascript for illustration purposes.</p><pre>var pairCreator = function(first, second) {<br>  var first, second;<br>  return function(which) {<br>    return which == 0 ? first : second;<br>  }<br>}<br>var pair = pairCreator(&#39;hello&#39;, &#39;there&#39;);<br>console.log(pair(0) + &#39; &#39; + pair(1));</pre><p>How do we implement an <strong>object as a function</strong>? Well it is pretty similar to the pair example.</p><pre>var MyObjConstructor = function(greeting) {<br>  var greet = function() {<br>    console.log(greeting);<br>  }<br>  var leave = function() {<br>    ...<br>  }<br>  return function(method) {<br>    switch(method) {<br>      case &#39;greet&#39;:<br>        return greet;<br>      case &#39;leave&#39;:<br>        return leave;<br>    }<br>  }<br>}<br>var obj = MyObjConstructor(&quot;hello there&quot;);<br>obj(&#39;greet&#39;)(); // call the greet method<br>var leave = obj(&#39;leave&#39;); // save a pointer to the leave method</pre><p>Of course you wouldn’t ever really want to implement an object like that in Javascript ;)</p><p>And no, not everything really is a function but it is an interesting thought experiment to try to look at everything as a function. It’ll get you to design your software in new ways and to find entirely new applications for closures.</p><p>This sums it up pretty well:</p><blockquote>The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said<strong> “Master, I have heard that objects are a very good thing — is this true?”</strong> Qc Na looked pityingly at his student and replied, <strong>“Foolish pupil — objects are merely a poor man’s closures.”</strong></blockquote><blockquote>Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire “Lambda: The Ultimate…” series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress.</blockquote><blockquote>On his next walk with Qc Na, Anton attempted to impress his master by saying <strong>“Master, I have diligently studied the matter, and now understand that objects are truly a poor man’s closures.”</strong> Qc Na responded by hitting Anton with his stick, saying <strong>“When will you learn? Closures are a poor man’s object.”</strong> At that moment, Anton became enlightened.</blockquote><p><a href="http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html">http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58ef5ef11488" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-development/the-almighty-function-58ef5ef11488">The Almighty Function</a> was originally published in <a href="https://medium.com/software-development">Software Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Practical Laziness in Programming]]></title>
            <link>https://medium.com/software-development/practical-laziness-in-programming-e4e6b044abfa?source=rss-8935d0167b24------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4e6b044abfa</guid>
            <dc:creator><![CDATA[Matt Crinklaw-Vogt]]></dc:creator>
            <pubDate>Sat, 04 Jan 2014 01:04:44 GMT</pubDate>
            <atom:updated>2014-01-04T01:12:48.741Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first heard about lazy evaluation I thought it was cool but not of much practical use, that is until I thought about it a bit harder.</p><p>So how does lazy evaluation make your code easier to read, write and maintain?</p><p>I’ll illustrate with a program I wrote to convert Javadoc comments to JSON. I started writing the program in Java and I quickly realized the problem would be easier with lazy evaluation.</p><p>Ideally I wanted to do something like:</p><ol><li>get a list of all the ClassDoc objects</li><li>convert every entry in the list to a JSON object</li><li>stringify all the JSON objects</li><li>write all the strings to different files in parallel</li></ol><p>In code:</p><pre>List&lt;ClassDoc&gt; docs = getClassDocs();<br>List&lt;JSONObject&gt; jsonObjects = toJSON(docs);<br>List&lt;String&gt; jsonStrings = stringify(jsonObjects);<br>writeAll(jsonStrings);</pre><p>That is a pretty straightforward sequence of steps but our repository is huge and I wanted to keep memory consumption down so I couldn&#39;t just process everything at once. I had to instead do:</p><ol><li>get a ClassDoc object</li><li>convert the ClassDoc object to a JSON object</li><li>stringify the JSON object</li><li>send the JSON object to an executor service that writes it to a file</li><li>repeat steps 1-4 until no ClassDoc objects remain</li></ol><p>In code:</p><pre>while (hasNext()) {<br>  ClassDoc doc = getNext();<br>  JSONObject jsonObject = toJSON(doc);<br>  String jsonString = stringify(jsonObject);<br>  write(jsonString);<br>}</pre><p>Now this doesn&#39;t seem like a big deal. After all, only 1 step was added and that step is just looping over the first 4 steps. The problem is that this second approach makes the code less <strong>composable</strong>.</p><p>With the first approach I can just return the results of each of my intermediate steps for someone to work with. I.e., I can define each step as a method on my api class and users can compose those methods, or add steps in between them, however they want.</p><p>Here is an example:</p><pre>// Normal conversion<br>api.write(api.stringifyJSON(<br>    api.toJSON(api.getClassDocs())));</pre><pre>// Conversion + user&#39;s own swag<br>api.write(<strong>swag</strong>.addCopyright(<br>   api.stringifyJSON(<strong>swag</strong>.addCustomProps(api.toJSON(<br>      api.getClassDocs())))));</pre><p>As you see in the “conversion + user’s own swag” example, the user can easily add a copyright notice and some custom properties to the JSON just by adding a few extra method calls within and around the normal api calls.</p><p>With the looping approach, that composability becomes quite a bit harder to attain. Instead of just having api methods that users can compose on their own, I now need to provide some callback interface and a way for users to inject callbacks to be called at different points in my loop.</p><p>E.g.</p><pre>while (hasNext()) {<br> ClassDoc doc = getNext();<br> <strong>callDocCallbacks</strong>(doc);<br> <br> JSONObject jsonObject = toJSON(doc);<br> <strong>callJsonObjectCallbacks</strong>(jsonObject); <br> <br> String jsonString = stringify(jsonObject);<br> <strong>callJsonStringCallbacks</strong>(jsonString); <br> <br> write(jsonString);<br>}</pre><p>and the api becomes something like:</p><pre>api.<strong>registerJsonObjectCallback</strong>(new Callback&lt;JSONObject&gt;() {<br>  public void apply(JSONObject obj) {    <br>    swag.addCustomProps(obj);<br>  }<br>});<br>api.<strong>registerJsonStringCallback</strong>(new Callback&lt;String&gt;(){...});</pre><pre>api.process();</pre><p>As you can see this requires work on the API side to call the appropriate hooks and work on the client side to implement the callback interface and register callbacks at the correct points. If I ever add new steps to the process then new hooks need to be added as well.</p><h4>What about laziness??</h4><p>The first approach, without laziness, is going to process every class all at once and execute every step before writing any data or releasing any data from memory. Not good.</p><p>Laziness allows the first approach to return lists that never actually contain anything until they are read. That is if my <em>List&lt;ClassDoc&gt; </em>is lazy then it won’t actually contain anything until someone tries to read from it. It’ll use 0 memory.</p><p>In other words, if <em>getClassDocs</em>, <em>toJSON </em>and <em>stringify </em>are all lazy then all of the following calls:</p><pre>List&lt;ClassDoc&gt; classDocs = api.getClassDocs();<br>List&lt;JSONObject&gt; jsonObjects = api.toJSON(classDocs);<br>List&lt;String&gt; jsonString = api.stringify(jsonObjects);</pre><p>won’t ever actually do any computation. Since each method is lazy they just return lists that don’t have anything in them until someone tries to read from them.<strong> It’s just like telling your mom you finished your homework but not actually starting your homework until she asks to see it later that night.</strong></p><p>Since lazy lists don’t produce elements until they are read we effectively get all of the benefits of the looping approach (low memory usage) and all the benefits of the composable approach (just working with normal lists).</p><h4>Great but how can I be lazy on the JVM?</h4><ol><li>Clojure — all map operations are lazy &amp; has lazy sequences</li><li>Scala — has lazy sequences</li><li>Write your own iterables which perform lazily</li></ol><p>My complete 30 lines of lazy Clojure code that converts Javadoc to JSON can be found <a href="https://github.com/tantaman/jsonDoclet/blob/master/src/com/tantaman/doc/JsonDoclet.clj">here</a>.</p><p>Of course you could make the looping approach just as composable as the lazy approach by using the Reactive Extensions for the JVM (<a href="https://github.com/Netflix/RxJava">https://github.com/Netflix/RxJava</a>) but that is for a later post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4e6b044abfa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-development/practical-laziness-in-programming-e4e6b044abfa">Practical Laziness in Programming</a> was originally published in <a href="https://medium.com/software-development">Software Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oh Lisp]]></title>
            <link>https://medium.com/software-development/oh-lisp-b41a5d4e6882?source=rss-8935d0167b24------2</link>
            <guid isPermaLink="false">https://medium.com/p/b41a5d4e6882</guid>
            <dc:creator><![CDATA[Matt Crinklaw-Vogt]]></dc:creator>
            <pubDate>Thu, 15 Aug 2013 17:42:46 GMT</pubDate>
            <atom:updated>2013-08-15T17:42:46.223Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*roLgoGKqrdXQAR2b.jpeg" /></figure><p>If you ever tell someone you like Lisp and that Lisp is a more suitable language for the work you are doing most of the time you’ll get weird looks and comments like:</p><blockquote>“Isn’t that… old?”<br>“All I know is that it has parenthesis everywhere.”<br>“Is that like COBOL?”<br>“Why would you use an underpowered language like Lisp?”</blockquote><p>Which is unfortunate because I believe Lisp to be one of the most important programming languages we currently have. I’ve yet to find an article that concisely, clearly and effectively describes the advantages of Lisp to the Lisp skeptic, so here goes my attempt at it.</p><p>I’m sure you’re familiar with XML so let’s consider that for a moment.</p><p>You can think of Lisp as being like XML. There really isn’t anything to XML besides balanced &lt;&gt;’s yet it is tremendously useful. Because of how open ended the XML syntax is, you can use it to represent nearly any kind of <strong>data</strong> or <strong>program</strong>. Because of how simple the XML syntax is, it is easily read and manipulated by humans and programs.</p><p>Some examples where XML is in use:</p><ol><li><a href="http://ant.apache.org/">Ant</a> uses XML to define build files.</li><li><a href="http://en.wikipedia.org/wiki/Web_Services_Description_Language">WSDL</a> uses XML to describe web services</li><li>XML <a href="http://exist-db.org/exist/apps/homepage/index.html">databases</a></li><li><a href="http://en.wikipedia.org/wiki/XSLT">XSLT</a> is an XML language for translating XML to other formats (Lisp’s analog would be macros)</li><li><a href="http://en.wikipedia.org/wiki/AIML">AIML</a> — Artificial Intelligence Markup Language</li></ol><p>As you can see from those examples and likely your own experience with XML, XML allows you to come up with your own tags and thus your own sub-language. Ant uses XML as a build language, WSDL uses it as a service language, ALICE uses it as an AI language and XSLT uses it as a macro language.</p><p>An external program or parser (e.g., Ant, XSLT, Maven, JAXB) is what confers meaning upon those tags by using them. When you’re defining a new XML schema, you’re defining a new language for your problem domain.</p><p>To make the comparison of XML and Lisp concrete, here is a comparison of an XML document and a representation of it in Lisp:</p><pre>&lt;!--xml--&gt;<br>&lt;println&gt;<br>    &lt;even&gt;<br>      &lt;list&gt;&lt;elem&gt;1&lt;/elem&gt;&lt;elem&gt;2&lt;/elem&gt;&lt;elem&gt;3&lt;/elem&gt;&lt;/list&gt;<br>    &lt;/even&gt;<br>&lt;/println&gt;</pre><pre>; Lisp<br>(println (even (list 1 2 3))) ; =&gt; 2</pre><p>In Lisp, every “tag” is a function or a macro. So in our above example, <em>println</em>, <em>even</em> and <em>list</em> are functions or macros that you would define in Lisp.</p><p>Since each “tag” is a function or macro, instead of having one program to confer meaning upon (i.e., to interpret) a set of tags like in XML, Lisp allows every “tag” to consume and interpret the expressions given to it. It’s like allowing Ant as a built in function to handle a section of your code and then a ALICE to handle another section.</p><p>Every “tag” in Lisp is another opportunity to define a perfectly tailored way of doing things. Just like Ant and Maven are two uses of the XML format for their own goals, the Lisp functions and macros you define are tailored uses of <a href="http://en.wikipedia.org/wiki/S-expression">S-expressions</a> (the nested lists or “parenthetical expressions” in Lisp) for their own goals.</p><p>The minimal syntax of Lisp and XML allows your programs to talk solely in terms of the problem domain (XML is certainly verbose but it is minimal in the number of components that make up its syntax).</p><p>Let’s look at a comparison of Lisp, XML and Javascript.</p><p>Lisp code to construct a deck of slides:</p><pre>(deck (slides <br>        (slide <br>          (components<br>             (text-box &quot;some text&quot; (position 0 0))<br>             (image &quot;img.png&quot; (position 0 200)))<br>        (slide ...))) </pre><p>XML:</p><pre>&lt;deck&gt;<br>  &lt;slides&gt;<br>    &lt;slide&gt;<br>      &lt;components&gt;<br>        &lt;text-box text=&quot;some text&quot; position=&quot;0,0&quot;/&gt;<br>        &lt;image src&quot;img.png&quot; position=&quot;0,200&quot;/&gt;<br>      &lt;/component&gt;<br>    &lt;/slide&gt;<br>  &lt;/slides&gt;<br>&lt;/deck&gt;</pre><p>Javascript to construct a deck of slides:</p><pre>var deck = new Deck();<br>var slide1 = new Slide([new TextBox(&quot;some text&quot;, new Position(0, 0)), new Image(&quot;img.png&quot;, new Poisiton(0, 200)]);<br>deck.add(slide1);<br>...</pre><p>You can see that while the Lisp and XML examples only have items relevant to the problem domain, the Javascript one is afflicted with extra ceremony (just imagine what it’d be like in Java…). Of course we could make the Javascript one more lisp-like (and take out some of the ceremonial syntax of the language) by using factories:</p><pre>Deck([Slide([TextBox(&quot;some text&quot;, Pos(0,0)), Image(&quot;img.png&quot;, Pos(0,200))])]);</pre><p>but it is still lacking. It is lacking because the Javascript code is stuck and rigid in that state. Javascript code isn’t <strong>data</strong>. In Lisp, the code can be treated as and manipulated as a list of lists. The code <strong>is</strong> data.</p><p>Lisp code is written as lists. In the Lisp code above, `(deck` starts the first list of symbols, `(slides` is a sub-list of `(deck` and `(slide` a sub-list of `(slides` and so on. In Lisp, you can create code and macros that take in and manipulate these code-as-list forms. E.g., calling <em>first</em> on the Lisp code above would return the <strong>symbol</strong> ‘deck’. Calling <em>second </em>(to get the second element of code) would return the <strong>code (as a list) </strong>that defines the list of slides. You can even add and remove from these lists to generate new code. This is similar to XML where you can use XSLT translate the XML into a new form.</p><p>This notion of code as data that can be manipulated by Lisp allows Lisp programs to be extremely flexible and expressive. With Lisp you can create whatever forms you need that aren’t yet present in the language.</p><blockquote>Essentially, Lisp can manipulate Lisp programs just as easily as XML can be manipulated with the DOM or as easily as HTML can be manipulated via jQuery.</blockquote><p>Recap,</p><ul><li>Lisp lets you create your own languages tailored to the problem domain, just as XML lets you create custom document formats for your domain.</li><li>The minimal syntax of Lisp clears away everything that is standing between you and your problem.</li><li>Lisp code and Lisp lists are interchangeable. I.e., you can take a Lisp list and evaluate it into a program and you can take a Lisp program and pass it around, and manipulate it, as a list of lists.</li><li>Just as XML can be trivially parsed and manipulated, Lisp code can be manipulated by Lisp functions and/or Lisp macros. <strong>The Lisp code is parsed into a data structure (a list of lists / tree / </strong><a href="http://en.wikipedia.org/wiki/S-expression"><strong>S expression</strong></a><strong>) for you to manipulate, just like the XML you work with is usually parsed into a DOM (a tree) for you to manipulate.</strong></li></ul><p>Here is an interesting comparison of <strong>Lisp &amp; Lisp Macros</strong> to <strong>XML &amp; XSLT </strong>(courtesy of <a href="http://c2.com/cgi/wiki?LispVsXml">http://c2.com/cgi/wiki?LispVsXml</a>) to further illustrate the nature of Lisp.</p><p>Notice how the code passed to the Lisp macro is accessed and used as a list of lists (which is a tree).</p><p><strong>Lisp Macro:</strong></p><pre> ; words is the code passed to the macro<br> (defmacro dictionary (&amp;rest words) <br> `(progn<br>	(format t &quot;&lt;dictionary&gt;~%&quot;)<br>        <br>          ; for each word in words<br>	(dolist (word &#39;,words) <br>	  (format t &quot; &lt;word&gt;~%&quot;)</pre><pre>            ; get the first item (e.g., xml,java,lisp)<br>	  (format t &quot;	&lt;id&gt;~A&lt;/id&gt;~%&quot; (first word))<br><br>            ; get the second item (i.e., the definition)<br>	  (format t &quot;	&lt;def&gt;~S&lt;/def&gt;~%&quot; (second word))</pre><pre>	  (format t &quot; &lt;/word&gt;~%&quot;))<br>	  (format t &quot;&lt;/dictionary&gt;~%&quot;))<br>        )</pre><p>Now, when I enter the following sexpr...</p><pre> (dictionary<br>	(xml &quot;data language&quot;)<br>	(java &quot;programming language&quot;)<br>	(lisp &quot;programming and data language&quot;))</pre><p>...I get the following result:</p><pre> &lt;dictionary&gt;<br>	&lt;word&gt;<br>	&lt;id&gt;xml&lt;/id&gt;<br>	&lt;def&gt;&quot;data language&quot;&lt;/def&gt;<br>	&lt;/word&gt;<br>	&lt;word&gt;<br>	&lt;id&gt;java&lt;/id&gt;<br>	&lt;def&gt;&quot;programming language&quot;&lt;/def&gt;<br>	&lt;/word&gt;<br>	&lt;word&gt;<br>	&lt;id&gt;lisp&lt;/id&gt;<br>	&lt;def&gt;&quot;programming and data language&quot;&lt;/def&gt;<br>	&lt;/word&gt;<br> &lt;/dictionary&gt;</pre><p><strong>XSLT:</strong></p><pre>&lt;xsl:template match=&quot;dictionary&quot;&gt;<br>	&lt;xsl:text&gt;(dictionary&lt;/xsl:text&gt;<br>	&lt;xsl:apply-templates /&gt;<br>	&lt;xsl:text&gt;)&amp;#10;&lt;/xsl:text&gt;<br> &lt;/xsl:template&gt;</pre><pre> &lt;xsl:template match=&quot;word&quot;&gt;<br>	&lt;xsl:text&gt;&amp;#10; (&lt;/xsl:text&gt;<br>	&lt;xsl:value-of select=&quot;id&quot; /&gt;<br>	&lt;xsl:text&gt; &amp;quot;&lt;/xsl:text&gt;<br>	&lt;xsl:value-of select=&quot;def&quot; /&gt;<br>	&lt;xsl:text&gt;&amp;quot;)&lt;/xsl:text&gt;<br> &lt;/xsl:template&gt;</pre><p>Now, when I enter the following XML,</p><pre> &lt;dictionary&gt;<br>	&lt;word&gt;<br>	&lt;id&gt;xml&lt;/id&gt;<br>	&lt;def&gt;data language&lt;/def&gt;<br>	&lt;/word&gt;<br>	&lt;word&gt;<br>	&lt;id&gt;java&lt;/id&gt;<br>	&lt;def&gt;programming language&lt;/def&gt;<br>	&lt;/word&gt;<br>	&lt;word&gt;<br>	&lt;id&gt;lisp&lt;/id&gt;<br>	&lt;def&gt;programming and data language&lt;/def&gt;<br>	&lt;/word&gt;<br> &lt;/dictionary&gt;</pre><p>I get the following result:</p><pre> (dictionary<br>	(xml &quot;data language&quot;)<br>	(java &quot;programming language&quot;)<br>	(lisp &quot;programming and data language&quot;))</pre><p>I hope this will have at least ignited some interest in Lisp in you.</p><p>It would be interesting to extend this analogy of Lisp and XML to something like “JSON as a programming language…”, maybe another time.</p><p>Lisp resources:</p><ul><li><a href="http://clojure.org/">Lisp on the JVM, CLR and Javascript</a></li><li><a href="http://racket-lang.org/">Lisp for creating new languages that don’t look like Lisp</a></li><li><a href="http://common-lisp.net/">Common Lisp</a></li></ul><p>XML based programming languages (not that I think these are a terribly good idea due to the verbosity of XML but it illustrates the flexibility of XML, and thus Lisp, effectively):</p><ul><li><a href="http://en.wikipedia.org/wiki/XSLT">XSLT</a> (turing complete)</li><li><a href="http://en.wikipedia.org/wiki/Schematron">Schematron</a></li><li><a href="http://en.wikipedia.org/wiki/POSXML">POSXML</a></li><li><a href="http://en.wikipedia.org/wiki/XProc">XProc</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b41a5d4e6882" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-development/oh-lisp-b41a5d4e6882">Oh Lisp</a> was originally published in <a href="https://medium.com/software-development">Software Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inheritance, Aggregation and Pipelines]]></title>
            <link>https://medium.com/software-development/inheritance-aggregation-and-pipelines-609943f77683?source=rss-8935d0167b24------2</link>
            <guid isPermaLink="false">https://medium.com/p/609943f77683</guid>
            <dc:creator><![CDATA[Matt Crinklaw-Vogt]]></dc:creator>
            <pubDate>Tue, 30 Jul 2013 17:44:08 GMT</pubDate>
            <atom:updated>2013-07-30T17:44:08.713Z</atom:updated>
            <content:encoded><![CDATA[<p>How does one write software that can be extended?</p><p>I think many developer’s first instinct is to set up some form of inheritance hierarchy. Inheritance is a step in the right direction but it is very restrictive. The problem with inheritance is that relationships between your components and their extensions are rigidly defined at compile time.</p><p>Take a set of classes that provide access to resources at various URIs as an example. The base class just provides get/put/delete operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/0*xWt1N8G9tAHw4elF.png" /><figcaption>base resource provider. get/put/delete resources at different URIs</figcaption></figure><p>Later, someone wants to add some sort of caching to this. Their first instinct is to extend the functionality via inheritance. So now you have something that looks like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/0*FYPGEVmLpmKZT4Kp.png" /><figcaption>ResourceProvider extended to add caching</figcaption></figure><p>But someone else in the organization may have a use case where LRU caching doesn’t work well so they add a new extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/0*0YTDiFjqPgATRaNS.png" /><figcaption>Two different caching algorithms</figcaption></figure><p>and finally a requirement is added that accesses to certain resource provider instances need to be journaled. So where do you put the journaling class in the hierarchy? You could inherit directly from <strong>ResourceProvider</strong> but then should you update the cache implementations to inherit from the journaling class? What about the use cases that need caching but not journaling? Or journaling and not caching? Inheritance has forced you into an awkward situation where you can’t perfectly capture any of the relationships you need.</p><p>Another problem with the inheritance solution is that you can’t change your extension composition at runtime. E.g., you can’t easily change caching algorithms at runtime and you can’t easily add or remove journaling from a <strong>ResourceProvider</strong> at runtime.</p><p>A slightly more experienced developer would have probably tackled this problem with aggregation instead of inheritance.</p><h3>Aggregation</h3><p>A solution that depends on aggregation would differ in that instead of each class inheriting from <strong>ResourceProvider </strong>each class would implement an <strong>IResourceProvider </strong>interface and contain an instance of an <strong>IResourceProvider</strong>.</p><p>If you want to make a Journaling, LRU cached resource provider then you instantiate those three classes and have them contain one another. Here is a class diagram to illustrate a Journaling, LRU cached resource provider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/0*GLdudYA_my8wDiVL.png" /><figcaption>Instead of inheriting, everyone implements a common interface and then holds an instance of that interface.</figcaption></figure><p>The <strong>JournalingResourceProvider</strong> contains an <strong>LRUCachedResourceProvider</strong> which contains a regular <strong>ResourceProvider</strong>.<strong> </strong>Calls made on the <strong>JournalingResourceProvider</strong> are handled and then passed on to the <strong>LRUCachedResourceProvider</strong> where they are handled by the cache and then passed on to the actual <strong>ResourceProvider</strong> if need be.</p><p>Since these classes contain instances of <strong>IResourceProvider </strong>and not any specific implementation, you can create any configuration of resource providers that you like. You could have a Journaling, MRU Cached resource provider or even a Journaling, MRU Cached and LRU Cached resource provider by varying your composition of instances of these classes.</p><p>Since aggregation sets up relationships between objects via member variables you can manipulate aggregation relationships at runtime. That is, you can change your cache from LRU to MRU by changing what delegate you’re holding.</p><p>Of course aggregation has its limitations as well. In the prior example, if you want to have the <strong>JournalingResourceProvider</strong> change its delegate from an <strong>LRUCachedResourceProvider</strong> to a <strong>MRUCachedResourceProvider</strong> you’ll have to do some fiddling. You need to get the original <strong>IResourceProvider</strong> held by the <strong>LRUCachedResourceProvider</strong> and put it into the new <strong>MRUCachedResourceProvider</strong>. You’ll also have to explicitly update the reference managed by the <strong>JournalingResourceProvider</strong>.</p><p>More generally, adding and removing delegates in the middle of the chain of aggregations is difficult. You have to touch the objects on either side of what is being added, removed or replaced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/0*aAObMhbhtqIygCj2.png" /><figcaption>Aggregate1&#39;s link needs to be updated to refer to Replacement. Aggregate2 needs to expose its link so Replacement can refer to Aggregate3.</figcaption></figure><p>This difficulty in replacing arbitrary parts of the aggregation isn’t ideal but luckily there is a solution.</p><h3>Pipelines</h3><p>Pipelines are the final abstraction that will help us resolve all of the difficulties mentioned previously. Instead of each class being responsible for holding its own delegate we move that responsibility to a 3rd party.</p><p>Continuing our resource provider example, all of the instances of <strong>IResourceProvider</strong> that we want to chain together will now be held by a <strong>Pipeline </strong>class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*OgJC-GK-UUvscHiu.png" /><figcaption>The Pipeline holds a list of IResourceProviders instead of the IResourceProviders holding one another.</figcaption></figure><p>As you can see the <strong>Pipeline</strong> holds an arbitrary number of <strong>IResourceProviders </strong>and allows <strong>IResourceProvider</strong> instances to be added and removed. The <strong>Pipeline</strong> also implements the <strong>IResourceProvider</strong> interface since you’ll invoke methods on the pipeline which will forward those invocations to the members of the pipeline.</p><pre>public static void main(String [] args) {<br>   resourcePipeline.put(uri, resource);<br>}</pre><pre>// A method from a very naive Pipeline implementation<br>public class Pipeline {<br>…<br>public put(String uri, Resource resource) {<br>  for (IResourceProvider handler : handlers) {<br>    handler.put(uri, resource);<br>  }<br>}<br>…<br>}</pre><p>This moving of responsibility allows us to easily add/remove/replace items in the pipeline without touching any objects besides the <strong>Pipeline</strong> instance.</p><p>Pipelining also allows us to build more and more complex processing without ever impacting existing classes.</p><p>-Need to log put requests? Add an object to the pipeline for it.</p><p>-Need to record calls to a specific URI? Add an object to the pipeline for it.</p><p>-Need to calculate the number of bytes being put to a URI? Add an object to the pipeline for it.</p><p>The simplest pipeline just invokes a method on every handler it contains. Kind of like notifying listeners. Of course this is not always how you would like to do things so a more robust pipeline passes a “<strong>next</strong>” or “<strong>context</strong>” object to each member of the pipeline that it calls. Using the context object, members of the pipeline can choose to stop a call from continuing down the pipeline or make adjustments to the parameters of a call as it moves down the pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/0*2eCzRYPJyVWpT5no.png" /><figcaption>A new interface for items in the pipeline. The Context object can be used to stop calls from moving down the pipeline among other things.</figcaption></figure><p>A common use for the <strong>Context</strong> object is to allow members of the pipeline to choose when to call the next member of the pipeline. The context object could also allow a member of the pipeline to pass an updated set of parameters to the next member.</p><pre>// An example of a member of the ResourceProvider Pipeline.<br>public class LRUCachedResourceProvider implements IPipelinedResourceProvider {<br>  …<br>  public void get(String uri, Context ctx) {<br>    if (cacheContains(uri)) {<br>      // we found it in our cache so return and don’t <br>      // call the next member of the pipeline.<br>      return getCachedValue(uri);<br>    } else {<br>      // It wasn’t in the cache.  Forward call to<br>      // the next handler in the pipeline.<br>      return ctx.nextGet(uri, ctx);<br>    }<br>  }<br>  …<br>}</pre><p>If you want to see the pipeline pattern in practice you can check out the Netty project and their <a href="http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/ChannelPipeline.html">ChannelPipeline</a>.</p><p>Dynamic languages have a surprisingly easy time when it comes to constructing pipelines. Here an <a href="https://github.com/tantaman/Pipeline.js/blob/master/README.md">example</a> of using <a href="https://github.com/tantaman/Pipeline.js">Pipeline.js</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=609943f77683" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-development/inheritance-aggregation-and-pipelines-609943f77683">Inheritance, Aggregation and Pipelines</a> was originally published in <a href="https://medium.com/software-development">Software Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Services and Coupling]]></title>
            <link>https://medium.com/software-development/services-and-coupling-d6f3fa73b28e?source=rss-8935d0167b24------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6f3fa73b28e</guid>
            <dc:creator><![CDATA[Matt Crinklaw-Vogt]]></dc:creator>
            <pubDate>Sat, 29 Jun 2013 00:21:46 GMT</pubDate>
            <atom:updated>2013-08-15T14:48:12.393Z</atom:updated>
            <content:encoded><![CDATA[<p>Lines of code like:</p><blockquote>PositionCalculator calc = new MercatorPositionCalculator();</blockquote><p>(where <strong><em>PositionCalculator</em></strong> is an interface and <strong><em>MercatorPositionCalculator</em></strong> the implementation) have always bugged me and probably any other astute programmer out there.</p><p>We’re trying to be generic by typing our variable as the interface type but that one call to <strong><em>new MercatorPositionCalculator()</em></strong> suddenly death-ties the class containing that line to the <strong><em>MercatorPositionCalculator</em></strong>.</p><p>The use of the interface is effectively useless in a line where you directly construct the implementation of the interface.</p><h4>Dependency Injection</h4><p>Dependency injection helps to resolve the above problem but it still falls short. With dependency injection your class no longer directly constructs its dependencies but instead takes them in as parameters.</p><p>Example:</p><pre>public class ObjectDrawer {<br>  private final PositionCalculator calc;<br>  public ObjectDrawer(PositionCalculator calc) {<br>    this.calc = calc;<br>  }<br>}</pre><p>This trick of pushing dependencies out and requiring them to be passed in makes our <strong><em>ObjectDrawer</em></strong> more reusable since it now only has interface level dependencies.</p><p>Users of <strong><em>ObjectDrawer</em></strong> can use it with <strong><em>Spherical</em></strong>, <strong><em>Stereographic</em></strong>, <strong><em>Mercator</em></strong> or any other type of <strong><em>PositionCalculator </em></strong>by passing in the correct implementation.</p><p>Using Dependency Injection we’ve resolved the dependency problem at the class level but our component, as a whole, still has hard dependencies on the implementations being used.</p><h4>Enter Services</h4><p>Using dependency injection, construction of dependencies is still the responsibility of your component. Services, however, push your dependencies out to their final level.</p><p>In a service oriented world each component is responsible for instantiating the implementations of the services that it provides. That is, instead of the user of an interface instantiating the implementation of that interface, the component providing the implementation is responsible for instantiating it.</p><blockquote>Since the provider of an implementation is also responsible for instantiating the implementation you no longer have any cross component dependencies! (other than at the interface level but your interfaces should be in a component all on their own)</blockquote><p>This makes total sense since the thing providing an implementation doesn’t have to pull in extra stuff to instantiate the implementation. Conversely, if the consumer of some some interface had to instantiate the implementation of that interface then it would have to pull the implementation in as a dependency.</p><p>The next question is how does the consumer of an interface get an implementation if the consumer, and nothing in the component that the consumer is a part of, instantiates the implementation?</p><p>In most service frameworks there is a notion of a registry. The registry is where components go to register the services that they provide or look up the services they need.</p><p>If I have a component that handles Mercator coordinates then it would register its <strong><em>MercatorCalculator</em></strong> with the registry under the interface name <strong><em>PositionCalculator.</em></strong></p><p>Another component that handles Stereographic coordinates would register its <strong><em>StereographicCalculator</em></strong> under the same <strong><em>PositionCalculator</em></strong> interface name. Various bits of metadata can be attached to service registrations to handle the case where multiple services implementing the same interface are registered.</p><p>The components that are clients of a service then look up the services they need by their interface name and/or additional metadata. This allows components to be dependent on <strong>descriptions</strong> of <strong>capabilities</strong> and not some specific set of implementations.</p><p>So a component that relies on <strong><em>PositionCalculators</em></strong> would then do something like:</p><pre>calculator = registry.getService(PositionCalculator.class.getName(), worldLocation);</pre><p>to get the implementation that it needs. As you can see, the component only has a dependency on the <strong><em>PositionCalculator </em></strong>interface.</p><p>The second parameter would be additional metadata to discriminate between available position calculators. The additional metadata should be something that is well within the domain of the component. In this case, the metadata is a conflated location in the world since that determines if we should use <a href="http://en.wikipedia.org/wiki/Universal_Polar_Stereographic_coordinate_system">Stereographic</a> or <a href="http://en.wikipedia.org/wiki/Universal_Transverse_Mercator">Mercator</a> coordinate systems.</p><p>If you’re developing in Java, <a href="http://en.wikipedia.org/wiki/OSGi">OSGi</a> has a great component and service model (although getting up and running for your first time will be a trial but it is worth it in the end).</p><p>If you’re a Javascript developer, <a href="http://angularjs.org/">AngularJS</a> has a decent service system with automatic dependency injection.</p><p>There is also <a href="https://github.com/tantaman/ServiceRegistry.js">ServiceRegistry.js</a> which is used by <a href="http://strut.io/">Strut.io</a> to manage storage providers, presentation generators, available edit modes and more. It lacks an automatic dependency injection mechanism and so it can be quite cumbersome but it does account for the service lifecycle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6f3fa73b28e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/software-development/services-and-coupling-d6f3fa73b28e">Services and Coupling</a> was originally published in <a href="https://medium.com/software-development">Software Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Talent vs Genius]]></title>
            <link>https://medium.com/conceptual-distinctions/talent-vs-genius-88f8f7fca210?source=rss-8935d0167b24------2</link>
            <guid isPermaLink="false">https://medium.com/p/88f8f7fca210</guid>
            <dc:creator><![CDATA[Matt Crinklaw-Vogt]]></dc:creator>
            <pubDate>Fri, 28 Jun 2013 03:04:42 GMT</pubDate>
            <atom:updated>2013-06-28T03:05:05.549Z</atom:updated>
            <content:encoded><![CDATA[<p>Happening to have the behaviors that allow one to excel is talent.</p><p>Being able to discover and cultivate the behaviors that allow one to excel is genius.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88f8f7fca210" width="1" height="1" alt=""><hr><p><a href="https://medium.com/conceptual-distinctions/talent-vs-genius-88f8f7fca210">Talent vs Genius</a> was originally published in <a href="https://medium.com/conceptual-distinctions">Conceptual Distinctions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>