Monthly Archives: October 2012

JDD 2012

Last week I attended the JDD 2012 conference. Here’s a bunch of very quick notes from the talks.

  • Rebecca Wirfs Brock, Joseph Yoder “Pragmatic, Not Dogmatic TDD: Rethinking How We Test” – nice presentation about TDD, felt a bit like theater (dialogue between two presenters). A few good points to show that TDD is not only about the fast red-green cycle (anyone thinks so, by the way?). Little gem: Use pomodoro specifically to break the flow, take a step back and look at the big picture.
  • Jarosław Pałka “The deconstruction of architecture in times of crisis” – very good talk about applying system thinking to software development. The theory is fairly well applicable to our craft, and the interdisciplinary view helps you see it in different perspective. Briefly explained some pieces of the theory as well as a few concrete examples (tragedy of the commons, boiling frog syndrome). I only found one important bit missing: Theory of constraints. Suggested reading: Thinking in Systems: A Primer.
  • Jakub Kubryński “Microbenchmarks performance in the smaller scale” – difficult choice (in conflict with Jessica Kerr’s FP/OOP talk), but I went for this one since the topic was less familiar. And I don’t regret it. I learned a ton about Java execution model: The role and place of JIT, possible optimizations, and finally the impact on microbenchmarks (and ways to do them better).
  • Sławomir Sobótka “Evolutionary Distillation of Architecture” (in Polish, I took the liberty of translating the title) – introduction to ports & adapters (aka hexagonal architecture). As usually, served in a broader context on thinking about how we code, what tools we use and why we should constantly learn new ones. As always, very entertaining, professional and inspiring. Little gem: If someone only knows entity and service, he’ll go at great lengths implementing everything with just those two concepts. Related reading: Hexagonal Architecture by Alistair Cockburn.
  • Piotr Bucki on cross site scripting attacks – nice presentation on XSS, discussing various ways to protect an application: input sanitization and validation, escaping on input and output, white list filtering for places which need to allow special content (like auction descriptions with limited HTML). Conclusion: Sanitize and validate input, escape everything on output. Careful, include all directions and outputs – validate batch import from files, don’t even trust your own logs (someone could deliberately execute an invalid request to have it logged, and then XSS into your admin log viewer). Solid, though not spectacular talk.
  • Wiktor Żołnowski “Reversed Tests Pyramid – dealing with legacy code” – great idea on approach to testing legacy code that can’t easily be covered with unit tests. Start with end-to-end tests (in bigger number that would otherwise be necessary) to gain some understanding and confidence in refactoring. Write more and more lower level tests as you refactor. Eventually throw away slow higher level tests as they become redundant and invert the pyramid as it should be. Quite fun, felt almost like a BOF session (appropriate for the evening). Hated one bit: Looking down upon the audience and repeating “I moved from development to coaching a few years ago”, “This is probably not interesting to you, developers” etc.
  • Thomas Sundberg “How to fail a software project fast and efficiently?” – pretty bad presentation. Could’ve been fun and sarcastic, but was really shallow and dull. Very little content, no argumentation.
  • Adam Bien “Java EE Future Is Now, But It Is Not Evenly Distributed Yet” – positive suprise! Went there just because I know so little about recent JEE and wanted to see something new. Very professional and dense. On our eyes Adam built a JEE app from scratch that demonstrated dependency injection (including configuration/params), differences between EJB and non-EJB life cycles, JSF, asynchronous execution (comet), event propagation… Very good mix of humor and live coding. Repeat, that was one spectacular live coding. I expected some fanaticism, but got none of that sort – some respect to Spring and others, but actually focusing on showing how JEE became lean and cool, not bashing the competition.
  • Patrycja Wegrzynowicz “Security Vulnerabilities in OpenSource Java Libraries” – stats done bad. Most of the presentation was a view statistical views on data for number of vulnerabilities discovered in various libraries and app servers. Ignoring information on how quickly the holes are patched (or whether there are workarounds known to community), it literally contained information such as over X years 100 issues have been discovered in Tomcat, 20 in JBoss, so Tomcat is much more likely to be insecure. But app servers from IBM and Oracle are even worse, they’ve had more issues discovered over so many years.
  • Hardy Ferentschik “JPA into the Cloud Introducing OGM and OpenShift” – demonstrated an experimental Hibernate extension to persist JPA to NoSQL databases (and deploy that to cloud using OpenShift). Not yet production ready, has some rough edges and I’m not completely sure why you’d want to do that. Anyway – challenging, interesting, well prepared and presented.
  • Gustaf Nilsson Kotte “Surviving the Zombie Apocalypse of Connected Devices” – proposal to use HTML hypermedia as the data format for all kinds of environments. Create a basic HTML model that can be viewed by any browser (leverage the fact that browser can display HTML data in a nice way). That can be used directly as default for most non-critical screens. For more interesting (or critical) areas or environments, use HTML merely as data format and build an app on top of that. We have tools to parse and generate HTML, so why not use it as data format? Very interesting idea – instead of REST and all kinds of unprintable data formats, use a popular format that has decent support and can be displayed by any device. The talk was pretty hard to follow, though – too calm and sleepy.
  • Jessica Kerr “Git Happens” – very good talk on Git to close the conference. No live demos, very good explanation of basic concepts. Not just the happy path, and not overly optimistic. Also, Jessica is an excellent speaker – passionate (sometimes to the point of running, screaming and damaging equipment), but also with a very good plan and attention to detail.

