The Holy Java

Building the right thing, building it right, fast

Archive for April, 2014

Most interesting links of April ’14

Posted by Jakub Holý on April 30, 2014

Recommended Readings

  • The economics of reuse – developing code for reuse costs much more than for one need – it might cost 300% more to develop and save you 75% of work when (re)using it instead of developing from scratch (if one of the factors goes down, the other one typically goes down too). Summary: “That means that to get any value from your reused component, you better have five or more reusers or you have to find a way to substantially improve the [reuse value factor] or [reusability cost factor]. Very smart people have failed to do this.
  • Book in making: Reactive Design Patterns (1st ch free)

Sharing data on the web

Clojure Corner

  • 8th Light: Combining Clojure and ClojureScript Libraries (3/2014) – really good and detailed article / tutorial using CLJX and platform-specific platform.clj[s] files to share code between Clojure and ClojureScript. It also recommends a file structure (src/(clj|cljs)/), demonstrates testing, discusses macro development, shows how to pack both into one jar.


Favourite Quotes

Posted in General, Languages, Top links of month | Tagged: , , , , | Comments Off on Most interesting links of April ’14

Clojure: How To Prevent “Expected Map, Got Vector” And Similar Errors

Posted by Jakub Holý on April 30, 2014

What my Clojure code is doing most of the time is transforming data. Yet I cannot see the shape of data being transformed – I have to know what the data looks like on the input and hold a mental model of how they change at each step. But I make mistakes. I make mistakes in my code so that the data does not correspond anymore to the model it should follow. And I make mistakes in my mental model of what the data currently looks like, leading likely to a code error later on. The end result is the same – a little helpful exception at some later step regarding wrong shape of data. There are two problems here: The error typically provides too little useful information and it usually manifests later than where the code/model mistake actually is. I therefore easily spend an hour or more troubleshooting these mistakes. In addition to that, it is also hard to read such code because a reader lacks the writer’s mental model of the data and has to derive it herself – which is quite hard especially if the shape of the input data is not clear in the first place.

I should mention that I of course write tests and experiment in the REPL but I still hit these problems so it is not enough for me. Tests cannot protect me from having a wrong model of the input data (since I write the [unit] tests based on the same assumptions as the code and only discover the error when I integrate all the bits) and even if they help to discover an error, it is still time-consuming the root cause.

Can I do better? I believe I can.

Read the rest of this entry »

Posted in Languages | Tagged: | 8 Comments »

How to create and run Gatling 2.0 tests

Posted by Jakub Holý on April 28, 2014

Getting up and running with Gatling perf. tests as I would like so I record this for my future reference.

0. Create a project:

$ mvn archetype:generate \

(The trailing “:” in the filter is important.)

1. Import to IntelliJ

In IntelliJ choose to import an object, instead of “from sources” select “from external model” and then Maven. You will also need to have the Scala plugin installed and, when imported, you will likely need to right-click on pom.xml and Maven – Reimport.

2. Record a simulation

  1. Run the src/test/scala/Recorder.scala (right-click – Run ‘Recorder’)
  2. Set the port it should listen on, f.ex. 8000 (maybe you also need to set port for HTTPS, f.ex. 8001), set the target app (perhaps localhost, <some port>, <some https/dummy port>)
  3. Optionally set the class name of the recorded simulation and the target package (the output goes to src/test/scala/<package>/<name>.scala)
  4. Click [Start !]
  5. Go to your browser and configure it to use the recorder as its HTTP[s] proxy
  6. Browse localhost:8000/your_app as you want for the test
  7. Click [Stop and save] in the Recorder UI

Read the rest of this entry »

Posted in Testing, Tools | Tagged: , | Comments Off on How to create and run Gatling 2.0 tests

Kioo: How to Troubleshoot Template Processing

Posted by Jakub Holý on April 8, 2014

So you have created an Om/Reagent/React component using a Kioo template and the result is not as you expected, perhaps just an empty element? Let me share what I have discovered about troubleshooting this (though I am no expert). You will se how to invoke the underlying Clojure function component* manually, how to expand the deftemplate macro, how to call the resulting JavaScript function, and what the intermediate forms look like.

Read the rest of this entry »

Posted in Languages | Tagged: , , | 3 Comments »

Kioo: How To Replace The Whole Body

Posted by Jakub Holý on April 8, 2014

This whole post in unnecessary since it is simply possible to use a snippet directly without a template, as kindly explained by Creighton Kirkendall.

Kioo, the enlive-inspired templating library for React.js and derived libs such as Om, normally works by matching selectors against elements inside <body> and transforming the matched elements while also keeping all the other ones. But what if you want to keep just the single matched element and drop all the others? You need some tricks and I will demonstrate one possible way.

Dislaimer: This is a result of my experimentation, not deep knowledge if Kioo.

Read the rest of this entry »

Posted in Languages | Tagged: , | Comments Off on Kioo: How To Replace The Whole Body