Monday, 12 September 2016

New and Shiny Things

There is risk with upgrading anything, be it language, framework, library, OS or third parties.

In the past I was rather gung-ho about upgrading. New version out? We need it. In fact, this need is often a want. The new version often seems better. Developers seem addicted to the latest and greatest.

One of the best, but also one of the worst problems with software development is weekly there is something new to use or try. Keeping pace is impossible.

Internet Echo Chamber Effect

If you look at a news article on the release of something, you feel as if you are the only person not using it. Everyone is is using it, we need to as well.

In fact this is quite the opposite case. A site about the latest web framework will seem as if everyone is using the framework apart from yourself. This is known as the Internet Echo Chamber Effect.

Wait for a Patch

Wise advice I received and saw others follow was the minor or patch adoption. If version 2 comes out, wait for 2.1. Let others find the issues and wait for the version to stabilize. If you really must use version 2, use it in a low risk way. Personal projects or in house solutions make sense. You can keep pace but reduce risk in this manner.

Boring but Stable

Another approach is to take widely used, stable solutions. Avoiding anything new or cutting edge except for personal projects or internal projects.

If your job is to write software to sell widgets, focus solely on that, what you use behind the scenes really doesn't matter. As long as you can delivery value and aid the sale of widgets you're on track for success.

A similar alternative is to use boring solutions for anything that has high risk. While using newer, more exciting solutions for low risk projects. Again risk is managed and reduced. If the new, cutting edge solution becomes the norm, eventually you can adopt this in the future.

A younger, less experienced self would not find this advice at all appealing. After all if the tests pass why can't you upgrade to the latest and greatest? The main issue is risk, which will be the subject of a future post. Every single change, be it a single line of code has risk.

The one exception to this advice is security concerns. If a security release is available you should aim to upgrade as soon as possible. Usually such releases form minor releases, meaning risk is low and matches the delayed upgrade path above.


  • Any change has risk.
  • Reduce risk when handling new technology.
  • Either use stable versions or boring solutions.
  • Play and test new technology on the side, in low risk scenarios.
  • What technology you use to build something actually doesn't matter in most cases.

Wednesday, 31 August 2016

Past Mistakes - ORMs and Bounded Contexts

Sticking with the theme of documenting past mistakes, it's worth expanding a real life scenario where I was unaware of the use of bounded contexts and fully understanding the tools you use.

Ignoring a Bounded Context

A fellow developer set upon a quest to rid numerous projects of duplicated records, which was effectively the active record pattern. This was a huge under taking split across hundreds of thousands of lines of code, over numerous separate projects. Close to completing the task I assisted and finally the shared library containing a single record for each type was complete. Each project now referenced the shared copy. This was versioned as each build was completed.

For a while this worked with no problems. It certainly felt nice to see the reduction in duplicated code. Sadly sometime later myself and another developer made a seemingly innocent change. In terms of relation, the change was as far removed from the production error that we had just been alerted to was. There was no link. It was a different project, in a different path, on a different model. The only commonality was the fact the issue only occurred after the previous deploy.

ORMs and Changes

Several minutes of panic later, the problem was spotted. While the model we had changed had no direct relation, indirectly there was. As each record was loaded by the ORM in question, links and dependencies where also loaded or checked. So were the children's links and dependencies. Finally this would hit the newly changed record. Due to the database changing ahead of the library, numerous other projects now had a runtime error. As we naively believed we were only working within a single project, we deployed the changes within the one project. As the library was shared, all other projects were now vulnerable.

This lack of bounded context, and focusing on removal of duplication was not the only lesson here. This issue painfully highlighted the need and importance to know exactly what your tools are doing, especially when they are hidden behind the scenes. In fact, my use of ORMs other than micro-ORMs is next to non existent at present.


  • Use bounded contexts.
  • Favour loose coupling, over reduced duplication.
  • Anything shared must be deployed and tested as a single unit, otherwise remove the shared component.
  • ORMs (or other tools) should be understand and respected.

Wednesday, 24 August 2016

Test Your Live System using Live Service Tests

Traditionally there are three categories of functional tests.

  • Acceptance
  • Integration
  • Unit

This is often refereed to as the testing pyramid. Unit tests form the bulk of your suite, followed by a smaller subset of integration tests. Acceptance tests that cover features should be the tip of your testing strategy, few in number. These are great but there is a missing suite of tests - live service tests.

  • Live Service Tests
  • Acceptance
  • Integration
  • Unit

Live Service Tests.

