<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  <title>cleancode.se</title>
  <link rel="alternate" type="text/html" href="http://cleancode.se/" />
  
  <id>http://cleancode.se/atom.xml</id>
  <updated>2012-03-31T11:19:30Z</updated>
  <subtitle>My thoughts on clean code, languages and more.</subtitle>

  
    
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Cleancode" /><feedburner:info uri="cleancode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <title>Refreshing caches in ehcache</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/gNYbrRtdZp8/refreshing-caches-in-ehcache.html" />
    <id>http://www.cleancode.se/:/2012/03/31/refreshing-caches-in-ehcache</id>
    <updated>2012-03-31T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>A decription on how default caches in ehcache work, and how to change the behaviour.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;h3&gt;TL;DR&lt;/h3&gt;
&lt;p&gt;To (almost) never have a request hit a cold cache:&lt;br /&gt;
annotate your cached methods with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="nd"&gt;@Cacheable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cacheName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;propertyCache&amp;quot;&lt;/span&gt;
	&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;decoratedCacheType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;DecoratedCacheType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;REFRESHING_SELF_POPULATING_CACHE&lt;/span&gt;
	&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;refreshInterval&lt;/span&gt;&lt;span class="o"&gt;=[&lt;/span&gt;&lt;span class="n"&gt;oldTimeToLiveInterval&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;and in ehcache.xml change timeToLive to timeToIdle.&lt;/p&gt;
&lt;h3&gt;The full story&lt;/h3&gt;
&lt;p&gt;Ehcache has several ways to populate its cache. The sandardway is When a request is made and the value isnt in the cache. The cache forwards the request to the method beeing cahed. If you for example have a database call cached the call to the database will be made. This is whats commonly known as a read through cache. There is one thing to note: &lt;i&gt;The method call is not blocking. If a second call to the same method is done before the first call populates the cache. The second call will also forward to the method.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Ehcache has a way to change this behaviour called decorators. And &lt;a href="http://code.google.com/p/ehcache-spring-annotations/"&gt;ehcache spring annotations&lt;/a&gt; provide some with annotations.&lt;/p&gt;
&lt;p&gt;The first one solves the problem mentioned above. The only difference to the standard cache is that it is blocking. So if 10 calls comes at the same time, it will still just render one call to the database.  To use the blocking cache annotate the method as follows:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;&lt;span class="nd"&gt;@Cacheable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cacheName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;propertyCache&amp;quot;&lt;/span&gt;
	&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;decoratedCacheType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;DecoratedCacheType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;SELF_POPULATING_CACHE&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getProperties&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
	&lt;span class="c1"&gt;//call database&lt;/span&gt;
	&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can also add selfPopulatingTimeout=1234 to set the time to wait before giving up and forwarding to the method.&lt;/p&gt;
&lt;p&gt;I would say this solution is good enough. But, the second annotation provided is a self refreshing cache. all you need to do is to change the above to:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="java"&gt;    &lt;span class="nd"&gt;@Cacheable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cacheName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;propertyCache&amp;quot;&lt;/span&gt;
    &lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;decoratedCacheType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;DecoratedCacheType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;REFRESHING_SELF_POPULATING_CACHE&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getProperties&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
	&lt;span class="c1"&gt;//call database&lt;/span&gt;
	&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;you can also specify the interval for the refresh by adding “refreshInterval=1000” to the annotation. I added “refreshInterval=[value i had for timeToLive in ehcache.xml]”, to keep the caches to be updated in the same interval as before the change.&lt;br /&gt;
This will cause ehcache to save the metod calls used when getting a value, and in the background run it again every [refreshInterval] ms. This means your cache will be updated without any http request needing to wait for the slow database call. &lt;br /&gt;
You probably also want to open up your ehcache.xml and change timeToLiveSeconds to timeToIdleSeconds. Since the cache will be updated anyway, It is probably not a good idea to expire the cache based on when it was first used (the refresh thread wont reset the timeToLive timer). Since if you do,tThe items will still expire and cause them to be removed and that will cause an empty cache hit. Have in mind, that timeToIdle is probably going to be reset alot more then timeToLive. So if you keep it at the same value as you had timeToLive, you will probably end up with more items in the cache, taking up more memory. But that is dependent on how your application is used.&lt;/p&gt;
&lt;p&gt;It is worth noting. That if possible, it is even more effective to be sure to always update the caches when changing a value. Then you can set your caches ttl to extremly long times, and never have to call the database at all. But unfortunatly, that is often very hard to accomplish. For one, you most likely need to use something like terracotta to cluster your jvm’s. And to keep track of all chages is most likely a very hard task. It can be made easier if you plan for it from the begining. For me and the application i am working on. We dont realy have a database load problem and can easily let the caches be updated pretty often and just refresh some keys or entire caches when something changes.&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/gNYbrRtdZp8" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2012/03/31/refreshing-caches-in-ehcache.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Productivity tools for java developers</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/D7eQMujF0vE/productivity-tools.html" />
    <id>http://www.cleancode.se/:/2012/03/03/productivity-tools</id>
    <updated>2012-03-03T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>Tools that can help java developers to be more productive and keep the focus on writing code.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;As a developer, i use alot of tools, some help more then other. For a while now, i have been forcing myself to learn new tools to see what could increase my productivity. I thought maybe my learnings could be of some help.&lt;/p&gt;
&lt;h3&gt;jrebel&lt;/h3&gt;
&lt;p&gt;I remember the time before i found jrebel. I will never go back. Not having to redeploy is incredibly important. The time from implementation to feedback needs to be kept short, and with jrebel it is close to 0. It isnt perfect, there are some things that cant be reloaded, it uses some extra memory but is worth it.&lt;/p&gt;
 &lt;h3&gt;tmux&lt;/h3&gt;
&lt;p&gt;I have used screen for a long time togheter with irssi. But not much else. I also loved the split screens in emacs for a long time. With tmux you can have split screen terminals that live between sessions. Using split screens and multiple terminals in one window makes it easier for me to find the terminal i want. I have a terminal full screen on one monitor, and switch window for when im coding, deploying, or any other type of task.&lt;/p&gt;
&lt;h3&gt;zsh&lt;/h3&gt;
&lt;p&gt;Although bash is great, zsh is the next step. smarter auto-completion, a history that works, and so much more. you can probably get your bash to do most of the great stuff from zsh, but unless you are a hardcore bash lover. I dont see any point in that. zsh just works. Also take a look at oh-my-zsh (https://github.com/robbyrussell/oh-my-zsh). For plug in and theme handling.&lt;/p&gt;
&lt;h3&gt;sublime&lt;/h3&gt;
&lt;p&gt;I must admit I&amp;#8217;m very new to sublime, just about a week, but the love came fast. It does most of what my beloved netbeans does, but faster, and while using way less memory. Dont get me wrong, it is not an ide, it is an editor. But i still use it on my laptoptop for some java. It is just easier to get up and running. And with jrebel and maven cli, it just works great. But mostly i use it as a text editor, and to edit non java code.&lt;/p&gt;
&lt;h3&gt;vi(m)&lt;/h3&gt;
&lt;p&gt;first of all, im not saying vim is better then emacs (or the other way around). You should learn vim anyway. Not to replace your ide or editor of choice. But instead of using nano to edit config files and similar while on ssh. I dont think i have ever used a server without vi installed, but they hardly ever have for example emacs. And if im going to use vim, i should be good at it.&lt;/p&gt;
&lt;h3&gt;bash/awk/sed/cut/a good scripting language&lt;/h3&gt;
&lt;p&gt;Even if you are working with java al day long. Some tasks are more suitable for a small bash script or a oneliner with awk/sed. Writing a small shellscript is often incredibly fast. And when you know what you can do, you will find more simple scripts to make your everyday easier.&lt;br /&gt;
I also recomend learning a more powerfull scripting language, i prefer python but ruby or any other language that you most likely can run on any server is just as good. Some tasks are just to big for bash, but you still want it as a script.&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/D7eQMujF0vE" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2012/03/03/productivity-tools.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Simple configuration handling in tomcat</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/edZdN_5fnm4/simple-configuration-handling-in-tomcat.html" />
    <id>http://www.cleancode.se/:/2012/02/13/simple-configuration-handling-in-tomcat</id>
    <updated>2012-02-13T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>My simple solution on keeping production and development configuration in sync</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;Keeping configuration in sync and making it easy to change is extremly important. When doing changes in production you want to know that thera are no human errors in editing. And you want to be sure that the exact same configuration was tested in development before putting it live. There are several solutions that solve this problem. My favorite and probably the most known is puppet. But although puppet seems awesome, for many reasons we are not ready to implement puppet at work now. But i still wanted to fix my problem with configuration handling, atleast for some things. My first target beeing server.xml of tomcat. Mostly since we have been tuning our connectionpools alot lately, and it is tedious to change a number in 15+ places everytime. I looked around and didnt find anything simple enough. So i went the classic way and did it myself. I decided to use python (despite i don&amp;#8217;t really know it), mostly because i know al the &lt;br /&gt;
servers can run python and its a simple language.&lt;/p&gt;
&lt;p&gt;My script ended up as follows:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="python"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nn"&gt;sys&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nn"&gt;host&lt;/span&gt;	&lt;span class="n"&gt;Info&lt;/span&gt;
&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;server.xml&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;r&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;hostInfo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;where hostinfo is a python file with a map&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="python"&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="s"&gt;&amp;#39;mysqlHost&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;192.168.65.1,&lt;/span&gt;
&lt;span class="s"&gt;&amp;#39;hostname&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;myawesomeserver&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;&amp;#39;logdir&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;/mount/logs/myawesomeserver&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;&amp;#39;workerName&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;tomcat1&amp;#39;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And thats basicly it. i can now in my server.xml for example write:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="xml"&gt;   &lt;span class="nt"&gt;&amp;lt;Resource&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;jdbc/MySQL/myawesomedb&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;auth=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Container&amp;quot;&lt;/span&gt;
                   &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;javax.sql.DataSource&amp;quot;&lt;/span&gt;
                   &lt;span class="na"&gt;initialSize=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;maxActive=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;maxIdle=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;4&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;maxWait=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;10000&amp;quot;&lt;/span&gt;
                   &lt;span class="na"&gt;username=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;user&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;password=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;topsecret&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;driverClassName=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;com.mysql.jdbc.Driver&amp;quot;&lt;/span&gt;
                   &lt;span class="na"&gt;url=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;jdbc:mysql://{mysqlHost}:3306/myawesomedb&amp;quot;&lt;/span&gt;
                   &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now if i change the configuration, i can simply push it out to our stage enviroment first. Where i have one mysqlHost. And when i know the change works and its time for production. I can be sure to push out the exact same configuration to al my production servers without any risk of human errors. And al it took was 5 lines of python.&lt;/p&gt;
&lt;p&gt;This can (and should) be more generalised to take other files then server.xml. To actually push the configuration out to servers i can think of several ways. Either run it local for each server and pipe the output into files and push thoose into git/svn. Or you can keep the template in svn, and just keep the hostinfo.py on each server and run the script there.&lt;/p&gt;
&lt;p&gt;For me, this was a solution so obvious and simple that i at first didnt think it was worth a blog post. But then on the other hand. It took me several years to think of this obvious simple idea. So maybe, just maybe. Im not alone.&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/edZdN_5fnm4" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2012/02/13/simple-configuration-handling-in-tomcat.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Lessons learned from ehcache.</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/pt0SB2YtBJQ/ehcache-gotchas.html" />
    <id>http://www.cleancode.se/:/2012/02/07/ehcache-gotchas</id>
    <updated>2012-02-07T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>Some gotchas i stumbled on while using ehcache.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;I recently took over a webpage that is using ehcache for caching. I had never used ehcache before and from start i was far from impressed. It was alot of xml, i found the get from caches was much slower then what i am used to see in for example memcached. After some more looking around in the code i found a CacheManager implementation and a cacheKey generator. The later was my biggest surprise. To generate a key for a cache (get or put) it used a deep json representation of al the arguments of the method called. This included some methods that used Lists and other complex datastructures as arguments. This ofcource had to be changed. So i upgraded ehcache and added ehcache-spring-annotations to get rid of the xml. And i used the default deep hashcode key implementation provided by the annotations library. The upgrade and conversion went fairly smooth. But i learnt some things that i thought i should share:&lt;/p&gt;
&lt;p&gt;Ehcache doesnt have a default eviction policy, or rather. the default eviction policy is to not remove dead elements until the cache is full.  An element is only ever removed if the cache is full. Or when a get of the element realizes that the element is to old, then it is purged and a new item is generated. This behaviour can be changed in your applicationcontext by adding an eviction policy and setting a time in minutes for how often the cache should be cleaned.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="xml"&gt;    &lt;span class="nt"&gt;&amp;lt;ehcache:config&lt;/span&gt; &lt;span class="na"&gt;cache-manager=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;cacheManager&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;ehcache:evict-expired-elements&lt;/span&gt; &lt;span class="na"&gt;interval=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;60&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ehcache:config&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;One hard to find bug was introduced in the migration. Some values seemed to randomly suddenly get the default value, it came and went by flushing the cache. After alot of debbuging, we found that it was since one method that took an Integer as argument, made a difference between 0 and null in the inside the method. And it seems that in the hashcode based key generator, null and 0 get the same hashcode. Not a big supprice but still. And the real problem was that the code used null as a value, but it is something to watch out for.&lt;/p&gt;
&lt;p&gt;Since the annotations create a proxy of the class, they require an interface, and that the call to the method is from otuside the class. otherwise it wont pass through the proxy created by the annotation. You wont get notified by this in any other way then that the cache will stay empty.&lt;/p&gt;
&lt;p&gt;I had pretty much only used memcached before, so this came as a big surprise to me. By default, when you get from the cache, you get the actual instance of the object you put there. This of cource makes sense when you think about it, but i wasn&amp;#8217;t ready for it. The effect is that if you change a mutable item after you get it from the cache, you also change it in the cache. You cant treat the instance you get as a unique instance. There is a setting to enable copy on read and copy on write. I decided to take care of that myself, since most items are immutable anyway and those that aren&amp;#8217;t i know how to copy faster then just serializing them back and forth. The best solution is of cource to only have immutable objects.&lt;/p&gt;
&lt;p&gt;Most (if not all) of this is things you can find in the documentation of ehcache and ehcache-spring-annotations. But i guess im not the only one who has a hard time to find it al. Especially if you arent looking.&lt;/p&gt;
&lt;p&gt;Overall i must say, that now when i am getting used to ehcache. It feels pretty nice. I love the fact that you dont have to do the normal get from cache, check if null dance that im used to from just using memcached.&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/pt0SB2YtBJQ" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2012/02/07/ehcache-gotchas.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Getting started with Moustache and Enlive</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/a4moFbygyUs/getting-started-with-moustache-and-enlive.html" />
    <id>http://www.cleancode.se/:/2011/01/04/getting-started-with-moustache-and-enlive</id>
    <updated>2011-01-04T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>A simple guide creating a bookmarking site in clojure, using Mustache and Enlive.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;A while ago i wrote a tutorial for compojure. Since i have switched to using &lt;a href="https://github.com/cgrand/enlive"&gt;enlive&lt;/a&gt; and  &lt;a href="https://github.com/cgrand/moustache"&gt;moustache&lt;/a&gt; almost al the time. I think it is time for them to get a tutorial aswell.&lt;/p&gt;
&lt;p&gt;The goal for this tutorial will be to write a simple page for bookmarking.&lt;/p&gt;
&lt;h2&gt; Getting started &lt;/h2&gt;
&lt;p&gt;I will be using Leinigen, you can ofcource use Cake without changing much (if anything at al). &lt;br /&gt;
Start with&lt;br /&gt;
&lt;pre&gt;lein new FeedTutorial&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I have added all the dependencies that will be used, so we dont have to go back later:&lt;br /&gt;
My project.clj&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;defproject&lt;/span&gt; &lt;span class="nv"&gt;FeedTutorial&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;1.0.0-SNAPSHOT&amp;quot;&lt;/span&gt;
  &lt;span class="nv"&gt;:description&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;FIXME: write&amp;quot;&lt;/span&gt;
  &lt;span class="nv"&gt;:dependencies&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="nv"&gt;org&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;clojure/clojure&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;1.2.0&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;org&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;clojure/clojure-contrib&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;1.2.0&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;enlive&lt;/span&gt;  &lt;span class="s"&gt;&amp;quot;1.0.0-SNAPSHOT&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;net&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;cgrand/moustache&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;1.0.0-SNAPSHOT&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ring/ring-core&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;0.2.5&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ring/ring-devel&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;0.2.5&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ring/ring-jetty-adapter&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;0.2.5&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now, open up your core.clj. The first thing we need is the basic code for moustache. We will need jetty to run it, and we will need a simple route to display something:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;FeedTutorial&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;core&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;:use&lt;/span&gt; &lt;span class="nv"&gt;net&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;cgrand&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;moustache&lt;/span&gt;
         &lt;span class="nv"&gt;net&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;cgrand&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;enlive-html&lt;/span&gt;
         &lt;span class="nv"&gt;ring&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;util&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;response&lt;/span&gt;
         &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ring&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;adapter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;jetty&lt;/span&gt; &lt;span class="nv"&gt;:only&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;run-jetty&lt;/span&gt;&lt;span class="p"&gt;]]))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;my-app-handler&lt;/span&gt;
     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app&lt;/span&gt;     
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&amp;gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;My own page!&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;response&lt;/span&gt; &lt;span class="nv"&gt;constantly&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;run-jetty&lt;/span&gt; &lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="ss"&gt;&amp;#39;my-app-handler&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:port&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;
                                  &lt;span class="nv"&gt;:join?&lt;/span&gt; &lt;span class="nv"&gt;false&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;app is macro, it helps us to create routes in an easy syntax.&lt;br /&gt;
