… something on Code Habitability

Kevlin Henney (@KevlinHenney) talks of a property of code which means it is easy to live in:

I love the concept.

Absolutely love it.

It hits a nail on the head for where we should be aiming to be with with our codebases.

Code should be easy to navigate around, nicely organised, everything put in its place where you expect it. Changing one thing in one place should not break something elsewhere. Small parts should be easily replaced without having knock on affects to the surrounding code. You can interchange one database technology with another, or the user interface, or update the javascript framework without a major rewrite.

It should be an easy place to live.

But in trying to write a blogpost on the subject it has become apparent it is a double-edged sword…

Many a crime has been committed when the original author(s) felt too comfortable. And indeed there’s always the danger of Stockholm Syndrome, where a developer comes to love the idiosyncrasies of a codebase they’ve worked on for too long.

So if you’ve been working in the environment of a codebase for a while, is your present-self the best judge, or do you need a pair of fresh eyes to judge, or even just yourself in six months time. Like a well worn jumper, or even a child’s bedroom where everything has its place, but that place is ‘somewhere on the floor’ (As @unclebobmartin would say). The inhabitee knows exactly where things are, but that’s by keeping everything in memory; it doesn’t scale; it’s impossible to handover.

As an analogy, Psychological Safety can actually mean a degradation in standards – the environment can become too safe – leading to unethical behaviour. Similarly there is a danger that a codebase can become too comfortable, for a small number of people at least.

This leads on to the willingness to learn, develop and exchange ideas – a team of ‘Expert Beginners‘ can be self-taught, solve things by brute force, try apply well-known rules but misinterpret them, or over-apply them, or just become a cargo-cult; they not progressed to being an expert, but tell themselves they have. They’ve got stuck in an eddy current and aren’t talking to the wider community.
So Habitability can only really be judged by those not involved in the codebase on a day to day basis, or a new joiner to the team for example. There are many formal and informal guidelines to what makes code Habitable but even these need to be used in context and often in moderation.

So, in search of Technical Excellence we need to aim for Code Habitability, but it is in the Eye of the Beholder, not the Author(s).

Posted in Uncategorized | Leave a comment

… something on when refactoring is not Refactoring

Refactoring is essential to a healthy, maintainable codebase.

Refactoring is taking two fixed endpoints (the input and the output) and changing what’s in between. It’s changing how it’s implemented, not what’s implemented. The changes should be functionally invisible to a user who is viewing the system as a blackbox; which demonstrates the benefit of coding to an interface and having a clear API.

Before you refactor you should (must) have in place some tests that prove you haven’t broken anything, in fact Michael Feathers defines Legacy Code as “Code without Tests”.

It’s becoming rarer and rarer to come across code with *no* tests, though that doesn’t mean that the tests are useful or not; in extremis the tests can have been nothing more than a box-ticking exercise. Legacy Code however is not becoming rarer. So perhaps that should read “Code without useful tests”. Or meaningful, or valuable, or stable, or easily-run, or continuously run, etc.

No, Refactoring (capital R) by its nature tends to happen in the small (behind an interface). If you’re wholesale rewriting the tests as part of the ‘refactor’, actually that’s just rewriting (or possibly reworking) and not refactoring at all. Indeed, if you’re changing the interface, you’re changing the behaviour.

Much of what is meant when people talk of refactoring, isn’t.

Posted in refactoring, Software | Leave a comment

… something on the link between size of team and codebase

No software conference is complete without a reference to Conway’s Law – the communication within the organisation producing some software will be reflected in the design of that software.

Kevlin Henney (@KevlinHenney) often talks of projects where a team of ten developers would suffice, but over one hundred are used. This leads to a codebase that a hundred people can work on without disturbing each other (or, if you’re lucky, each pair). This feels like a corollary of Conway’s Law; either the one hundred developers are:

  • split into teams, ideally using the Two Pizza Rule, each responsible for a part of the system, meaning the system will be made up of as many parts as there are teams;
  • or else at worst, one big team which, by Conway’s Law will mean the codebase will be one (enormous) unstructured mess.

