<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <body>Really cool post by Lau Jensen on using clojure/compojure to replicate reddit. This dude is pretty much the only guy on the internet talking about using clojure for the web, I really hope he keeps going with these tutorial style posts

[link][1]


  [1]: http://www.bestinclass.dk/index.php/2010/02/reddit-clone-in-10-minutes-and-91-lines-of-clojure/</body>
    <category-id type="integer">17</category-id>
    <created-at type="datetime">2010-02-02T23:06:36Z</created-at>
    <id type="integer">40</id>
    <live type="boolean">true</live>
    <publish-date type="datetime">2010-02-02T23:06:44Z</publish-date>
    <slug>reddit-in-92-lines-of-clojure</slug>
    <title>Reddit in 92 lines of clojure</title>
    <updated-at type="datetime">2010-02-02T23:06:44Z</updated-at>
  </post>
  <post>
    <body>Ran across this today for the first time, and I am so impressed I don't think I will ever use the term &quot;Monkey Patch&quot; again!

from [wikipedia][1]

&gt; Some members in the Ruby world started adopting the term duck punching in lieu of monkey patching. This term comes from the extensive use of duck typing in Ruby and Python as explained by Adam Keys and Patrick Ewing at RailsConf 2007:[3]

&gt; Well, I was just totally sold by Adam, the idea being that if it walks like a duck and talks like a duck, it&#8217;s a duck, right? So if this duck is not giving you the noise that you want, you&#8217;ve got to just punch that duck until it returns what you expect. &#8211; Patrick Ewing

  

[1]: http://en.wikipedia.org/wiki/Monkey_patch

</body>
    <category-id type="integer">14</category-id>
    <created-at type="datetime">2010-02-02T19:51:24Z</created-at>
    <id type="integer">39</id>
    <live type="boolean">true</live>
    <publish-date type="datetime">2010-02-02T19:51:31Z</publish-date>
    <slug>duck-punching</slug>
    <title>Duck Punching</title>
    <updated-at type="datetime">2010-02-02T19:51:31Z</updated-at>
  </post>
  <post>
    <body>So after a few days of reading and playing around in the REPL, I have a few things I can say I have learned.

Forms
========

Clojure syntax is the most simple thing I have ever seen in a language. The anatomy is this:

    (symbol arguments return)

The parens mean a list, which is the basic data structure. One core concept in all Lisps is that the code and the data are one and the same, so code execution is achieved with a list that starts with a symbol.

Arguements are everything in the list up to the last item. The last item is what the form will evaluate to.

This allows for a hell of a lot of consistency. 

For example, in java, you do something like this for math

    1 * 2 * 3

In clojure, that becomes

    (* 1 2 3)

In java, you define a function like this

    public void string name(int arg1, int arg2) { 
      return arg1 * arg2 
    }

in clojure, that becomes

    (defn name [arg1 arg2] (* arg1 arg2))

that kind of syntax even extends to java interop. In java, to show a swing dialog, you would do something like this

    javax.swing.JOptionPane.showMessageDialog(null, &quot;Hello World&quot;);

in clojure, that becomes

    (. javax.swing.JOptionPane (showMessageDialog nil &quot;Hello World&quot;))

This way of doing things takes a lot of getting used to, and I honestly can't say I am there yet. From an intellectual point of view though, I think it is hela-cool, basically reducing down the syntax of an incredable powerful language down to a single rule.

Purity of Functions
======================

For a function to be _pure_, it takes arguments, does something to them, and returns the result. In my earlier example of 

    (defn name [arg1 arg2] (* arg1 arg2)) 

you can see that, it takes two arguments, multiplies them, and returns the result. What happened if we wanted to show a dialog box with the result, as well as return it? 

In clojure, showing the message box is considered a _Side Effect_, it is something else that is happening which doesn't relate to the function itself. Because clojure is a language that makes a distinction between pure and impure functions, all side effects need to be inside a `do` form.

    (defn foo
          [arg1 arg2]
          (do (. javax.swing.JOptionPane 
                 (showMessageDialog nil (* arg1 arg2))))
          (* arg1 arg2))

call that with `(foo 2 2)` and you will get a box popping up that says `4`, as well as having the form evaluate to 4.

This is sort of tangential, but we can clean up that function some more. Currently the multiplication is being used in two places, which is not very DRY. In clojure, there is a keyword called `let`, which allows you to define temporary bindings that only exist in the scope of that form. Adding a let form to the function above will give us

    (defn foo
          [arg1 arg2]
          (let [arg3 (* arg1 arg2)]
          (do (. javax.swing.JOptionPane 
                 (showMessageDialog nil arg3)))
          arg3))
          
This accomplishes the same thing as the first version, only it is a bit simpler, and also more efficent since it only does the multiplication once instead of twice. One last step, having the fully qualified name for JOptionPane seems a bit messy, thankfully clojure has a java import method as well
    
    (import '(javax.swing JOptionPane))
    
    (defn foo
          [arg1 arg2]
          (let [arg3 (* arg1 arg2)]
          (do (. JOptionPane (showMessageDialog nil arg3)))
          arg3))

Much nicer :-) 

That is about as far as I can currently go with clojure forms, but I know it is the tip of the iceburg. One big gotcha for me was how sometimes functions treat vectors as a data structure, other times they will end up pairing up the values into key/value pairs (like the case of `let`).  </body>
    <category-id type="integer">17</category-id>
    <created-at type="datetime">2010-01-20T20:30:30Z</created-at>
    <id type="integer">38</id>
    <live type="boolean">true</live>
    <publish-date type="datetime">2010-01-21T00:37:28Z</publish-date>
    <slug>beginning-of-clojure-enlightenment</slug>
    <title>Beginning of Clojure Enlightenment</title>
    <updated-at type="datetime">2010-01-21T00:37:28Z</updated-at>
  </post>
  <post>
    <body>&gt;&gt;&quot;the greatest single programming language ever designed&quot;