All in all, I’m quite satisfied with this conference. Like any, it had some low points and on one or two occasions I skipped the talks because there was nothing interesting to me in that hour. Feels small and local compared to 33rd Degree, and doesn’t have the community vibe of Confitura, but certainly has its place. Anyway, I learned a few new things, most of the presentations were good and a few were great, so it definitely was worth it.

Hello, Backbone and ClojureScript

A few days ago I started learning ClojureScript. I wrote a trivial “hello world” application just to get ClojureScript to compile and execute, and later added some basic jQuery support with jayq.

The time has come to make things a little bit more interesting and add Backbone.js to the mix. I’ve never done ClojureScript or Backbone before, so I’m learning them at the same time with an interesting learning curve.

Anyway, I managed to rewrite the first two examples from Backbone docs to pure CLJS. I made some minor modifications like triggering events on button click and changing main background instead of sidebar.

Here’s my page source (with Hiccup):

   [:button#clickable-event "Click to trigger an alert from basic Backbone event"]
   [:button#clickable-color "Click to change background color"]

As you can see, it renders a very basic page with two buttons and includes a few JS libraries.

And here’s the CLJS file mixing jQuery and Backbone:

(ns hello-clojurescript
  (:use [jayq.core :only [$]])
  (:require [jayq.core :as jq]))

; Rewrite of
(def o {})

(.extend js/_ o Backbone.Events)

(.on o "alert" 
  (fn [msg] (js/alert msg)))

(jq/bind ($ "#clickable-event") :click 
      (fn [e] (.trigger o "alert" "Hello Backbone!")))

; Inspired by but without sidebar

(def MyModel 
  (.extend Backbone.Model
      (fn [] 
        (let [ css-color (js/prompt "Please enter a CSS color:")]
          (this-as this
                   (.set this (js-obj "color" css-color))))))))

(def my-model (MyModel.))
(.on my-model "change:color"
  (fn [model color]
    (jq/css ($ "body") {:background color})))

(jq/bind ($ "#clickable-color") :click 
         (fn [e] (.promptColor my-model)))

There’s a number of new things (to me) and nonobvious pitfalls. View this side-by-side with Backbone demos, and note:

  • To invoke _.extend(o, Backbone.Events), do (.extend js/_ o Backbone.Events). ClojureScript will correctly transform (.extend js/_ ...) to _.extend(...), and it will copy Backbone.Events as is (no quoting necessary)
  • To distinguish between objects and functions defined elsewhere and in CLJS, always prefix the former with js/name. Works for alert, underscore etc.
  • I had an issue with passing objects (as maps) directly to calls like Backbone.Model.extend(). Tried things like {:promptColor fn} and {"promptColor" fn} to no avail. I finally discovered (js-obj) and it did the trick, but it’s pretty cumbersome. I wonder if there’s a better way.
  • You need some extra work to use this. It has to be bound to a Clojure symbol with this-as macro.
  • On a slightly related note, I really begin to love jayq. In this example I use bare Backbone directly and struggle, and really appreciate jayq bridging the gap to jQuery. I wonder if there is a CLJS wrapper for Backbone.

All in all, it’s an interesting exercise. Just the right learning curve – stimulating, but not discouraging, regularly providing visible feedback.

As usually, complete source is at GitHub. I created a new repository for it, to keep “hello ClojureScript” as small as possible. This new demo probably will grow as I learn more Backbone.

Hello, ClojureScript! (with jQuery)

I decided to give ClojureScript a try. It did not come easy, because I found the official documentation somewhat complicated. I know there is ClojureScript One, but that project also is not as simple as it could be. I don’t want fancy functionality, noir/compojure, enlive/hiccup, and tons of other semi-relevant tools. Bare simplistic HTML and a starting hook for ClojureScript is pretty much all I need for the head start, I can add the rest later.

I was looking for something really minimal, and the first simple example on my Google search was Daniel Harper’s article. I got rid of noir, used up to date versions of libraries, and voila – it’s working!

When I had my first “hello world” alert showing on page load, I decided to make things a little bit more interesting and introduce jQuery. I found jayq from Chris Granger and decided to give it a shot. There’s also a sample app on Chris’ blog that helped me with some issues, namely figuring out how to bind events. It references a few more interesting libs (namely fetch & crate), but I’ve had enough for now. I guess I could spend the whole night chasing such references.

In the end, the interesting pieces of code are below:

project.clj (configured to compile CLJS from src-cljs to resources/public/js/cljs.js):

(defproject hello-clojurescript "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "Eclipse Public License"
            :url ""}
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [ring "1.1.6"]
                 [jayq "0.1.0-alpha3"]]
  :plugins [[lein-cljsbuild "0.2.8"]]
   :source-path "src-cljs"
    :output-to "resources/public/js/cljs.js"
    :optimizations :simple
    :pretty-print true
  :main hello-clojurescript.core

