Monday, 23 December 2013

December disappeared in a rush of vacation and a fleeting tour of Australia. It's hard to believe that it's the eve of Christmas Eve already, it's almost impossible to feel Christmassy when you're getting sunburnt on a boat and seeing people in swim-suits wearing santa hats. A mid-winter festival (complete with trees and fake snow) just feels very odd in summer.

I cannot take Christmas seriously in this weather

YOW! is a unique conference, in that it's the same agenda in three different cities: Melbourne, Brisbane and Sydney. It seems to me that this is a great way to attract speakers from a long way away (and everywhere is a long way away from Australia) but make it cost effective - although you have to shuttle the speakers between the cities, you have the speakers for nearly two weeks and get the material three times in the three different locations.

I suffered a lot for this conference...

As a speaker, it's awesome - not only do you spend the better part of the month in the sun when your hemisphere is nearing mid-winter, but you also have the opportunity to really get to know the other speakers - you're sharing bus journeys, flights and dinners together for a week and a half. Also, because you're at the same conference three times, you have the chance to see a lot more of the talks. I admit I missed most of them in Melbourne because I was re-writing and practicing both my talks (note to self - next time, only commit to one talk), but by Sydney I saw the talks that I wouldn't normally get around to - talks on technologies I'm not currently using and probably won't get a chance to. But it was great to see other approaches to problems, and the variety of presentation styles.

Since I saw most of the talks, I thought I'd give a run down of those I watched (now I feel bad I didn't get a chance to see everyone's, if I missed you it's not because I don't love you):

I've seen Jeff talk on this subject twice before - an earlier version of the talk at Strangeloop 2012, and then the keynote at GOTO Aarhus. It's a really fascinating approach to machine learning that's different to traditional Artificial Intelligence approaches. It's waaay beyond my comprehension level, but reminded me why I studied AI at university. If you get a chance to see it, I recommend it. There's a video available of the Aarhus talk.

A thought-provoking talk on how agile teams succeed. Mostly it talks about how a process is not going to save you, that you need to find your own approach from all the practices that are available. I liked the message because it's very Lean Startup-ish, and I think the approach of getting feedback and learning from it is the best way to succeed. My take-home points:

Change from a delivery-focussed organisation to a learning organisation

Even if you're not using Neo4J or other graph databases, it's worth seeing this talk just to understand what sort of problems graphs are good at solving. Also to see how graph theory could have predicted the first world war (not sure if this was funnier or more awkward when Jim presented this in Berlin...). A great talk if you're interested in Data Structures or the NoSQL space. Not so good when Jim feels compelled to make Mongo Is Web Scale jokes because he sees yours truly in the front row. Will we never get over that? Jim's a great presenter and therefore this theoretical talk is very approachable.

Take home points:

With graph databases your query emerges from the structure of the graph itself

It seems like another interesting way of modelling your domain

Most databases are tuned for size because traditionally size impacts the cost of querying

In a graph database, query latency is proportional to the size of the graph you want to explore (not to the whole database).

Quite an in-depth talk about how the JVM could evolve to support more than simply Java-the-language. Interesting at an abstract level for us Java developers to see how our language is not the be-all and end-all, and get a glimpse of things we might need to care about in the future. Not too many take-home points for the every day developer, but definitely interesting for those more interested in how a language is built and what goes on behind the scenes.

A look at the whole landscape - past, present and future - of RDBMS/SQL, NoSQL, NewSQL. It's a good way to step back and see what's going on there, not to blindly follow the new trends. The thoughts that occurred to me:

NoSQL solutions might not be the silver bullet solution, but by offering lots of different persistence options we're challenging perceived best-practices and having conversations around how to store and access our data

Michael gave a really great talk on where the DevOps movement started, what it's all about, and tackled some of the fears and obstacles that people and organisations face that can prevent them doing things in a more DevOps-y way (and problems that you keep seeing when you separate Dev and Ops). I saw a lot of things in this talk that resonated with my experiences, and it was another example of how the hard stuff in our jobs is all about the people and the politics, not the technologies.

What if you measured Ops on the number of features going into production, and Dev on the stability of production?

Performance is a feature.

You'll never teach yourself out of a job, the more you teach, the more people will rely on you

A failure-inducing system is a system that lets people fail. Don't blame the people.

Your development tools and environment are part of production, because they are on the critical path to production, and should be treated as such.