Don’t forget, the effort of coordination for a hundred person endeavour will not be insignificant in itself. There are 100-factorial communication paths. Teamwork is likely to be at the looser end, though there may be pockets (a team self-organises itself into existance).

In all of this time, the ten person team could have been building out incrementally something more sized appropriate to the challenge.

Kevlin also talks of Habitability: a property of code which means it is easy to live in:

It feels like a logical progression to say that developers on a long enough running project will produce enough code for them each to feel comfortable to work on individually, without stepping on one another’s toes. The equivalent of the Van der Waals force. The equivalent of each developer building a comfort zone of code around them, reducing the interaction and co-ordination costs.

Whether the amount of code is proportional to the number of developers, or whether there is a ‘discount rate’, will tell you how much the developers and their code interact with each other. The more collaboration there is the fewer lines of code there are per developer.

A team working in perfect collaboration will produce enough code to encapsulate he necessary complexity of the problem domain and no more – minimising the accidental (unnecessary) complexity to the optimum.

 

 

 

Posted in Uncategorized | Leave a comment

… something on Software not Stoneware

I’ve been using this phrase for a few years now, particularly during my series of talks on Keeping Code Agile (as I put it).

“It’s Software not Stoneware”

This came from a number of teams I had worked on that had become so risk averse that they didn’t actually want to commit any code (ie work) in case they broke the build, or product (or anything).

More recently someone joked that I was “Moving fast and breaking things”. This wasn’t actually the case, I had a change I thought was the right thing to do, but the only way to verify this was by checking it in, to see what happened in the build system (it broke). It wasn’t that I tried to do something fast, more that at some point I had to try it at all.

Over the time I was there I highlighted a number of areas where their process was extremely fragile; one build failed because it ran out of letters of the alphabet to append to the artifact name! I usually highlighted this by walking in to some bear trap of a process shortcoming.

There is a maxim in Continuous Delivery, if something (you need to do) is painful, do it more often.

It’s the same with making great software, if you don’t try to improve it, it becomes more difficult to.

Sometimes the codebase seems to ossify and no-one wants to change anything for the fear of breaking it; it has become Stoneware – Chiselled in stone tablets and handed down from developer to developer (or have they become Dusters at that point?).

But it’s called Software for a reason. You can change it and make it better. In fact that’s your job. Perhaps that gnarly bit of the codebase could be written to be clearer and even work better. Or perhaps you could even give it a try and if it doesn’t work, then the not-recent-invention of version control means you can revert it again.

Posted in Software | Tagged , | Leave a comment

… something on Refactoring for Understanding

I’ve dealt with quite a few legacy codebases in my time. And many of them I’ve pummeled in to shape over time.

The one thing I can say is that I would have never come to understand any of them by simply looking at them, merely by reading them.

Code is a static representation of what should happen in a dynamic system. Just like looking at a map can only ever give you an indication of what a location is actually like, so it is with code and what happens at execution time.

In Legacy Code it is often that the code does not adequately represent the hidden dangers of changing it. Bits of innocuous looking code over here affect unrelated looking code (through incoherency, lack of encapsulation, global state, etc) over there because of how it is wired together, or so many temporal dependencies the program is one large race condition.

A friend on my degree course was a stereotype of an Engineer in that they couldn’t resist taking everything apart (even when brand new) to see how it worked; they also tended to test everything to destruction.

This is how I gain understanding of a codebase; especially a legacy one. By doing the refactoring that needs doing anyway – breaking down methods and classes to be one level of abstraction, simplifying logic, making the code understandable – you form and increase an understanding of how the code hangs together.

This understanding furthers the improvements you can make to the code, becoming a virtual circle.

And this leads to a further point. Even if you do Refactor for Understanding, until you commit it, it’s never to late to revert it; the learning will remain even if the refactoring doesn’t.

Posted in Uncategorized | Leave a comment

… something on Rewriting or Refactoring