The role of live service tests (LST) is to test the live system against the production environment and configuration. LST would be fewer in number than acceptance tests. Unlike acceptance tests, these should run constantly. Once a run has completed, kick of a new test run. This will require a dedicated machine or piece of infrastructure, but the value provided is well worth it.

LST should focus on journeys instead of functionality or features. In contrast to acceptance tests a user journey would be the core purpose of the system. For example, a LST suite to cover this blog would ensure the home page loads, an individual post can be loaded, and the archive is accessible. The rest of the site such as comments or social media interactions could be broken, but the core purpose of the system is working. Readers can read and browse the blog. If at any time the tests detect a failure in the core journey there is a big problem.


LST offer the fastest feedback possible due to the fact they are constantly running. It is far more desirable to detect a problem before your users do. Naturally LST offer great protection after deploys. Deployment of new code is one of the times you are more likely to encounter issues, so a suite of tests triggered after a deployment is a natural fit. LST also protect against unplanned events. In my experience, exceeding disk space, DNS failure, third party issues and more have all be detected.

How To

Adding another suite of tests may sound like increased effort but the cost associated with LST is rather low. Sometimes acceptance tests can be run as LST, meaning no extra effort. Care must be taken here if the tests perform anything destructive or anything that interacts with third parties.

Alternatively writing LST is simpler than standard acceptance tests. The same tooling can be used such as Selenium, NUnit and so forth. As the tests themselves focus on journeys rather than functionality, the tests are often less complex to write.

The only difficulty LST introduce is the fact they are executing against the live system. Consider interactions with a third party. Using a real account on the real system may be problematic. One way to get around this issue is to embed test functionality within the system itself. For example you could set up a test account which the tests use. Instead of executing against the third party system, the dummy account is used. Likewise most third parties have test accounts which can be setup and used instead.

LST are a nice compliant to a diagnostic dashboard. If your dash is reporting no issues, and your tests are green, you can be confident the system is operating in a good enough state.


  • Functional tests are not enough.
  • Use live service tests to test the real production system.
  • Run live service tests constantly for the earliest feedback possible.
  • Alter production code to introduce test functionality.
  • Make use of test accounts and anything else that third parties may offer.

Thursday, 4 August 2016

Why You Should Do Code Katas

Code katas are simple exercises that are meant to be repeated. They are great for learning a new language or tool. The goal is to learn something, not to complete them. In fact, if you don't finish a kata that is perfectly normal as long as you take something away. The beauty of code katas is they are small enough to be repeated and possibly completed within small time slots.


Beginner or expert there will be something you can learn or take away. Beginners should take away language skills, tooling tricks and more. This is furthered when pair programming.

Experts should be inclined to try new solutions rather than rinse repeat. Instead of solving the problem in the manner you do 9-5, try something completely new. Solving a kata ten times the same way is a waste. Instead solve it once, ten different ways. In short, experiment in code katas, not your production code.

Going Further

Sadly a small minority seem such simple exercises as below them. No one is above doing a kata. Constant improvement or training is essential regardless of level. Katas alone are not enough to support personal development. Experience, reading and practical development are all still required. However when code katas are combined they are an excellent aid.

Sunday, 31 July 2016

I Need to Stop Misusing Divs

I a certainly not a skilled or expert front end developer. While I'm more than capable of creating pages I lack any design magic to make them look half decent. Despite this one area where improvement can be made is in my markup itself.

Over the past few months I've spent most of my time getting to grips with recent additions and changes in the HTML5 and CSS3 space. During this one area stood out, my misuse of the division element or <div>.

Before the addition of the newer elements pages nested with div after div was normal. However this is no longer the case. From this point onwards I will be ensuring that every time I introduce a div element I question whether a more appropriate element should be used.

The HTML div element (or HTML Document Division Element) is the generic container for flow content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang. It should be used only when no other semantic element (such as article or nav) is appropriate.

Semantic Meaning

Two huge side effects that are often overlooked when ignoring semantic markup is device compatibility with screen readers or other input methods and future proofing content.

Many people wrongly assume that all users are either keyboard/mouse or mobile (touch) users. By using semantic elements, users of other input methods get a much smoother experience. It is possible to jump to navigation or content without having to page through dozens of unrelated sections added only for stylistic purposes. Having used such devices first hand, the joy such simple changes make are outstanding.

Using semantic elements also helps future proof content. Screen scraping and other technologies can be simplified massively if content is correctly marked up. The thought that pages of content written now will still be used and accessible decades from now is incredible.


The lesson here is an easy one. Every time you write a generic division element, stop and ask yourself is there an element with more semantic meaning that will do the same job?