_- Alan Kay, on Lisp_


&gt;&gt;&quot;Greenspun's Tenth Rule of Programming: any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp.&quot;

_- Philip Greenspun_

&gt;&gt;&quot;Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.&quot;

_- Eric Raymond, &quot;How to Become a Hacker&quot;_

&gt;&gt;&quot;Lisp has jokingly been called &quot;the most intelligent way to misuse a computer&quot;. I think that description is a great compliment because it transmits the full flavor of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.&quot;

_- Edsger Dijkstra, CACM, 15:10_

As a relatively young developer who didn't go the whole university route, one of the things that I have always felt was lacking from not doing the CS thing was an understand of Lisp. When most of the greatest hackers of all time speak about a language in revered tones, you sort of wonder what it is that you are missing out on.

Deciding on learning a new language, I was hit by the whole &quot;what to choose&quot; thing again. Lisp has always been something I wanted to look into, but I had a bit of a problem digging into something at I perceived to be (at this point anyways) mostly an academic language. Enter Clojure.

Clojure
-------

Clojure is a Lisp dialect for the JVM. The java integration seems (if anything) to be better then most JVM languages, which means you get all java libraries pretty much out of the box. It takes an opinionated stance on concurrency, and all data structures are both fast and immutable out of the box. In fact, to introduce any sort of mutability, you have to jump through some hoops. While the performance isn't at the level of java, it comes very close for most things, generally doing better then languages like JRuby and JPython.

As a web guy, all this means that you get existing java servers and infrastructure out of the box. There is also a minimalist web framework called Compojure which, while in its early stages, already is pretty awesome.

First Impressions
-----------------

Probably something along the lines of &quot;wtf.&quot;. I've got a decent amount of languages under my belt at this point, and usually learning a new one involves a whole bunch of easy to understand syntax, and then a couple of topics that require some work to wrap my head around. Clojure hasn't been like that. Pretty much from the first page of [Pragmatic Clojure][pragcloj], it has been along the lines of &quot;read two pages, realize I didn't fully grasp what was on the previous page, jump back and read it again&quot;. 

I am nowhere near the point where I could write something more significant then a hello, world style app. That being said, I have been enjoying working at it, and have been very impressed by what I have grokked so far. More on this in weeks to come.

[pragcloj]:http://pragprog.com/titles/shcloj/programming-clojure


</body>
    <category-id type="integer">17</category-id>
    <created-at type="datetime">2010-01-20T16:54:09Z</created-at>
    <id type="integer">37</id>
    <live type="boolean">true</live>
    <publish-date type="datetime">2010-01-20T16:54:37Z</publish-date>
    <slug>clojure-first-impressions</slug>
    <title>Clojure: First Impressions</title>
    <updated-at type="datetime">2010-01-20T16:54:37Z</updated-at>
  </post>
  <post>
    <body>Some may have noticed the bubbling, fanboy nature of pretty much everything I have to say about ruby. I have found myself in this place before a whole bunch of times, it is this great period between really starting to grasp more advanced concepts in a new language, and starting to bump up against some of its warts and shortcommings. Looking back at a previous post, [5 things I hate about C#][1], I could not give that list in ruby.

I have a personal goal to learn at least one new language per year. As the new year just passed, I am finding myself in a bit of a quandry; I have starting going deep on ruby, but I am still in the honeymoon period, and quite honestly, don't really want to move on yet. Thinking back on my goal of one language per year, I think the main thing to keep in mind was the original goal, to expand my mind. I am at the point where I can sort of grasp ruby idioms, and I am no longer writing C# in ruby syntax. I have also notice ruby idioms begin to influence my C# code, and I actually get frustrated when I know how elegant a solution to a specific problem could be, if not for an inflexible type system.

I am definitely not going to be leaving ruby behind, but at the same time it is time to start on something new. Ruby has given me the ability to think dynamically, and also taught me more about how incredible declarative programming can be when done right. The declarative programming aspect is actually what has driven my new choice of language, [Clojure][2].

I have zero knowledge of functional programming. I have a good idea of what is involved, and my time with javascript and ruby has taught me the benefits of declarative code over imparative code, but I have a feeling there is a lot more to learn by actually learning how to think in LISP. Looking at what is available (CL, Scheme, etc), it seems to me (being an outsider who knows nothing about that world) that Clojure is one of the more practical variants, and one where there are actually web frameworks available (no matter what happens, I will always be a web guy).

So I took the plunge. Ordered two books, the first is [Programming Clojure][3], and looks like a very solid &quot;From the ground up&quot; type book, which is what I need coming from an imparative background. I also picked up [The Joy of Clojure][4], which seems to more focus on the philosphy and idioms of the language (try the code j1337 for 30% off). It really looks like an exciting language, and I can't wait to start sinking my teeth into it.




  [1]: http://www.mattcode.net/posts/5-things-i-hate-about-csharp
  [2]: http://clojure.org/
  [3]: http://www.pragprog.com/titles/shcloj/programming-clojure
  [4]: http://www.manning.com/fogus/</body>
    <category-id type="integer">16</category-id>
    <created-at type="datetime">2009-12-07T19:45:59Z</created-at>
    <id type="integer">21</id>
    <live type="boolean">true</live>
    <publish-date type="datetime">2010-01-15T19:35:14Z</publish-date>
    <slug>the-honeymoon-period</slug>
    <title>The Honeymoon Period</title>
    <updated-at type="datetime">2010-01-15T19:35:14Z</updated-at>
  </post>
</posts>
