Tuesday, December 31, 2013

2013 summary

This post is meant to be a point of reference for the upcoming year, that is to track my own progress (or lack of it) in the future.

Most notably:
- new job - moved to London to work for Sky Network Services (part of Sky)

Paired (as in Pair Programming):
- remotely with 2 persons (thanks to Avdi Grimm's #pairwithme)
- locally with ~15 people

Coded:
- professionally in: Java, JavaScript
- for fun in: Ruby, Clojure
...and very briefly in: Bash, Python, C#

New frameworks and tools used in projects:
- Gradle (multi-language build tool)
- AngularJS (single-page apps with JavaScript)
- Jasmine and PhantomJS (unit testing setup for JavaScript)
- SpringJDBC (Database interface for Java)
- Jersey (RESTful web services for Java)
- Yatspec (supporting Java tool for Behaviour Driven Development)
- Spark (Sinatra-inspired micro framework for web applications in Java)
- writing one's own MVC framework
- ...and  IntelliJ (Java IDE), Mac, MacOS, TeamCity (Continuous Integration supporting tool)

Attended meetups:
- Global Day of Code Retreat 2013 at Valtech, London (by LSCC)
- Software Craftsmanship Round Tables (by LSCC)
- Evening Code and Coffee / Craft Beer (by LSCC)
- eXtreme Tuesdays Club
- Architectural Kata with Alexandru Bolboaca (by LSCC)
- BDD workshop with Steve Tookie (by LSCC)
- BDD workshop with Meza Meszaros (by eXtreme Tuesdays Club)

Seen live and had a short chat with:
- Kent Beck ("My first feature and beyond: Why I work at Facebook")
- Uncle Bob ("Automated Acceptance Testing", "Professionalism", "Design Patterns")

Seen live (people I had heard of before moving to London):
- Michael Feathers, Steve Freeman, Nat Pryce, Dan North, Tim Mackinnon, Liz Keogh, Keith Braithwaite, Sandro Mancuso, Giovanni Asproni, Enrique Comba Riepenhausen

Read books:
- Practical Object-Oriented Design in Ruby by Sandi Metz
- Smalltalk Best Practice Patterns by Kent Beck
- Responsible Design in Android by J.B. Rainsberger
- Confident Ruby by Avdi Grimm
- Are your lights on? by D. Gause, G. Weinberg
- ... and partially bunch of other ones :)

Watched podcasts/screencasts:
- Destroy All Software by Gary Bernhardt
- Clean Coders by Uncle Bob
- Test-Driven Development by Kent Beck
- Ruby Rogues

And finally read/watched way to many blog posts, articles, interviews, conference talks, etc :)





Saturday, November 2, 2013

Silent Pair Programming

On Thursday 31 October I participated in a Silent Pair Programming event organised by the London Software Craftsmanship community. During the sessions pairs are not allowed to talk about the problem and they can only discuss secondary issues as the IDE, keyboard shortcuts, etc. The goal of the exercise is to communicate with code and maximise its readability. Here are a couple of my learnings from the session.

If the partner writes a test which requires too much of implementation code at once, one way to solve it is to make it pass by hardcoding the response and then writing a smaller test. Once implemented, the following test should prove the hardcoded response insufficient and in consequence to its removal by generalising the production code.

When working on the production code, it might be worth following Kent Beck's Composed Method pattern (from "Smalltalk: Best Practices and Patterns"). That is, let your partner follow your thoughts by implementing the method (almost) entirely with well-named private methods and variables. Programming language specific features and APIs should be hidden in the private methods. The reason is that they are often too generic to convey the intent. Once the test is green, the pair might want to minimise the code by inlining some of the private methods, if the underlying generic code does not obscure the readability.

If you don't understand what a piece of code written by your partner does, you might want to select it in the editor and hand over the keyboard to them, so that they refactor it towards more clarity.

If you can think of any other tips for Silent Pair Programming sessions, please feel free to post them in the comments :)





Wednesday, September 18, 2013

Manual Dependency Injection with Jersey and embedded Jetty

I wrote a little application demonstrating how to manually (through constructors) inject dependencies into Jersey resources in an embedded container like Jetty. 

The benefits are:
- lightweightness (no need to use Spring, Guice, etc.),
- more control over your application (less magic behind the scenes),
- controlling dependencies in tests (via Dependency Injection)
- running a web app with a simple Java main method (via embedded Jetty)

The example application is called Time Expert. It exposes the current time via a RESTful web service, so when I run it in the production (via Main.java) I can use it as following:

Here's how I test it (TimeAcceptanceTest.java) :

However,  I cannot rely here on the real time because it changes every time I run tests . The problem can be easily solved with the Clock pattern. My tests require a FixedClock which allows me to set the current time to any value:



 So I start my server with a fixed clock:


... and then set it to, say, 20:15:


Since my Jersey resource class is only aware of the clock interface, it will display 20:15:


In order to create your Jersey resources with manually injected dependencies you have to register org.glassfish.jersey.servlet.ServletContainer with a customized org.glassfish.jersey.server.ResourceConfig. In that config Jersey resources can be newed up with their dependencies:

Of course the production provides a real clock (which returns new Date()):


Code is available under: https://github.com/unclejamal/TimeMaster

Enjoy!

Tested using:
- Java 1.7,
- Gradle 1.7 (easily convertible to Maven :)),
- Jersey 2.2,
- Jetty 9.0.5.