“Let’s just rewrite this” is a common refrain in the software industry and even newly written code can quickly come to be seen as Legacy Code. It is often seen as the easy option, but can lead to months and even years of effort to replicate a system with the same set of problems.

There are a number of reasons why a rewrite of a current solution is considered the answer to all ills. Sadly whilst some are legitimate, some of these just don’t consider the significant risks involved.

There can be imperative or legitimate reasons to rewrite; sometimes the language of a codebase can just become obsolete, unstable, insecure, or unsuitable for the purposes of the solution. Equally the recruitment of new staff to work in that language can become the bottleneck, with the skills disappearing from the market.

But sometimes it can just be a jump to a shinier technology, chasing the microservices dream or latest industry trend.

But what are the risks?

Firstly, there is the sheer amount of elapsed time to reimplement and replicate the existing set of features, and the rewrite is often not able to be released and deliver value until *all* the existing features are in place. The problem here, as witnessed first hand, is that the first deliverable becomes so large as to be unmanageable; Software Development has diseconomies of scale, as Allan Kelly says. And for all that time the original codebase must be maintained. All too often new features are required on the original in the interim, making the rewrite having to aim at a moving target.

Secondly, there is the amount of effort required, ie the sum of all the development effort on replicating something you already have. Not to mention the management time and opportunity cost of working on something else. And is the existing product or application being maintained and updated in the meantime?

Thirdly, when you consider Conway’s Law as well as technical and organisational culture, will a rewrite deliver the value anticipated or hoped for? If the organisation has produced a codebase with minimal automated testing what is to say that a new ‘Greenfield’ replacement will suddenly be developed with sufficient test coverage  or developed under Test Driven Development (TDD) methodologies?

Software produced by the same people under the same conditions is likely to have similar outcomes. The only way to break this loop is by making sure you learn from the mistakes. Was the original really as a prototype for the rewrite? or has the organisation and team failed to ensure the code, tests and pipeline were up to standard?

Fourthly, in trying to rewrite, you are in danger of having to reimplement an existing application warts and all. Suddenly bugs and workarounds have become features, and the expected behaviour is that of the existing product, not that of the original requirement. This can add significantly to the complexity of the solution, where ‘accidental’ (unnecessary) complexity introduced by the original solution has become part of the ‘necessary’ complexity of the domain.

Finally, there is significant risk that once the decision is taken, or even before, to eventually retire the existing application, the team and organisation can psychologically ‘give up’ on maintaining high standards, either deliberately or not, and the existing codebase can rapidly degrade. Problems are not fixed or addressed, and worse, new work is done in a more slapdash manner, with the result of a death-spiral.

But what if the time and effort you were going to spend on rewriting was spent on taking the existing system in hand? It’s Software not Stoneware™ after all; teams can become afraid to change the code leading to ossification and a loss of working understanding of the code.

So what are the alternatives?

Well that depends on the motivation for the rewrite.

If it is to update the UI, then moving the existing backend to a rest server and ‘skinning’ the application with that afternoon’s hottest javascript framework might suffice. The rest of the application may be heavily affected if the original architecture did not separate the presentation layer from the business logic and other workings. This highlights the importance of using APIs to decouple the application’s architecture.

If it is the lack of testing, then starting to introduce tests over time may be a more profitable approach, as described in Michael Feathers’ Working Effectively with Legacy Code. As the level of automated testing progresses the more the codebase can be improved so that it is also more testable, and ultimately enables refactoring of the existing codebase.

With poor code quality or architecture, then a conscious evolution of the codebase over time can be more productive, using techniques from Michael Feathers book. Sometimes instead of wringing hands over the quality of the codebase it comes down to getting out there and fixing it.

Whilst a Move Slowly and Fix Things is usually the correct approach, when a legacy system needs re-architecting there sometimes needs to be some creative destruction to get from A to B; you can’t make an omelette without breaking eggs. After all, the architecture is often defined as the things that are hard to change.