Given my interest in Software Design this year, this was a talk that was close to my heart. It looked at each of the SOLID principles, where they came from, what they are, helped us understand why we need to care about them (or not). It became clear to me that as we become more experienced, as we grow, we need to continually re-visit the things we think we know, or the basics of what we're trying to do, as you'll find things there that surprise you - things you thought you understood, or things that you didn't understand before and now have more context for. In particular, I learnt another argument against using inheritance willy-nilly (one of my current favourite bug-bears)

Writing software is like writing fiction.

Experts say "it depends" because they know a number of rules which might be applicable.

You can't change published interfaces because other people are dependent upon your code (pretty much the entire basis of my Backwards Compatibility talk), but if you own the code you can change it to your heart's content.

Netflix are doing some really amazing stuff with architecture, design and code, and what I love the most is that they're willing to share it with the rest of us. Rx and reactive programming are big buzz words at the moment, and the event-driven, asynchronous approach is something that we embraced at LMAX and is now, to my mind, an "obvious" way to create scalable systems.

I liked Ben's visualisation of the events in the system using marble diagrams, and I liked that he showed us code and walked through it. There were a number of things to get your head around in the talk, and I personally would like to see it again to see what I missed first time around. Definitely worth watching if you're interested in this way of coding, I think it's a paradigm that will be used more and more.

I don't know why it never occurred to me that you could create a framework for professional development for agile coaches. Lyssa and Michael have done just that, and having something a bit more formalised helps figure out what a coach needs to do in order to develop further. Agile coach, scrum master, iteration lead... all these titles do not currently tell anyone how good you are at the job or what your strengths and weaknesses are. The Agile Coach Competency Framework seems like a good starting point for conversations around: the coaches you have; the coaches you need; your current skills as a coach; the direction you want to go in as a coach. If you need to hire or develop an agile coach, or if you are a professional in this space, this is worth looking at.

I was so pleased to hang around with my old LMAX colleague during YOW that I totally failed to take the time to see all of this talk. Depending upon the city it either clashed with mine or was immediately before. However, it's a must-see for fans of the Disruptor, Mike goes into detail about what's in the latest version of the Disruptor, how and why these things work. I'll definitely be watching the video when it's online.

A funny, polished, brilliant keynote. Honestly I can't remember anything about it other than something-something-Microsoft-cloud, and push things down to the client because there's power there, but don't let that put you off - I did not write notes, I simply sat and enjoyed every minute of it. It was a great performance, and a reminder of how much practice it takes to become a truly good keynote speaker.

It was the best presentation of the conference. Different to anything I'd seen before, engrossing, creative, fun. Sure, watch the video, but if you get a chance to catch this at any other conference, I highly recommend seeing it in person.

I nearly didn't go to this talk, because we did BDD at LMAX and I'm trying to lead us towards this at MongoDB and I know all this stuff blah blah blah. I'm so glad I did go - not only is it nice to have your opinions confirmed and the concepts you try to live by repeated to you again, but there were things in here that should help me push the BDD approach more.

One of the things I remember Liz for is explaining the use of the word "should" at the Lean conference at Bletchley in 2010. In this talk I was struck once again how important the words we use are: should, given/when/then, and so on, giving us a framework for thinking about a problem. It's one of the reasons I wanted to move towards Spock, because it forces the use of some of these words.

I wrote lots of notes:

Assume you got it wrong

Is there a context in which the event will create a different outcome? (Your account is empty, the ATM is out of cash, you have a pre-approved overdraft)

Don't think of the software that will solve the problem, assume it will be done by pixies (like Pratchett's Iconograph), forcing us to stop thinking of solutions when we're trying to outline the problem.

Not all user stories are about the user, they might be about other stakeholders

Acceptance criteria vs scenarios - "Can you give me an example?"

Ask why a change needs to be made or why something is a bug, if I've messed up this feature I might have messed up something else

Testers do think differently to developers, they have a process of deliberate discovery

BA/Dev/Tester huddle - the three amigos

If a project has no risks, don't do it

Complicated/Complex/Chaotic/Simple projects/systems. Some types of systems don't lend themselves well to BDD

All the risk is in Complex problems, and this is also likely where the value is. This is the area that developers tend to like to live.

Afterwards I questioned Liz on her separation of Devs and Testers in the talk - this seems contra to the current trend of hiring developers-in-test or other moves to make QAs and developers one-team-one-dream. She pointed out that it's less of a job description and more of a role that people take in a team. Then she suggested I was currently in a tester role, not developer, as my mindset is very much focussed around proving our code quality rather than jumping in and implementing features. I think it was meant as a positive thing...