core.clj (trivial app, with Ring wrapper configured to serve JS resources):

(ns hello-clojurescript.core
  (:require [ring.adapter.jetty :as jetty]
            [ring.middleware.resource :as resources]))

(defn handler [request]
  {:status 200
   :headers {"Content-Type" "text/html"}
   (str "<!DOCTYPE html>"
        "<p id=\"clickable\">Click me!</p>"
        "<p id=\"toggle\">Toggle Visible</p>"
        "<script src=\"\"></script>"
        "<script src=\"js/cljs.js\"></script>"

(def app 
  (-> handler
    (resources/wrap-resource "public")))

(defn -main [& args]
  (jetty/run-jetty app {:port 3000}))

hello-clojurescript.cljs (this one gets compiled to JavaScript):

(ns hello-clojurescript
  (:use [jayq.core :only [$ delegate toggle]]))

(def $body ($ :body))

(delegate $body :#clickable :click
          (fn [e]
            (toggle ($ :#toggle))))

Complete source code with instructions can be found at my GitHub repository.

At the moment I see the following issues:

  • I’m really green at ClojureScript. Tons to learn here!
  • The JavaScript file compiled from this trivial example is 13k lines long and weighs about 500 kb. Doh! Fine for local development on desktop, not that good for targetting mobile.
  • The official docs for ClojureScript are really… discouraging. Just like core Clojure documentation, they are pretty academic and obscure.
  • Docs for jayq are… Wait a minute, nonexistent? At least it’s a fairly thin adapter with small, comprehensible codebase.

DevDay 2012

On October 5, 2012 I attended the second edition of DevDay, a one-day conference sponsored and organized by ABB in Krakow.

The Awesome

Scott Hanselman was the first speaker, and also one of the main reasons why I went to the conference. Even though I only knew him from This Developer’s Life.

His “Scaling Yourself” talk was probably the best productivity talk I’ve seen so far. Part of it was tricks and techniques I have already known, such as GTD and pomodoro. Apart from that, my notes include:

  • The fewer things you do, the more of each you can do.
  • By doing something you are likely to get more of it. If you’re available on weekends and after hours, you will be expected to do it. If you’re available for calls about work on vacations, you will be called. Even if you do work at that time, set that email to go out at 9 AM next business morning.
  • Avoid “guilt systems” such as long collection of recorded TV shows – or books, or unread articles. Or whatever it is that you collect and want to do, but eventually forms a big pile that you only feel guilty about.
  • Sort your information streams by importance and limit usage. Some obvious ones like do less Twitter or Facebook. Some less obvious ones like basic email filters. Combine that with techniques that help you root out the distractions such as pomodoro or Rescue Time.
  • Use information aggregators: Blogs or sites that repost articles, mashups etc. instead of subscribing to 100 different blogs and news sites.
  • Do not multitask, except for things that go well together. Foe example, exercise while watching TV or listening to podcasts. What’s more: use activities you want to do to motivate things you should do. For instance, watch TV only as long as you keep on moving on the treadmill.
  • Plan your work: Find three things you want to do today, this week and this year, and do them. Helps you set the focus on goals. Hint: Email & twitter probably won’t be on the list.
  • Plan your work: Plan your own work sprints, execute, and finally perform retrospectives. Can be applied to work, but also all kinds of personal activities.
  • Synchronize to paper. Don’t limit your space to one screen when you can print or write/draw it on as many sheets of paper as you want. Also, paper notebooks can be used in different conditions and never run out of battery..

Finally, Scott is a great speaker. Lots and lots of content served in a perfect way, sauced with some pretty good jokes. Delicious.

That’s just a bunch of quick notes. Even if you think you’ve heard enough on the topic of productivity, go watch the presentation on Scott’s site. Now.

The Good

I enjoyed the “Why You Should Talk to Strangers” talk from Martin Mazur. Half of it was about social interactions: “us versus them” divisions, difficulties that one can face when approaching complete strangers in public, and the amount of new things you can learn from them if you break the ice. The rest was really about polyglot programming: learning Eiffel, Haskell or Ruby and applying some concepts and ideas back to C#. Largely an unknown territory, but still the talk resonated really well with me.

Antek Piechnik gave a good talk on continuous delivery at an extreme scale: Where each new team member pushes code to production during the first week, and each commit to master can trigger deployment. I found the ideas on project organization pretty controversial, though: having a totally flat team, large pool of features and everyone working on what they want and how they want. Sounds interesting, but it’s only possible if you have only experienced A++ programmers in team that also have the same vision, agree on tools and techniques, and so on.

Finally, I liked Greg Young’s talk on getting productive in a project in 24 hours. The talk was nothing like the subject, though. Basically an introduction to code analysis: afferent/efferent coupling, test coverage and cyclomatic complexity, as well as data mining VCS. Very clear and down-to-earth, discussing some tools and practical examples for each concept.

I particularly liked the points on code coverage. I knew that method with 20 possible paths can have 100% line coverage from 2 tests, but still be poorly tested. Greg made a good point explaining that method coverage gets worse as the number of methods/collaborators between the test and the method grows, or when the methods between the test and our method have high cyclomatic complexity. In such cases it’s really an accidental coverage that in no way guarantees security.

Greg repeatedly stressed how all these concepts are only tools. They indicate interesting areas that may be trouble spots and may need attention. But one can never say that cyclomatic complexity of X is good code and Y is bad code (and the same is true for all other metrics).

The Rest

Rob Ashton’s talk on JavaScript was alright, but not spectacular. I did not learn much new. I know that the language is here to stay, for better or worse. You can patch some gaps with jslint/jshint and others with CoffeeScript, but for its spread the tooling is really patchy and barely existent.

I skipped Mark Rendle’s talk on Simple.Data/Simple.Web. Not my area.

I really did not like Sebastien Lambla’s talk on HTTP caching. Noise to signal ratio approaching infinity. Filled with poor jokes and irrelevant comments. Little, chaotically and patchily discussed substance.

Wrapping Up

All in all, DevDay was a good conference. Really good selection of speakers on a free conference, with free lunch, coffee and snacks. No recruiters, no stands, just the participants and speakers. I wish it had at least two tracks and more focus. I’m not sure if it’s a generic developer conference or a .net event (went for the former, felt atmosphere of the latter).

Configuration Files in Clojure

I recently made a contribution to ghijira, a small tool written in Clojure for exporting issues from GitHub in JIRA-compatible format. One of the problems to solve there was loading configuration from file.

Originally, it used have a separate config.clj file that looked like this:

(def auth "EMAIL:PASS")
(def ghuser "user-name")
(def ghproject "project-name")
(def user-map
  { "GithubUser1" "JIRAUser1"
    "GithubUser2" "JIRAUser2"})

Then it was imported in place with:

(load-file "config.clj")

I did not like it, because it did not feel very functional and the configuration file had too much noise (isn’t def form manipulation too much for a configuration file?).

For a moment I thought about using standard Java .properties files. They get the job done, but they’re also somewhat rigid and unwieldy.

It occurred to me I really could use something similar to Leiningen and its project.clj files: Make the config a plain Clojure map. It’s very flexible with minimal syntax, and it’s pure data just like it should be.

From a quick Google search I found the answer at StackOverflow.

It turns out I can rewrite my configuration file to:

{:auth      "EMAIL:PASS"
 :ghuser    "user-name"
 :ghproject "project-name"
   { "GithubUser1" "JIRAUser1"
     "GithubUser2" "JIRAUser2" }

And then load it in Clojure with read:

(defn load-config [filename]
  (with-open [r (io/reader filename)]
    (read ( r))))

That’s it, just call read.

I find this solution a lot more elegant and “pure”.

By the way, this data format is getting a life of its own, called Extensive Data Notation. The Relevance team has even published a library to use EDN in Ruby.