Regardless of everything else, if the principles of Continuous Delivery are applied to the existing system much can be achieved: having a build pipeline, single click deployment, database automation (ahem). Modularisation, introducing strong, clean APIs, decoupling of components, updating and wrapping of dependencies all improve the structure of the code, and your ability to understand, maintain, extend and change it.

Separating out the state from the operation of business logic can be essential to allow reasoning about the state whilst refactoring to immutability can bring clarity to thinking.

I myself have used different approaches in different projects, to resurrect codebases and deliver value, without throwing the baby out with the bath water. Please do relate your own experiences in the comment.

It’s amazing what you can achieve with the existing codebase. And often it can be done with less effort than employing a full rewrite.

Rewriting can sometimes be the correct decision, but it is not risk-free as sometimes presented.

Posted in Uncategorized | Leave a comment

… something on Code as Content

One of the great things about going to a conference, or at least the ones Itry to go to, is the melting pot of ideas. To get this, you need to be at ones that have a mix of big names, thought leaders, but also all the way through to first time speakers who come with differentt ideas and perspectives.

Agile in the City: Bristol, along with its sister conferences, and independent ones like Agile On The Beach and SwanseaCon (Which I’ve not made it to, yet) are just such conferences.

I’ve already written one post on The Sunk Debt Fallacy, and this one came from a similar blend of long-running trains of thoughts and comments.

So, for the background, Kevlin Henney in his The Seven Ineffective Habits of Many Developers talk provides a compelling argument for why, even with widescreen monitors, code should be limited to 60-80 characters per line. And uses an anecdote about how sometimes the end of certain lines could end up in a different timezone.

Before this I was in the ‘longer line’ camp, but found the arguments compelling.

Then, at Agile in the City: Bristol, Kevlin ran a Technical Excellence workshop, examining what we mean by Technical Excellence and how that might be sold to different parts of the organisation. The point was made that the Agile Manifesto (written as I now know, in the Continuous Present tense) *does* mention Technical Excellence, just that it is on page 2.

In discussing presentation of code, the comment was made about “what if this had to fit on a webpage or app – scrolling to the right is not an option. Due to time pressures this comment was not picked up and we moved on.

During the keynote the following morning, Sophie Dennis was discussing strategy, and touched on honing a strategy by getting a content manager on board to “get rid of waffle” and how to present it as a webpage.

The two things clicked in my mind, this is about presenting both a Strategy and Code in the most accessible way. And applying modern UX/UI/content principles to the two problems.

Or are they the same problem?

Too much time is wasted in developer circles arguing whether brackets should be on one line or the next. A common idea is to split the content from the presentation. So why not for code itself.

Why not have the code stored and use design thinking to present it in the most readable way possible? After all, a common practice these days is to do code reviews in a web browser as part of a Pull Request.

And as for “getting rid of waffle”, that’s certainly something I can sign up for in code.

 

Posted in Uncategorized | Leave a comment

… something on the Sunk Debt Fallacy