"Microservices" is another one of these buzz words doing the rounds at the moment. There was a lot of discussion amongst the speakers about how micro is micro, and one definition I liked was "a microservice is a service that does one thing and one thing only". In Sam's talk I got an idea of why microservices are a Good Thing, and how you might go about moving in that direction. There was practical advice on things you should be doing if you're using this kind of architecture:

Align your services with your organisational structure

Microservices let you deploy independently and move faster, and you can run each service in whichever technology / language is right for the job

I saw this because I'm interested in geolocation and geo-stuff at the moment, but this talk wasn't really about the sort of thing I'm playing around with. It was (to my mind) really interesting material though - using satellite images from the past few decades to spot patterns and predict things. It's really nice to see applications of technology that could potentially impact the whole world, rather than just things that make money for companies. My Dad, who's a geography teacher, would have loved this talk.

Really interesting talk, always to a packed room, about how Netflix has created a scalable architecture. As I said earlier, I'm really impressed with what they're doing, I'm particularly interested in their chaos monkeys and primates. I definitely recommend seeing this presentation.

A look under the covers of how Facebook ships things. It's a very interesting contrast to the Netflix, microservices approach. It's great to see the different approaches at the same conference, maybe it gives people an idea of the pros and cons of each way forward.

What I particularly liked from Facebook was that the teams seem to be set a goal, and then they're free (to some extent) to pick what to work on in order to meet that goal. There's definitely an experimentation side to things (very Lean Startup again), a lack of fear of trying new things, some stuff will work and some won't, that's life. But at the end of the day there's a definite measurable that will tell you if you're doing the right thing or not. On the VM team, the aim is to get CPU cycles down, that's it. This is a very different approach to having a backlog of stories that's prioritised by the business. Interesting and useful stuff in this talk.

I'll be honest, I went to this talk because I chatted to Jay a number of times throughout the travelling circus, and I liked him - I have almost zero interest in Clojure at this moment in time. But I'm really glad I went, because I learnt loads of stuff that's relevant for my day job (who knew?). This presentation is basically about how to introduce a new language into a company/team, and he's able to show the process over a period of several years, which in our industry is a life-time - many talks are around the latest, shiniest thing a company has introduced. He speaks frankly about the cost of introducing a new language, gives some good advice on the approach to take, and personally made me wonder if I might have bitten off more than I can chew by sneaking Groovy into the Java driver via Spock and Gradle.

Don't force people to use a different editor AND a different language - if you take away both comfort zones you'll meet resistance

Keep the other tools in place too - ant, maven, etc.

Choose non-production code to try it out on

Choose code that showcases the power of the language, its strengths

Choose something that you're willing to keep in the old language, in case it all goes horribly wrong and you have to go back

When you've introduced a new language, you've just given yourself a second full-time job - supporting that language, training people, etc.

You need to know everything - you are the expert. Read everything.

Get a budget for training and support

"It's practical to get your career sorted before playing with new technologies" (I wrote that down and now don't remember the context, but it's an interesting point)

There's so many things you can do by innovating and adopting a new language.

I always love meeting people who's books I've read (or at least, started). I've been really interested in the Domain Driven Design stuff since the guys were banging on about it at LMAX, and I've tried to use some of the concepts to drive the design of the new Java driver for MongoDB. This presentation was a specific (anonymised) case study of applying Domain Driven Design. My main take away point is that not plunging into development, that asking questions, that waiting, is sometimes the best thing you can do.

I'm not doing mobile development at the moment, so this is another talk I went to because I met Brian at the various speakers events and wanted to see his talk. It was another talk I really enjoyed - very well presented, technical, code-y, entertaining. And it also blew away my preconceptions about PhoneGap, an opinion I had formulated during my very short stint working at ThoughtWorks three years ago. If you're in the mobile space, or even in web development, definitely worth watching. If not, then maybe just give it a watch to see what's happening out there.

"We're web developers, we don't need tests"

Cadence and project heartbeat really important

"Performance first", but actually it's about the people

Find one thing and do it well

Measure everything

Build a real app and extract out the components, instead of doing enterprise architecture

Help pages with example code templates: "developers copy and paste, at least this way they'll be copying the right stuff"

Scrum-type methodologies tend to focus on user stories and feature delivery. This presentation talks about physically colouring the different types of work that you have in your backlog (tech debt, bugs, stories, architecture) and understanding how to prioritise each of them. This talk is worth seeing if you are in a Scrum-ish environment, and you have a backlog of stories. If you're struggling to find time to address tech debt, this is probably applicable too. For me, the take-away point was simply having visibility of the different types of work - often the backlog only contains stories, and the other stuff is missing. From there, you're in a better position to work out how to prioritise things.