the [&amp;quot;&amp;quot;] mapps to the root, ie when jetty is running you can go to http://localhost:8080/ and se &amp;#8220;My own page!&amp;#8221;&lt;br /&gt;
if you change [&amp;quot;&amp;quot;] to for example [&amp;#8220;wow&amp;#8221;] it will instead map to http://localhost:8080/wow&lt;/p&gt;
&lt;p&gt;The &amp;#8220;response&amp;#8221; function takes a string and creates a response map. We can run it in the repl:&lt;br /&gt;
FeedTutorial.core&amp;gt; (&amp;#8594; &amp;#8220;Sometext&amp;#8221; response)&lt;br /&gt;
{:status 200, :headers {}, :body &amp;quot;Sometext&amp;quot;}&lt;/p&gt;
&lt;p&gt;In case you havent seen &amp;#8594; before. it is a macro that just makes the code easier to read.&lt;br /&gt;
(&amp;#8594; a b c d) is the same as (d (c (b (a))))&lt;/p&gt;
&lt;p&gt;So we could write:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="nv"&gt;FeedTutorial&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;core&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;response&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Sometext&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:status&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:headers&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:body&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Sometext&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The constantly function just takes anything and creates a function that takes any number of arguments and returns what you gave it.&lt;br /&gt;
For example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="nv"&gt;FeedTutorial&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;core&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nb"&gt;constantly &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="nv"&gt;FeedTutorial&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;core&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nb"&gt;constantly &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In other words:&lt;br /&gt;
(&amp;#8594; &amp;#8220;My own page!&amp;#8221; response constantly)) &lt;br /&gt;
creates a function that always returns a response with the body &amp;#8220;My own page!&amp;#8221;&lt;/p&gt;
&lt;h2&gt; Adding a template &lt;/h2&gt;
&lt;p&gt;As i said earlier, i will use enlive, wich is a templating engine. Lets see some code, we create our first template:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deftemplate&lt;/span&gt; &lt;span class="nv"&gt;index&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;FeedTutorial/index.html&amp;quot;&lt;/span&gt;
  &lt;span class="p"&gt;[])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now all this template does, is that it loads the FeedTutorial/index.html file. This ofcource means we have to create it. It should be located in: &lt;br /&gt;
FeedTutorial/src/FeedTutorial/index.html that is the same folder as your core.clj.&lt;br /&gt;
At this point it doesnt realy mather how it looks, i created the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My page!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
   I am using a template!
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Calling the function at the repl yields:&lt;br /&gt;
FeedTutorial.core&amp;gt; (index)&lt;br /&gt;
(&amp;#8220;&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;My page!&lt;/title&gt;\n  &lt;/head&gt;\n&lt;body&gt;\n   I am using a template!\n&lt;/body&gt;\n\n&lt;/html&gt;&amp;#8221;)&lt;/p&gt;
&lt;p&gt;Note: if you get a nullpointerexception, you probably put the index.html in the wrong folder.&lt;/p&gt;
&lt;p&gt;As you can see it is simply the html code in a list as a string.&lt;/p&gt;
&lt;p&gt;We also need to add a route for it. I moved our old route to &amp;#8220;hello&amp;#8221;, you can remove it if you like. My routes look like the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;my-app-handler&lt;/span&gt;
     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;response&lt;/span&gt; &lt;span class="nv"&gt;constantly&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&amp;gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;My own page!&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;response&lt;/span&gt; &lt;span class="nv"&gt;constantly&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see it is the same as before, except that i wrap &amp;#8220;index&amp;#8221; in paranthesis to call it. rendering the string.&lt;br /&gt;
Now if you browse http://localhost:8080/ you will see the html you wrote in index.html&lt;/p&gt;
&lt;h2&gt;Making changes to the template&lt;/h2&gt;
&lt;p&gt;Displaying a static .html file is not realy magic. To make changes, we first add something in the .html file that we want to change.&lt;br /&gt;
I added:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;   &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bookmarks&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     
   &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To add some text in that div, using enlive. We expand our template:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deftemplate&lt;/span&gt; &lt;span class="nv"&gt;index&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;FeedTutorial/index.html&amp;quot;&lt;/span&gt;
  &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:div&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;I changed the html&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you might have guessed. that row says:&lt;br /&gt;
&amp;#8220;Find the div with id &amp;#8216;bookmarks&amp;#8217; and set the content to &amp;#8216;I changed the html&amp;#8217;&amp;#8221;&lt;br /&gt;
If you happen to know jquery, it is equal to:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;div#bookmarks&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;jquery changed me&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If you now browse to http://localhost:8080 you should see the text &amp;#8220;I changed the html&amp;#8221; (in addition to any other text you had on the page before)&lt;/p&gt;
&lt;p&gt;Now, lets say we have a vector of strings:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Something happend!&amp;quot;&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;More news.&amp;quot;&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Very cool stuff&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And we want that to be a list on our page?&lt;br /&gt;
First: we add a list tag to our html.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;   &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
	&lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;This will be replaced&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then we update our template:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deftemplate&lt;/span&gt; &lt;span class="nv"&gt;index&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;FeedTutorial/index.html&amp;quot;&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:div&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;I changed the html&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:ul&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt; &lt;span class="nv"&gt;:li&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;clone-for&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;item&lt;/span&gt; &lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="nv"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And since we added an argument (items) to the template, we need to update our route:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;index &lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;response&lt;/span&gt; &lt;span class="nv"&gt;constantly&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, it now takes one argument &amp;#8220;items&amp;#8221; that is the sequence to be displayed as a list.&lt;br /&gt;
[:ul#items :li] selects the list tag in the unorderd list items. Then the clone-for function makes a copy of the list tag for each item in items. and sets its content to the content of item.&lt;/p&gt;
&lt;p&gt;in other words you should now see:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Something happend!&lt;/li&gt;
	&lt;li&gt;More news.&lt;/li&gt;
	&lt;li&gt;Very cool stuff&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Very pretty!&lt;br /&gt;
Now, maybe we want to display the link to the source of the bookmark aswell.&lt;/p&gt;
&lt;p&gt;We can update our bookmarks vector to contain the urls aswell:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Something happend!&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.someurl.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;More news.&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.newssite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Very cool stuff&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.verycoolsite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A list is not very suitable to display this. So lets change the html file to contain a table instead.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;   &lt;span class="nt"&gt;&amp;lt;table&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bookmark&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We ofcource also need to update the template:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deftemplate&lt;/span&gt; &lt;span class="nv"&gt;index&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;FeedTutorial/index.html&amp;quot;&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:div&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;I changed the html&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:table&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="nv"&gt;items&lt;/span&gt; &lt;span class="nv"&gt;:tr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bookmark&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;clone-for&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;item&lt;/span&gt; &lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                                &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:td&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;:title&lt;/span&gt; &lt;span class="nv"&gt;item&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                                &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:td&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;url&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;:url&lt;/span&gt; &lt;span class="nv"&gt;item&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I changed the ul to be the table. and point the first selector to the :tr. Since that has children, ie two :td elements. We can clone them and change their content. I find this an extremly elegant way to do this. We can move the table anywhere we like in the html, we can style it with css. We can do anything view related without havint to see any clojure code. &lt;br /&gt;
If you visit localhost:8080 and view the source. it should look something like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;   &lt;span class="nt"&gt;&amp;lt;table&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
    &lt;span class="nt"&gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bookmark&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Something happend!&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt; 
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;www.someurl.com&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt; 
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bookmark&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;More news.&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt; 
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;www.newssite.com&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt; 
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bookmark&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Very cool stuff&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt; 
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;www.verycoolsite.com&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt; 
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt; 
 
    &lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can now for example add a table header in our html file:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;   &lt;span class="nt"&gt;&amp;lt;table&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;header&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Title&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;URL&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bookmark&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To get the page to update you need to evaluate the enlive template again.&lt;/p&gt;
&lt;p&gt;My full project now can be found at:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/bobo/FeedTutorial/tree/27854d4d7abaafcdfdaa35a03b97cc3419f21ae9"&gt;Here at my GitHub account&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That is my files as they looked at this point.&lt;/p&gt;
&lt;p&gt;I removed the initial &amp;#8220;i am using a template&amp;#8221; text since it isnt used.&lt;/p&gt;
&lt;p&gt;We should use the bookmarks div for something more usefull. We can put a header there for example!&lt;/p&gt;
&lt;p&gt;Change the Template to:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;:div&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt; &lt;span class="nv"&gt;:*&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;content&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;My own bookmarkingpage!&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The :* is not a smiley, it selects anything. I choose to use it so we can change from h1 to h2 or something else. Without having to go into the clojure code.&lt;/p&gt;
&lt;p&gt;In the html file i put:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bookmarks&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;Adding new content&lt;/h2&gt;
&lt;p&gt;We have a very static page, since the only way to change the content now is to change the clojure code itself. We can change this by adding a /addBookmark route&lt;/p&gt;
&lt;p&gt;First we need a function to handle the request:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;add-bookmark&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;request&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;response&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str &lt;/span&gt;&lt;span class="nv"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;For now, it just returns a response displaying the http request as a string&lt;br /&gt;
And add a route for it and tell moustache that it should call add-bookmark2	.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;addBookmark&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nv"&gt;add-bookmark&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, we dont say anything about the request, or dont pass any parameter into add-bookmark, even though it requires one. Moustache takes care of this for us.&lt;/p&gt;
&lt;p&gt;If you browse to your localhost:8080/addBookmark you will now see your request map. mine looks like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;remote&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;addr&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;0:0:0:0:0:0:0:1&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;scheme&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;uri&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;/addBookmark&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;localhost&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;accept-charset&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;ISO-8859-1,utf-8;q=0.7,*;q=0.3&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="s2"&gt;&amp;quot;accept-language&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;en-US,en;q=0.8&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;accept-encoding&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;gzip,deflate,sdch&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="s2"&gt;&amp;quot;user-agent&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.15 (KHTML, like Gecko) Chrome/10.0.612.1 Safari/534.15&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="s2"&gt;&amp;quot;accept&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="s2"&gt;&amp;quot;connection&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;keep-alive&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;host&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;localhost:8080&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;encoding&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Input&lt;/span&gt; &lt;span class="nx"&gt;org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mortbay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;jetty&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;HttpParser$Input&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;faf67f0&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Since we are adding a new bookmark, we want to use request-method post. To be able to post you can use curl, find a plugin for your browser, or write a simple html form. I will use curl. &lt;br /&gt;
I want the parameters to be called &amp;#8220;title&amp;#8221; and &amp;#8220;url&amp;#8221; so my curl command would be:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
curl -d &amp;#8220;title=a title&amp;amp;url=www.myurl.com&amp;#8221; localhost:8080/addBookmark&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
The response i get now is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;remote&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;addr&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;0:0:0:0:0:0:0:1&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;scheme&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;uri&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;/addBookmark&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;localhost&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;content-type&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="s2"&gt;&amp;quot;content-length&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;27&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;accept&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;*/*&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;host&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;localhost:8080&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="s2"&gt;&amp;quot;user-agent&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;encoding&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Input&lt;/span&gt; &lt;span class="nx"&gt;org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mortbay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;jetty&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;HttpParser$Input&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="mi"&gt;769652&lt;/span&gt;&lt;span class="nx"&gt;dd&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It says nothing about my title or url! We need to tell moustache to wrap the parameters. we use the ring middleware &amp;#8220;wrap-params&amp;#8221; for this. My routes now look like:&lt;br /&gt;
(after removing the now unused &amp;#8220;hello&amp;#8221; route)&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;my-app-handler&lt;/span&gt;
     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app&lt;/span&gt;
      &lt;span class="nv"&gt;wrap-params&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;addBookmark&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="nv"&gt;add-bookmark&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;index &lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;response&lt;/span&gt; &lt;span class="nv"&gt;constantly&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;raw&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;response&lt;/span&gt; &lt;span class="nv"&gt;constantly&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You also need to use wrap params in the ns declaration:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;FeedTutorial&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;core&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;:use&lt;/span&gt; &lt;span class="nv"&gt;net&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;cgrand&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;moustache&lt;/span&gt;
         &lt;span class="nv"&gt;net&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;cgrand&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;enlive-html&lt;/span&gt;
         &lt;span class="nv"&gt;ring&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;util&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;response&lt;/span&gt;
         &lt;span class="nv"&gt;ring&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;middleware&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;params&lt;/span&gt;
         &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;ring&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;adapter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;jetty&lt;/span&gt; &lt;span class="nv"&gt;:only&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;run-jetty&lt;/span&gt;&lt;span class="p"&gt;]]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now if we try our curl again:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;span class="nx"&gt;curl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;title=a title&amp;amp;url=myurl.com&amp;quot;&lt;/span&gt; &lt;span class="nx"&gt;localhost&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;addBookmarks&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;remote&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;addr&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;0:0:0:0:0:0:0:1&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;scheme&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;url&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;myurl.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;title&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;a title&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;uri&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;/addBookmarks&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;localhost&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;url&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;myurl.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;title&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;a title&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;content-type&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="s2"&gt;&amp;quot;content-length&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;27&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;accept&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;*/*&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;host&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;localhost:8080&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="s2"&gt;&amp;quot;user-agent&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;encoding&lt;/span&gt; &lt;span class="nx"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Input&lt;/span&gt; &lt;span class="nx"&gt;org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mortbay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;jetty&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;HttpParser$Input&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="mi"&gt;44&lt;/span&gt;&lt;span class="nx"&gt;fc63be&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now it is there! nice and tidy in a map we can reach using the :params key. To clean up a little, we can use destructuring in the add-bookmark function and only fetch the params.h&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;add-bookmark&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;params&lt;/span&gt; &lt;span class="nv"&gt;:params&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;response&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str &lt;/span&gt;&lt;span class="nv"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We now get a much nicer response:&lt;/p&gt;
&lt;pre&gt;

 curl -d "title=a title&amp;amp;url=myurl.com" localhost:8080/addNews
{"url" "myurl.com", "title" "a title"}

&lt;/pre&gt;
&lt;p&gt;To be able to add bookmarks in a nice way. We can wrap it as an agent:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;agent &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Something happend!&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.someurl.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                       &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;More news.&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.newssite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                       &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Very cool stuff&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.verycoolsite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We then have to replace references to bookmarks with @bookmarks. The route for example will now be:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;-&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;index &lt;/span&gt;&lt;span class="nv"&gt;@bookmarks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;response&lt;/span&gt; &lt;span class="nv"&gt;constantly&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To add to a vector, we can use conj. And since our bookmarks are in an agent we have to use send to send a function and its arguments to the agent.&lt;/p&gt;
&lt;p&gt;An operation with conj without the agent could look like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;conj &lt;/span&gt;&lt;span class="nv"&gt;@bookmarks&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;test&amp;quot;&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.test.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Something happend!&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.someurl.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;More news.&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.newssite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Very cool stuff&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.verycoolsite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.test.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here i deref bookmarks to get the vector.&lt;/p&gt;
&lt;p&gt;if we deref bookmarks again, we will see it hasnt changed.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="nv"&gt;@bookmarks&lt;/span&gt;
&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Something happend!&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.someurl.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;More news.&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.newssite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Very cool stuff&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;www.verycoolsite.com&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Since we want the change to be persistent. We have to send conj yo our agent:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;add-bookmark&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;params&lt;/span&gt; &lt;span class="nv"&gt;:params&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;send &lt;/span&gt;&lt;span class="nv"&gt;bookmarks&lt;/span&gt; &lt;span class="nv"&gt;conj&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:title&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;params&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;:url&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;params&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)})&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;response&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str &lt;/span&gt;&lt;span class="nv"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, send is used by sending the function and its arguments to an agent. that function is then applied to the content of the agent.&lt;/p&gt;
&lt;p&gt;Using curl to add new bookmarks is not a good way in the long run. I took a look at instapaper, read it later and similar. And changed one of their bookmarklets to work with our own bookmarking tools!&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="javascript"&gt;&lt;span class="nx"&gt;javascript&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="nx"&gt;iprl5&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;scr&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;ipt&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;src&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;protocol&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;//localhost:8080/addBookmark?title=&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nb"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;amp;url=&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nb"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Please wait until the page has loaded.&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);}}&lt;/span&gt;&lt;span class="nx"&gt;iprl5&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can create a bookmark in your browser with this as url. Now you can click on it while on any page, and it will add it to your bookmarks page.&lt;br /&gt;
I am not a javascript genie, But it works. It sends a call to localhost:8080/addBookmark with title set to the title of the current page, and url to the url of the current page. Very nice!&lt;/p&gt;
&lt;p&gt;I think this will be enough for this time. There is still alot you can do, and maybe il write a part two. &lt;br /&gt;
Dont be afraid to leave feedback, good or bad. I cant improve unless i know what is wrong.&lt;/p&gt;
&lt;p&gt;The &amp;#8220;done&amp;#8221; version can be found here:&lt;br /&gt;
&lt;a href="https://github.com/bobo/FeedTutorial/tree/6c86440edf87e015382ea264b1fd1725cb5e2829"&gt;Here at my GitHub account&lt;/a&gt;&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/a4moFbygyUs" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2011/01/04/getting-started-with-moustache-and-enlive.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>What is Clojure good at?</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/MfrotNW7mNc/what-is-clojure-good-at.html" />
    <id>http://www.cleancode.se/:/2010/10/17/what-is-clojure-good-at</id>
    <updated>2010-10-17T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>Some thoughts on what clojure is good at, and why you should learn it.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;I was recently asked the question &amp;#8220;What is Clojure&amp;#8217;s sweetspot?&amp;#8221;. I ofcources started rambling about how nice it is for concurent applications, that you can make a map statement run in multiple threads by simply changing &amp;#8220;map&amp;#8221; to &amp;#8220;pmap&amp;#8221;. That you dont have to care about locks and so on. &lt;br /&gt;
But then i was asked about a real world problem or something that you would encounter in your real day job. I found this alot harder to answer, the only thing i could come up with on the spot was data intense applications like flight caster. But i couldnt realy let the question go. Lets start with what clojure is not.&lt;/p&gt;
&lt;h3&gt; Clojure is not a better java &lt;/h3&gt;
&lt;p&gt;I often hear &amp;#8220;scala is a better java&amp;#8221; and i agree with it. With scala, you can continue to write code like you do with java. It will just have less and more effective syntax. This is even the prefered aproach, and makes it easy to introduce scala to new developers. With clojure, this is not the case. You have to think in totaly new ways and it can be realy hard in the begining. But in the end, it is very rewarding. Clojure (and lisp in general) is one of thoose languages that if you learn it, and never get to use it in production. You will still have had great benefit from knowing clojure and the functional ways of thinking. It will affect your coding in java.&lt;/p&gt;
&lt;h3&gt; Clojure is great at java &lt;/h3&gt;
&lt;p&gt;Clojure realy is great at java, maybe even better than java itself. It might sound weird at first, but let me explain. &lt;br /&gt;
&lt;b&gt;First&lt;/b&gt; of all, the repl is a killer. This is not something that is unique to clojure, but that doesnt make it less good. Beeing able to try out new api&amp;#8217;s and fumble forward is great.&lt;br /&gt;
&lt;b&gt;Second&lt;/b&gt;, there is no compile time. It is not that the compile time is short, it doesnt exist. Making a change to a webpage will be visible on next reload. All you do is re-evaluate the function you changed. &lt;br /&gt;
&lt;b&gt;Third&lt;/b&gt;, functions without state and side effects are alot easier to test then java code. Yes you can still create hard to test code, but it is harder.&lt;br /&gt;
&lt;b&gt;Fourth&lt;/b&gt;, you can abstract away more code. Take memcached for example. When using memcached, you have to &lt;br /&gt;
&lt;pre&gt; collect the value from the cache,&lt;br /&gt;
check if it is null, &lt;br /&gt;
if so calculate it. &lt;br /&gt;
store it in memcached &lt;br /&gt;
return it. &lt;/pre&gt;&lt;br /&gt;
You cant get rid of thoose 4 lines of extra code in every method (you probably can with annotations but i havent seen it?). In clojure you write a function call it for example &lt;br /&gt;
&lt;pre&gt; with-memcached &lt;/pre&gt;&lt;br /&gt;
You can then simply &lt;br /&gt;
&lt;pre&gt; (with-memcached &lt;br /&gt;
	(some-heavy-code) &amp;#8220;memcachedkey&amp;#8221;) &lt;/pre&gt;&lt;br /&gt;
and it will check the cache and so on for you. Same goes for performance timing. how many times have you written &lt;br /&gt;
&lt;pre&gt;long start = System.currentTimemillis(); // (or nanos..) &lt;br /&gt;
{some code } &lt;br /&gt;
System.out.println(&amp;quot;time: &amp;quot;+ (System.currentTimeillis()-start);&lt;br /&gt;
&lt;/pre&gt; in clojure you can just do &lt;br /&gt;
&lt;pre&gt;(time (my-function))&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I could go on, but im not going to, my point is not to say that Clojure is the best language ever made, or that everybody should learn Clojure. My point is, that if you want to learn and use clojure, it is not only suited for concurent code with big amounts of data. It is suited for most things. It might not be the best language for everything, but then again, no language is.&lt;/p&gt;
&lt;p&gt;A small disclaimer, note that i am not saying that Clojure is better then Scala or Groovy or anything else. I am just saying that Clojure is great. You can do alot/everything i mention in for ex Scala, that is besides the point.&lt;br /&gt;
I would love too see someone else write something similar about scala/jruby/groovy/whatnot, It might even already be some posts about it? I would love if someone could help me with more arguments for clojure in everyday life, there is probably a blogpost somewhere out there about that aswell?&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/MfrotNW7mNc" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2010/10/17/what-is-clojure-good-at.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Writing pretty Database code in java.</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/cuJfkLjEizU/code-abstractions.html" />
    <id>http://www.cleancode.se/:/2010/10/14/code-abstractions</id>
    <updated>2010-10-14T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>Some thoughts on how to make your database code cleaner.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;I write alot of database code in java. As an effect, i have a code macro in netbeans. So when i write:&lt;/p&gt;
&lt;p&gt;sql[tab]&lt;br /&gt;
it expands to:&lt;/p&gt;
&lt;script src="http://gist.github.com/624663.js"&gt; &lt;/script&gt;&lt;p&gt;Yes that is alot of code. And it doesnt even collect the result, or contain the sql needed.&lt;br /&gt;
I got very tired at looking at al this code. I thought alot, tried to extract some usefull method or anything to show the intent of the code more.&lt;/p&gt;
&lt;p&gt;Fortunatly, in java 7 this will be improved. Thanks to the new resource management.&lt;br /&gt;
It will then look something like:&lt;br /&gt;
&lt;script src="http://gist.github.com/624693.js"&gt; &lt;/script&gt;&lt;/p&gt;
&lt;p&gt;This is a great improvement, but i think we can do better. Also, we wont see java 7 anytime soon. And even when we do, its not sure our legacy projects can use it.&lt;/p&gt;
&lt;p&gt;Enter project lombok: &lt;a href="http://projectlombok.org/"&gt;http://projectlombok.org/&lt;/a&gt;&lt;br /&gt;
Lombok does some nice magic with annotations. We can now get the following:&lt;/p&gt;
&lt;script src="http://gist.github.com/624704.js"&gt; &lt;/script&gt;&lt;p&gt;No try catch at all, we pretty much dont have to add any code that we dont want. Creating a connection, preparing a statement, executing an sql, collecting each row into something. Return the Collection of objects. Simple!&lt;/p&gt;
&lt;p&gt;But i have been working in &lt;span class="caps"&gt;PHP&lt;/span&gt; alot lately, and this hurts to say. In php, you can abstract away even more.&lt;br /&gt;
You dont even have to create one method for each sql query. you can create a general query. So you can do something like this:&lt;/p&gt;
&lt;script src="http://gist.github.com/624738.js"&gt; &lt;/script&gt;&lt;p&gt;The only way to come close to this in java. Is to just use Object everywhere and cast everything as you need. But then you arent coding in java anymore. Instead, alot of java projects now use something like Hibernate. I am not the biggest fan of it. But it seems to do the trick most of the time.&lt;/p&gt;
&lt;p&gt;But, lets say we broaden our minds. Java is so much more then just the language, it is a platform. We can change java the language to something that suits our needs more. Enter groovy!&lt;br /&gt;
I havent used groovy alot, but i should have. This is why:&lt;/p&gt;
&lt;script src="http://gist.github.com/626735.js"&gt; &lt;/script&gt;&lt;p&gt;&lt;a href="http://docs.codehaus.org/display/GROOVY/Tutorial+6+-+Groovy+SQL"&gt; &lt;i&gt;Example Taken from this Tutorial &lt;/i&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;sql is just an object created with the connection details. This can be reused for all our queries.&lt;br /&gt;
Id and firstname are ofcource columns in the table you select from. And you can instead of printing add objects to a collection or do something else that is usefull. And all in one (1!) row. Groovy also has some other nice features for jdbc. If you do alot of jdbc, you should really take a look!&lt;/p&gt;
&lt;p&gt;If you want to go abit further from java. But still stay on the jvm, try clojure! Then your code can look like:&lt;/p&gt;
&lt;script src="http://gist.github.com/626745.js"&gt; &lt;/script&gt;&lt;p&gt;&lt;a href="http://en.wikibooks.org/wiki/Clojure_Programming/Examples/JDBC_Examples"&gt;&lt;i&gt; Example taken from this page &lt;/i&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I love clojure, but between the groovy and the clojure examples of jdbc, i prefer groovy.&lt;/p&gt;
&lt;p&gt;I bet you can create Java &lt;span class="caps"&gt;POJO&lt;/span&gt; from sql with jdbc using groovy or clojure, in less code then with Hibernate. And you dont have to clutter your model objects with annotations, you dont have to let Hibernate do bad sql queries, and you get to learn a new language. &lt;b&gt;Go try it!&lt;/b&gt;&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/cuJfkLjEizU" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2010/10/14/code-abstractions.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Getting started with compojure, part 2</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/uJlmgWCmRzk/getting-started-with-compojure2.html" />
    <id>http://www.cleancode.se/:/2010/09/03/getting-started-with-compojure2</id>
    <updated>2010-09-03T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>A basic guide to creating a simple todo webapp with compojure and clojure</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;This is part two of my getting started with clojure web dev tutorial. In the &lt;a href="http://cleancode.se/2010/08/30/getting-started-with-compojure.html"&gt;first  part&lt;/a&gt; we built a small tasklist, it is not very functional yet. But we made it ourselves!&lt;/p&gt;
&lt;p&gt;In this part, we will add javascript and ajax!&lt;br /&gt;
To do this, we need to be able to serve static files. This is pretty simple. &lt;br /&gt;
Start by creating a folder &amp;#8220;files&amp;#8221; in your project folder (ie the same folder as your project.clj)&lt;br /&gt;
In the files folder, create a javascript.js and enter som text in it.&lt;/p&gt;
&lt;p&gt;Now, back to core.clj. &lt;br /&gt;
We have to tell compojure/ring that it should serve files. we do this, wrapping our call to myroutes in the jetty function, to make it easier to read, we also move it to a new function:&lt;/p&gt;
&lt;script src="http://gist.github.com/562596.js"&gt;&lt;/script&gt;&lt;p&gt;we will also have to add: ring.middleware.file-info and ring.middleware.file to the (:use ) part of the ns declaration.&lt;/p&gt;
&lt;p&gt;Now if you go to http://localhost:8080/javascript.js you should see the contents of your file.&lt;/p&gt;
&lt;p&gt;Time for some ajax magic, to make our life simple, we will use jquery, and a jquery plugin called jquery.form.&lt;br /&gt;
you can find jquery.form here: &lt;a href="http://github.com/malsup/form/raw/master/jquery.form.js?v2.43"&gt;http://github.com/malsup/form/raw/master/jquery.form.js?v2.43&lt;/a&gt;&lt;br /&gt;
and jquery from jquery.org or from google: &lt;a href="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&lt;/a&gt;&lt;br /&gt;
download them and put them in your files folder.&lt;/p&gt;
&lt;p&gt;Try loading them in your browser: http://localhost:8080/jquery.min.js it should just works.&lt;/p&gt;
&lt;p&gt;To include them in our clojure code, we can use some helper functions in hiccup.&lt;/p&gt;
&lt;script src="http://gist.github.com/562659.js"&gt;&lt;/script&gt;&lt;p&gt;Load the form in your webpage again and you should see: &amp;lt;script src=&amp;#8220;/jquery.js&amp;#8221; type=&amp;#8220;text/javascript&amp;#8221;&amp;gt;&amp;lt;/script&amp;gt; and so on in your source.&lt;/p&gt;
&lt;p&gt;Now we can do some javascript coding!&lt;br /&gt;
Open your javascript.js and enter the following:&lt;/p&gt;
&lt;script src="http://gist.github.com/562665.js"&gt;&lt;/script&gt;&lt;p&gt;#formresult, is the css id of the tag where the result of the formpost should be placed. we want that in a div just under the form. A div is created like this:&lt;br /&gt;
   [:div {:id &amp;quot;formresult&amp;quot;} &amp;#8220;form result will be here&amp;#8221;]&lt;/p&gt;
&lt;p&gt;#myform, is the css id of the form we want to turn into an ajaxform. We add this to our form: &lt;br /&gt;
 (form-to {:id &amp;quot;myform&amp;quot;} [:post &amp;#8220;/form&amp;#8221; ]&lt;/p&gt;
&lt;p&gt;so the entire function should look like this:&lt;/p&gt;
&lt;script src="http://gist.github.com/562674.js"&gt;&lt;/script&gt;
&lt;p&gt;Now, evaluate the function and try your form. When you hit enter, it will not reload the page. &amp;#8220;form result here&amp;#8221; will just be replaced with task3 [&amp;#8220;task1&amp;#8221; &amp;#8220;task2&amp;#8221;], if you have entered task1,task2 and task3 in your form. Although that is pretty cool. We want it to look as pretty as our /view does. Simple!&lt;/p&gt;
&lt;script src="http://gist.github.com/562710.js"&gt;&lt;/script&gt;&lt;p&gt;What we do is simply to move the part that creates a vector of all our tasks to the let assignment. Then we have it handy and can once again use the (unordered-list) function to make our tasklist pretty. Note the (html that is also added.&lt;/p&gt;
&lt;p&gt;Incase you got something wrong, here is my full core.clj&lt;/p&gt;
&lt;p&gt;&lt;a href="http://gist.github.com/562716"&gt;core.clj&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now, this is not realy a tasklist, we cant remove tasks we are done with. This will be the next step:&lt;/p&gt;
&lt;p&gt;We start by creating a new route:&lt;/p&gt;
(&lt;span class="caps"&gt;GET&lt;/span&gt; &amp;#8220;/delete/:task&amp;#8221; {session :session, params :params} (delete-task (params &amp;#8220;task&amp;#8221;) session))
&lt;p&gt;Note, if we didnt need the session, we could have used the short version:&lt;br /&gt;
	(&lt;span class="caps"&gt;GET&lt;/span&gt; &amp;#8220;/delete/:task&amp;#8221; [task] (delete-task task session)&lt;/p&gt;
&lt;p&gt;The :task turns whatever you write there, into a parameter. So if you go to http://localhost:8080/delete/mytask it will call delete-task with the value mytask.&lt;/p&gt;
&lt;p&gt;We define our delete-task&lt;br /&gt;
(defn delete-task [task] )&lt;br /&gt;
Now for the question, how do ve remove from the vector? Vectors only support removal by index. The easiest way to solve this is to change our vector to a set. Simply change vector? to set? and (vector to (hash-set. Everything still works!&lt;/p&gt;
&lt;p&gt;Now we can write our function:&lt;/p&gt;
&lt;script src="http://gist.github.com/562811.js"&gt;&lt;/script&gt;&lt;p&gt;now, create some tasks. Then enter http://localhost:8080/delete/sometask and sometask is deleted! you can verify by using the /view we did in part one.&lt;/p&gt;
&lt;p&gt;But lets be honest, this is not a usefull way to handle this, We want to be able to click on a item to remove it.&lt;/p&gt;
&lt;p&gt;We solve this with some more jquery:&lt;/p&gt;
&lt;script src="http://gist.github.com/562841.js"&gt;&lt;/script&gt;&lt;p&gt;What we do here, is we create a function called done, this adds a clickListener to all list items. The clickListener calls /delete/list-item-text and on success, hides the item.&lt;/p&gt;
&lt;p&gt;This will be enough for the second part. &lt;br /&gt;
&lt;a href="http://gist.github.com/563831"&gt;My full core.clj&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;update: a running version can be viewed here: &lt;a href="http://cljtasks.appspot.com/"&gt;http://cljtasks.appspot.com/&lt;/a&gt;&lt;br /&gt;
Thanks to the excelent guides at: http://compojureongae.posterous.com/ for helping me get it up on app engine!&lt;/p&gt;
&lt;p&gt;In the next part, we will try to store our tasklist in a NoSQL database.&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/uJlmgWCmRzk" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2010/09/03/getting-started-with-compojure2.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Getting started with compojure</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/J0S4Rsy0Ru4/getting-started-with-compojure.html" />
    <id>http://www.cleancode.se/:/2010/08/30/getting-started-with-compojure</id>
    <updated>2010-08-30T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>A basic guide to creating a simple todo webapp with compojure and clojure</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;The goal of this tutorial is a simple tasklist written with clojure and compojure&lt;br /&gt;
I will be using Lein, so if you dont have that. Head over to: http://github.com/technomancy/leiningen and follow the instructions.&lt;br /&gt;
With that installed, lets start with:&lt;/p&gt;
&lt;p&gt;lein new SimpleTasks&lt;/p&gt;
&lt;p&gt;This will create a new project for us.&lt;br /&gt;
Lets begin by adding some dependencies that we will need. Open SimpleTasks/project.clj and add the following dependencies:&lt;/p&gt;
&lt;script src="http://gist.github.com/558643.js?file=gistfile1.clj"&gt;&lt;/script&gt;&lt;p&gt;Save the file and invoke &amp;#8220;lein deps&amp;#8221;. This will download all the dependencies we need.&lt;br /&gt;
If you dont want to use lein, enclojure in netbeans for example works great. All you need to do then is to go to clojars.org and find the dependencies listed above and add them to your project.&lt;br /&gt;
The &lt;br /&gt;
 :dev-dependencies [[swank-clojure &amp;#8220;1.2.1&amp;#8221;]] &lt;br /&gt;
is to be able to start a swank server and connect emacs to it. If you wont be using that, you can leave it out.&lt;/p&gt;
&lt;p&gt;Now we can start coding!&lt;/p&gt;
&lt;p&gt;Open up src/SimpleTasks/core.clj in your favorite editor. I use emacs with clojure mode and slime. But anything works.&lt;/p&gt;
&lt;p&gt;you will see:&lt;/p&gt;
&lt;p&gt;(ns SimpleTasks.core)&lt;/p&gt;
&lt;p&gt;Now, lets start by getting a webpage running!&lt;/p&gt;
&lt;script src="http://gist.github.com/555465.js?file=core.clj"&gt;&lt;/script&gt;&lt;p&gt;This is the basic setup of a simple compojure  webbapp.&lt;br /&gt;
If you run this and point your browser to localhost:8080 you will see &amp;#8220;Hello!&amp;#8221;&lt;br /&gt;
If you dont know how to run it. the simplest way is to use&lt;/p&gt;
&lt;p&gt;&amp;#8220;lein repl&amp;#8221; wait for the repl to load, and then:&lt;br /&gt;
clojure.core=&amp;gt; (require &amp;#8217;SimpleTasks.core)&lt;/p&gt;
&lt;p&gt;Now what does al this code do?&lt;/p&gt;
&lt;p&gt;(defonce server (run-jetty #&amp;#8217;myroutes&lt;br /&gt;
                           {:join? false&lt;br /&gt;
                            :port 8080}))&lt;/p&gt;
&lt;p&gt;Starts an instance of jetty at port 8080&lt;br /&gt;
join? false, makes the repl return instantly instead of blocking aslong as jetty is running.&lt;br /&gt;
#&amp;#8217;myroutes tells compojure what function it should called when the server recieves a request.&lt;/p&gt;
&lt;p&gt;(defroutes myroutes&lt;br /&gt;
  (&lt;span class="caps"&gt;GET&lt;/span&gt; &amp;#8220;/&amp;#8221; [] (display)))&lt;/p&gt;
&lt;p&gt;Here we define our routes, as you can see this is the method called by jetty.&lt;br /&gt;
It simply forwards any call to &amp;#8220;/&amp;#8221; ie &amp;#8220;localhost:8080/&amp;#8221; to the function display&lt;/p&gt;
&lt;p&gt;(defn display []&lt;br /&gt;
  (html [:h1 &amp;#8220;hello!&amp;#8221;]))&lt;/p&gt;
&lt;p&gt;Finally we end up in display. Al it does is render html page with &amp;#8220;hello!&amp;#8221; in a &amp;lt;h1&amp;gt; tag&lt;/p&gt;
&lt;p&gt;Now for a great thing about clojure and compojure.&lt;br /&gt;
edit the display funktion so it renders something else. ex:&lt;br /&gt;
(defn display []&lt;br /&gt;
  (html [:h1 &amp;#8220;hello world!&amp;#8221;]))&lt;/p&gt;
&lt;p&gt;To make compojure display this instead, al you need to do is to evalute that function, and reload your browser.&lt;/p&gt;
&lt;p&gt;Ok, lets start with the tasklist. The first thing we want is a form to add tasks:&lt;/p&gt;
&lt;p&gt;We start by adding another function to the routes:&lt;/p&gt;
&lt;script src="http://gist.github.com/558645.js?file=gistfile1.clj"&gt;&lt;/script&gt;&lt;p&gt;And this is the render-form function:&lt;br /&gt;
&lt;script src="https://gist.github.com/757598.js"&gt; &lt;/script&gt;&lt;/p&gt;
&lt;p&gt;Note: you also have to add: hiccup.form-helpers to the :use list in the ns declaration&lt;/p&gt;
&lt;p&gt;Now, evalute the defroutes and the render-form functions and point your browser to http://localhost:8080/form&lt;br /&gt;
&lt;i&gt;Hint: if you are using the repl you can use: (require &amp;#8217;SimpleTasks.core :reload) to evaluate it again.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;your core.clj should now look like: &lt;a href="http://gist.github.com/555496"&gt;http://gist.github.com/555496&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Try to type something in the box and submit the form. You will get a &amp;#8220;Not found&amp;#8221; error in your browser. &lt;br /&gt;
This is because al our routes ar &amp;#8220;&lt;span class="caps"&gt;GET&lt;/span&gt;&amp;#8221; and the form use &amp;#8220;&lt;span class="caps"&gt;POST&lt;/span&gt;&amp;#8221;&lt;/p&gt;
&lt;p&gt;So we need to add another route:&lt;/p&gt;
(&lt;span class="caps"&gt;POST&lt;/span&gt; &amp;#8220;/form&amp;#8221; {params :params} (handle-form (params &amp;#8220;task&amp;#8221;)))
&lt;p&gt;&lt;i&gt;Note: if you want a route to take all forms of requests, you can use (&lt;span class="caps"&gt;ANY&lt;/span&gt; &amp;#8220;/&amp;#8221; (myfunction))&lt;/i&gt;&lt;br /&gt;
The {params :params} gives us a map of the parameters from the form. Since we only care about the &amp;#8220;task&amp;#8221; parameter. we pick that and send it to handle-form.&lt;/p&gt;
&lt;p&gt;Lets check so the form works and just print the task:&lt;/p&gt;
&lt;p&gt;(defn handle-form [task]&lt;br /&gt;
  (html [:h2 task]))&lt;/p&gt;
&lt;p&gt;Load http://localhost:8080/form and enter something and submit. you should see the task you just entered.&lt;/p&gt;
&lt;p&gt;In a normal tasklist, you would probably store the tasks in a database or in textfiles. To make it simple, and to learn more of compojure/ring/hiccup. we will use the session.&lt;/p&gt;
&lt;p&gt;We begin by taking care of the result from the post:&lt;/p&gt;
&lt;p&gt;(defn handle-form [task]&lt;br /&gt;
  {:body (str &amp;#8220;stored&amp;#8221; task)&lt;br /&gt;
   :session {:tasks task}})&lt;/p&gt;
&lt;p&gt;Instead of using the (html) function from earlier, we specify the body and session. After this, the task will be stored under the key :tasks in the users session.&lt;/p&gt;
&lt;p&gt;To make ring/compojure understand and store data in the session, we also need:&lt;/p&gt;
&lt;p&gt;(wrap! myroutes :session)&lt;/p&gt;
&lt;p&gt;We also want a way to see what is in the session, this is pretty easy. we start by adding a new route:&lt;/p&gt;
(&lt;span class="caps"&gt;GET&lt;/span&gt; &amp;#8220;/view&amp;#8221; {session :session} (view session))
&lt;p&gt;A simple &lt;span class="caps"&gt;GET&lt;/span&gt; route that in the same way we saw with the parameters from the form, take the session and forward it to a function.&lt;/p&gt;
&lt;p&gt;The function that is called:&lt;/p&gt;
&lt;p&gt;(defn view [session]&lt;br /&gt;
  (html [:h1 (str &amp;quot;tasks: &amp;quot; (:tasks session))]))&lt;/p&gt;
&lt;p&gt;My full core.clj at this point:&lt;br /&gt;
&lt;a href="http://gist.github.com/557879"&gt;http://gist.github.com/557879&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Just beeing able to store one task is not going to work very long. Time to expand our tasks and store it in a vector.&lt;br /&gt;
This means that we want to append more tasks to the session, not only replace the information for every task we store.&lt;br /&gt;
We will use a simple vector as our storage format. To be able to do this, we need not only the parameters from the form, but also the current session. We change our &lt;span class="caps"&gt;POST&lt;/span&gt; route:&lt;/p&gt;
(&lt;span class="caps"&gt;POST&lt;/span&gt; &amp;#8220;/form&amp;#8221; {session :session, params :params} (handle-form (params &amp;#8220;task&amp;#8221;) session)))
&lt;p&gt;we now have the session and the task parameter from the form.&lt;br /&gt;
we change the form handler:&lt;/p&gt;
&lt;script src="http://gist.github.com/557897.js?file=core.clj"&gt;&lt;/script&gt;&lt;p&gt;What this does, except for print the task from the form, and the tasks from the session. Is that it checks if the value of the session is a vector.&lt;br /&gt;
If it is. the task is added to the current vector of tasks. If it is not a vector, it is most likely empty, and we create a new vector with our task.&lt;/p&gt;
&lt;p&gt;We dont need to change anything to our view route. &lt;br /&gt;
Try it out! We can now add multiple tasks to our simple tasklist!&lt;/p&gt;
&lt;p&gt;Time to make that view look like a real tasklist.&lt;br /&gt;
We will do this the easy way, add hiccup.page-helpers to the ever groving list of namespaces in :use.&lt;br /&gt;
then simply wrap our task vector in (unordered-list)&lt;/p&gt;
&lt;script src="http://gist.github.com/558587.js?file=gistfile1.clj"&gt;&lt;/script&gt;&lt;p&gt;We now have a list of tasks. This is how mine looks after adding three tasks:&lt;/p&gt;
&lt;h1&gt;Tasks&lt;/h1&gt;
&lt;ul&gt;
	&lt;li&gt;task1&lt;/li&gt;
	&lt;li&gt;task2&lt;/li&gt;
	&lt;li&gt;task3&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is enough for the first part.&lt;br /&gt;
We still have some work todo. We cant set tasks as completed or delete tasks. Later, we will also use jquery to make it smother too use.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;update: &lt;/b&gt; A question came up on the clojure mailing list &lt;a href="http://groups.google.com/group/clojure/browse_thread/thread/16c4904b60be53ea/ae04e0e29b118057#ae04e0e29b118057"&gt;&lt;span class="caps"&gt;HERE&lt;/span&gt;&lt;/a&gt; about how to reload a namespace if you are not using emacs. Thanks to mark Rathwell who posted the answer: &lt;br /&gt;
(require &amp;#8217;[foo.something :as something] :reload) &lt;br /&gt;
(require &amp;#8217;[foo.something :as something] :reload-all)&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/J0S4Rsy0Ru4" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2010/08/30/getting-started-with-compojure.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Code reviews</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/tj8B5gmgXZ4/code-reviews.html" />
    <id>http://www.cleancode.se/:/2010/06/15/code-reviews</id>
    <updated>2010-06-15T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>Some thoughts about code reviews.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;Code reviews are great. They are also often misunderstood.&lt;br /&gt;
If someone asks you to check his code, this does not mean that he wants you to make it your mission to find any mistake he made, so you can point and laugh at him. He simply wants you to help him improve the code. &lt;br /&gt;
But why should you help him with &lt;span class="caps"&gt;HIS&lt;/span&gt; &lt;span class="caps"&gt;CODE&lt;/span&gt;! it’s his work, cant he do his work on his own? If you have to check al the code he writes, you can just as well write it yourself and take his paycheck, right? No, ofcource not. &lt;br /&gt;
First, its not his code, its your code, its your teammates code, and all your future teammates code. &lt;span class="caps"&gt;YOU&lt;/span&gt; are responsible for every single line in that code base, yes everything. I do ofcource not mean you as a person, I mean you as a team. And by that i do not mean that the sum of the code responsibilities of all team-members is the entire codebase, i mean that the team as an entity is responsible for everything. &lt;br /&gt;
Second, the point of a code review is to improve, not only to improve your teammate, but also to improve you, and the teamwork of you and the one who wrote the code. You are not better than your teammate because he asks you to review his code, honestly, if he asks for reviews repeatedly and you dont. He is the better developer. Good developers know that they can improve, and that they can learn from everyone around them.&lt;/p&gt;
&lt;p&gt;What should you look for in a review? You should make sure you understand what everything does without having to think too much, that the flow is simple to follow and that you dont spot anything obviously wrong. And finally ofcource check so its properly tested and that the tests are clean. &lt;br /&gt;
When you find something you dont like or dont understand, discuss it, ask how the writer thought when he wrote it, and why he wrote it that way. It does not have to be something big; it can be a method name that can be misunderstood or a variable that could have a shorter scope.&lt;br /&gt;
Also, when you find something that you really like, tell him. Its always good with positive feedback.&lt;/p&gt;
&lt;p&gt;When should you do a code review? Well, when you feel you need it, if you are done with something. Ask someone or just everyone in general if anyone has time to check your code. Then take a conference room or just roll over with your chair and sit next to each other. I would even say its preferable to just sit at your workspace, that way, the entire team can hear you in the background and if they hear something that interests them, they can join the discussion.&lt;/p&gt;
&lt;p&gt;The best code review, is ofcource the continuous review that goes on al the time, also known as Pair programming. Try it!&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/tj8B5gmgXZ4" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2010/06/15/code-reviews.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Your tools should help you!</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/oaQFPRqlJNg/Your-tools-should-help-you.html" />
    <id>http://www.cleancode.se/:/2010/06/14/Your-tools-should-help-you</id>
    <updated>2010-06-14T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>Tools should help you, and make your life easier, not the opposite.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;The tools and libraries you use should help you, they can help your hardware and so on. but in the end, they should make your life easier.&lt;/p&gt;
&lt;p&gt;Take memcached for example, who does memcached help? Does it help your database server? yes, and thats a good thing! Does it help you? no, not realy, it forces you to make sure you invalidate keys, collect values from multiple sources and clutters your code and so on. Im not saying you shouldnt use memcached, im saying maybe you should use something in between, maybe you should find another library that helps you with using memcached. If you cant find such a library, maybe there is something else that can solve your problem, instead of solving the symptom of the problem.&lt;/p&gt;
&lt;p&gt;Let me explain what i mean, il continue to use memcached as the example. Why is it you use memcached? because your database cant keep up. The symptom of this is that your webpage gets slow. You &amp;#8220;solve&amp;#8221; this by giving the database less to do. But what your realy doing is solving the symptom, ie adding memcache and asking your database less, speeds upp the webpage again. But your problem is realy still there: you cant get the data up from the database fast enough. You are just giving your users old data. yes, this data can be unchanged. but its still old. &lt;br /&gt;
A solution to the problem, would be to store the data somewhere else, perhaps some nosql storage if that works. Or perhaps you dont even need to store it in a database, if your in java maybe something like terracotta can solve it. I dont realy care, but solve the problem, not the symptom. And more important, the solution should help you, not make you work harder.&lt;/p&gt;
&lt;p&gt;This is not meant as a bash against sql databases or memcached, they can be good tools. But they are often missused. My point is, your tools should not force you to work harder, or make your code more error prone. They should help you, and make your life easier, not only your hardwares life. Its not about what tools you use, its how you use them.&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/oaQFPRqlJNg" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2010/06/14/Your-tools-should-help-you.html</feedburner:origLink></entry>
  
    
  <entry>
    <title>Writing code is hard work!</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Cleancode/~3/YoaSuJ7HvkE/writing-code-is-hard-work.html" />
    <id>http://www.cleancode.se/:/2010/06/11/writing-code-is-hard-work</id>
    <updated>2010-06-11T00:00:00Z</updated>

    <author>
      <name>Mikael Sundberg</name>
      <uri>http://cleancode.se</uri>
      <email>micke@cleancode.se</email>
    </author>

    <summary>Some thoughts about whats important in software development.</summary>
    <content type="html" xml:lang="en" xml:base="http://cleancode.se/">
      &lt;p&gt;This post started out as a comment to: http://wolfie.github.com/2010/06/09/method-hierarchies.html&lt;br /&gt;
But when i had posted the comment i felt that i had more to say, so here we go:&lt;/p&gt;
&lt;p&gt;You do not get clean, readable, maintainable code by just writing short methods, or by just writing some junit tests, or by just refactoring some code now and then. You get clean code by hard work, practise, and discussions.&lt;/p&gt;
&lt;p&gt;If you encounter a bug in legacy code, and realise it is in a 1500 line class, you dont just find the problem and fix it. You treat the problem.&lt;br /&gt;
You do this by writing unit tests until you have isolated the problem (yes it is possible to write tests for the code, if you dont think so. go buy michael feathers book: http://amzn.to/9q7cNn).&lt;br /&gt;
When you have isolated the problem with a failing test, you make the test pass. If you have to change code that is not under test, you write tests for it first. Then you fix the problem, in as small increments as possible, with a run of tests for each increment.&lt;br /&gt;
When you have fixed the problem. You have most likely improved the design and readability of the class, if you havent. Do one small change to improve it.&lt;/p&gt;
&lt;p&gt;Why should you write small methods? why not just keep theese 4 lines in the other method? its the only place it is used anyway!&lt;br /&gt;
For several reasons:&lt;br /&gt;
It raises the abstractionlevel to extract methods.&lt;br /&gt;
It is easier to click on a methodcall to find what it does, then to ignore 4 lines in a method.&lt;br /&gt;
It is easier to verify that 4 lines does what they are expected to do, if they are in a method with a good name. Then just 4 lines among 100 in a big method.&lt;br /&gt;
It is easier to write a junit test for a 4 line method, then for 4 lines in a 100 line method.&lt;/p&gt;
&lt;p&gt;The problem with your codebase is not that someone wrote crap 4 years ago. It is that you didnt improve it everytime you touched it.&lt;br /&gt;
It is not someone elses code that is hard to read, everyone should own the code, it is your code that is hard to read!&lt;/p&gt;
&lt;p&gt;I love code reviews, not the code reviews that involve one &amp;#8220;chief architect&amp;#8221; saying &amp;#8220;thats not god enough, fix it&amp;#8221;. But the code reviews that involve 2-3 people disucssing someones code, why does that method have that name? could we improve a junit test here? could we extract another method? does this class do to many things? and so on. Dont review every single row of code, but thoose lines you review, do it well, discuss it, learn from it, improve from it. The goal of a code review is not perfect code. It is that one year from now, you have improved from it.&lt;/p&gt;
&lt;p&gt;I realise now that i havent mentioned &lt;span class="caps"&gt;TDD&lt;/span&gt; or pair-programing. But you already do that anyway, right?&lt;/p&gt;
&lt;p&gt;dont forget, software craftmanship is not about speed, it is about quality.&lt;/p&gt;
    &lt;img src="http://feeds.feedburner.com/~r/Cleancode/~4/YoaSuJ7HvkE" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://cleancode.se/2010/06/11/writing-code-is-hard-work.html</feedburner:origLink></entry>
  
</feed>