So I’m writing this at Agile in the City: Bristol, and I’ve just read Allan Kelly‘s very interesting and short book on Project Myopia (https://leanpub.com/myopia).

In it he discusses how the use of the term Technical Debt in front of Business people might not have the effect we want (or expected). Basically, using debt to fund a business (even on an ongoing basis) is seen a *good* thing – it’s called leverage. It’s not like household finances where you build up a debt and then pay it off again as soon as possible.

Allan Kelly proposes the term Technical Liability instead, to have the impact intended.

Allan Kelly also describes how when working within a Project model each one always wants the shortest path to get something working. No Project wants to be lumbered with the upfront cost of dealing with any Technical Liability, even though it might well be slowing each and every project down. So the Liability never gets reduced.

You aren’t necessarily aware that Technical Liability is slowing you down – it can very much creep up on you like the proverbial lobster in a pot. The water temperature rises without the lobster realising it. Technical Liability can accumulate until it suddenly kills a product. Also be clear, developers leave companies because of the state of the codebase they are required to work on.

There was also Lightning Talk on how every product these days was started from a Minimum Viable Product, where the only concern was how many corners can we cut to get something out there. Then afterwards there is no intention of tidying the mess made.

Then, during Kevlin Henney‘s workshop on Technical Excellence, whilst discussing very similar things, a thought occurred to me.

The Sunk Cost Fallacy (https://en.wikipedia.org/wiki/Sunk_cost) is essentially keeping (hanging on) or using something just because it has already been paid for. In software it often exhibits itself as continuing an approach even when it has been shown and is known to be wrong. The answer to this is often expressed as “It’s never too late to stop going down the wrong road”.

All of these things have made me think of coining the phrase:

“The Sunk Debt Fallacy”

All too often the attitude is taken that the Technical Debt is already there so it may as well stay there. There’s no point in fixing it. It will take too long. We’ve already accumulated, and after all – Debt is good, right?

I’m not saying that in every case it is uneconomic to fix all the problems, but if the product or application is an ongoing concern then it is essential.

I’m also not convinced that every decision to rewrite a product (because of the Technical Debt/Liability built up) is the right one. If the rewrite is written in the same circumstances as the existing, you are likely to have the same problems again.

Posted in Uncategorized | Leave a comment

… something on Failing

Everyone Fails.

I well remember my Dad telling me on one occasion “A man who never made a mistake, never made anything”. So I can usually embrace making a mistake, failing and learning from it. I do my best to be honest about mistakes, this promotes transparency, and to my mind is essential to an effective team.

But just rarely does it feel really painful. This can be because either you don’t know what you did wrong, so can’t learn. Or it can be because you feel you’ve been unfairly blamed for something. Or possibly disempowered or undermined in your efforts.

I failed recently. I don’t regret giving the endeavour a try in the first place, but this failure was painful. And it is still raw.

I hope to be able to write about it, but for now, I’m sore.

 

Posted in Uncategorized | Leave a comment

… something on the Dysfunctional Standup Game

Recently Cambridge Agile Exchange (CAE, @Cam_Agile_xchg) asked for volunteers to run ‘Agile Games’ for one of their regular meetings.

Having seen Mark Dalgarno (@markdalgarno, who’d presented at the previous CAE) run a game based on Dysfunctional Standups a few times, I couldn’t resist the chance to share it with a new audience; the results are usually hilarious.

I asked Mark if there was anyone I needed to credit for the game, and he said whilst he had a feeling he hadn’t invented it, he would appreciate the citation; I also know Joh Hunt (@joh) has been involved. The game is really an example of one of Mark’s favourite devices, the ‘Anti-problem’; what would the world’s worst standup look-like? By trying to identify this, you can often learn what a good standup might look like. Mark has even delivered a Lightning Talk called ‘The Worst Lightning Talk in the World’.

The game itself is a simple ‘improv game’, where you get a volunteer/nominee/press-ganged person to be the ScrumMaster and they have to (try to) run a normal daily standup meeting. What they do (or don’t) know is that you’ve given each (pretend) team-member a ‘behaviour’ to exhibit during the standup. An extra element can be for the ScrumMaster (or crowd) to guess what the behaviour is, either at the end or during the course of the game to ‘eliminate’ them.

The behaviours are down to the imagination of the person running the game and can include anything (decent, inclusive and not offensive I suggest). Not wanting to give an exhaustive list, but just someone who mumbles inaudibly, talks about nothing but the weekend, or spends the standup on their phone, to the person that immediately leaves the room when the standup starts.

They can be all the normal ways a standup can go wrong, and some may feel extreme examples (‘no one would ever do that, would they?’), but then you meet people who have encountered the behaviour in real life.

My best real-life example was someone who was never in the room at the time the standup should have started, but their phone was, with the alarm going off to tell him it was standup time. Every day.  I jest not.

The game is good for ice-breaking, but should always be followed up by a short discussion on learning points, observations. Hey – it’s almost like having a retrospective on it.

There is a long-standing ambition to produce a pack of ‘cards’ with a set of ‘behaviours’ on to pre-pack the game; who knows, this may have spurred me (amongst others) further down that road.

Watch this space.

Posted in Uncategorized | 1 Comment