More and more people are talking about APIs, especially as we now have lots of different ways of getting to data/applications, even if you just think web/phone/tablet. Stew gives very solid advice on how to build APIs so that you can correctly separate back- and front-end, and create (specifically) great iOS apps. There's a good intro to what REST really means too.

Different devices don't have to share the same API if it doesn't work well for them

On Objective C: "It's like ugly Ruby, or beautiful Java"

From day one send the information about the client version, the handset etc. to the server

You must worry about backwards compatibility because there's a very long tail on app upgrades

Libraries that bind your JSON have tight coupling

You can ship client code that checks if a feature is available on the server and ignore it if not - that lets you turn on the feature at the server-end

Encourage upgrades to the new version, by doing things like "if you had version 347 you could use this feature"

The phone application is the hardest thing to change so it should not be your integration point

You need an anti-corruption layer, your phone should not be pointing to the internal systems. This will be your mobile API, and can include caching and security

If your logic is in the client, it's in the place that's hardest to change.

And then there's my talks. Like I said, I was foolish enough to say yes to giving two of them, but the great thing was I got the chance to do a fluffy talk and a technical talk.

Dave Thomas saw me give a talk with this title at Aarhus, and asked me to present it at YOW. I was really pleased to get this chance, because conferences often find it hard to excuse a talk that might suggest you get a new job when your employer probably paid for your ticket.

I wasn't that happy with the Aarhus version, if I'm honest - I was trying to squeeze everything I'd learnt about managing my career over the last 15 years into an hour's talk, and I failed horribly. I re-wrote it almost entirely for YOW - it's clear there is a lot of stuff I'd love to talk about that I didn't get a chance to cover, but hopefully this talk is more broadly useful for everyone.

YOW might not have been the best audience for it, as most people had my level of experience or more, and a number of people said "I wish I'd known that 10 years ago", but my experience seems to tally with other people's, so maybe it will be helpful to more people over time.

It's kinda weird to stand there and talk about all the choices you made to get to where you are, the mistakes you've made and explain some of the choices. Especially weird if some of my ex-employers ever see the talk. But I did learn a lot of things the hard way, and I didn't end up here by accident, I want other developers (especially those in the early stages of their career) to learn things the easy way.

So yes, I've given a talk with this title a number of times this year. It morphed from the original version into two different talks - "Design is a Process, not a Document" and a more MongoDB-focussed one, which I reused the original title for. This newer, MongoDB-focussed one is what I gave at GOTO Berlin, and I decided to use this for YOW as it's a technical (ish) talk that goes into some detail about MongoDB, and they do pay my rent.

The really great (or possibly, bad) thing about YOW is that because it's the same conference at three venues, only a few days apart, it gives you a chance to put your Lean Startup knowledge into practice - you can experiment, get feedback, and improve. Like the GOTOs/QCons, they have a Green/Yellow/Red feedback system from the audience so you can get a feel for how they liked your talk (the Aussies are a bit non-committal, they were keen on the Yellow button - commit one way or another!! (or don't, I don't want more reds)). So decided to A/B test my talk - at Melbourne, I gave the GOTO Berlin one; at Brisbane, the original one with updated code and design diagrams. Since the Brisbane one got a higher score, I went with that with some minor tweaks for Sydney. The upshot is, people like hand-drawn pictures of monsters, and are less keen on understanding the internals of MongoDB. That's useful to know.

But the talks aren't the only things that make a conference. And YOW got the other stuff right too:

I loved the drinks receptions in the evenings, that's a great place for people to come and ask you questions about your talk, stuff they might not want to share in front of everyone. Note to attendees - if you do see a speaker at a drinks/network/mingle event, feel free to chat to them. We're there for you guys, and we're only people ourselves and like the company. At many events, the speakers know very few people.

Sydney had an outdoor eating area, which was awesome - if you're going to spend weeks in a conference hall, it's nice to get outside for food.

There was a, um, misunderstanding about appropriate dress code for one of the vendors. The conference organisers were on this immediately, and, to their credit, the vendor acted swiftly with no fuss. A great example of how to handle this sort of thing at tech conferences.

Having all the travel and accommodation, particularly for this complicated trip, arranged by very capable and approachable people made the speakers' lives really easy, and I think that helped us to be more prepared and relaxed for our talks.

A speaker's excursion (on a boat!) at the weekend was an amazing way to bond with the other guys.

Friday, 20 December 2013

In the last two articles on Spock I've covered mocking and stubbing. And I was pretty sold on Spock just based on that. But for a database driver, there's a killer feature: Data Driven Testing.

All developers have a tendency to think of and test the happy path. Not least of all because that's usually the path in the User Story - "As a customer I want to withdraw money and have the correct amount in my hand". We tend not to ask "what happens if they ask to withdraw money when the cash machine has no cash?" or "what happens when their account balance is zero?".

With any luck you'll have a test suite covering your happy paths, and probably at least twice as many grumpy paths. If you're like me, and you like one test to test one thing (and who doesn't?), sometimes your test classes can get quite long as you test various edge cases. Or, much worse (and I've done this too) you use a calculation remarkably like the one you're testing to generate test data. You run your test in a loop with the calculation and lo! The test passes. Woohoo?

Not that long ago I went through a process of re-writing a lot of unit tests that I had written a year or two before - we were about to do a big refactor of the code that generated some important numbers, and we wanted our tests to tell us we hadn't broken anything with the refactor. The only problem was, the tests used a calculation rather similar to the production calculation, and borrowed some constants to create the expected number. I ended up running the tests to find the numbers the test was generating as expected values, and hardcoding those values into the test. It felt dirty, but it was necessary - I wanted to make sure the refactoring didn't change the expected numbers as well as the ones generated by the real code. This is not a process I want to go through ever again.

When you're testing these sorts of things, you try and think of a few representative cases, code them into your tests, and hope that you've covered the main areas. What would be far nicer is if you could shove a whole load of different data into your system-under-test and make sure the results look sane.

An example from the Java driver is that we had tests that were checking the parsing of the URI - you can initialise your MongoDB settings simply using a String containing the URI.

Instead of having a separate test for every type of URL that needs parsing, you have a single test and each line in the where: section is a new combination of input URL and expected outputs. Each one of those lines used to be a test. In fact, some of them probably weren't tests as the ugliness and overhead of adding another copy-paste test seemed like overkill. But here, in Spock, it's just a case of adding one more line with a new input and set of outputs.

The major benefit here, to me, is that it's dead easy to add another test for a "what if?" that occurs to the developer. You don't have to have yet another test method that someone else is going to wonder "what the hell are we testing this for?". You just add another line which documents another set of expected outputs given the new input.

It's easy, it's neat, it's succinct.

One of the major benefits of this to our team is that we don't argue any more about whether a single test is testing too much. In the past, we had tests like:
And I can see why we have all those assertions in the same test, because technically these are all the same concept - make sure that each type of WriteConcern creates the correct command document. I believe these should be one test per line - because each line in the test is testing a different input and output, and I would want to document that in the test name ("fsync write concern should have fsync flag in getLastError command", "journalled write concern should set j flag to true in getLastError command" etc). Also don't forget that in JUnit, if the first assert fails, the rest of the test is not run. Therefore you have no idea if this is a failure that affects all write concerns, or just the first one. You lose the coverage provided by the later asserts.

But the argument against my viewpoint is then we'd have seven different one-line tests. What a waste of space.

You could argue for days about the best way to do it, or that this test is a sign of some other smell that needs addressing. But if you're in a real world project and your aim is to both improve your test coverage and improve the tests themselves, these arguments are getting in the way of progress. The nice thing about Spock is that you can take these tests that test too much, and turn them into something a bit prettier:
You might be thinking, what's the advantage over the JUnit way? Isn't that the same thing but Groovier? But there's one important difference - all the lines under where: get run, regardless of whether the test before it passes or fails. This basically is seven different tests, but takes up the same space as one.

That's great, but if just one of these lines fails, how do you know which one it was if all seven tests are masquerading as one? That's where the awesome @Unroll annotation comes in. This reports the passing or failing of each line as if it were a separate test. By default, when you run an unrolled test it will get reported as something like:

But in the test above we put some magic keywords into the test name: '#wc should return getlasterror document #commandDocument' - note that these values with # in front are the same headings from the where: section. They'll get replaced by the value being run in the current test:

Yeah, it can be a bit of a mouthful if the toString is hefty, but it does give you an idea of what was being tested, and it's prettier if the inputs have nice succinct string values:

This, combined with Spock's awesome power assert makes it dead simple to see what went wrong when one of these tests fails. Let's take the example of (somehow) the incorrect host being returned for one of the input URIs:

Data driven testing might lead one to over-test the simple things, but the cost of adding another "what if?" is so low - just another line - and the additional safety you get from trying a different input is rather nice. We've been using them for parsers and simple generators, where you want to throw in a bunch of inputs to a single method and see what you get out.

I'm totally sold on this feature, particularly for our type of application (the Java driver does a lot of taking stuff in one shape and turning it into something else). Just in case you want a final example, here's a final one.