Published on November 25, 2018
Author Emily Bache
Notice: This post is more than a year old. Some of the content might be outdated.

Advanced Testing & Refactoring Techniques

Lift-Up Conditional

When you inherit difficult code it can take weeks to become productive. I’d like to show you the difference it can make when you have the right tools for the job and know how to use them.

Once you’ve got good tests in place you can refactor much more confidently. In my previous post I showed how to get good tests using Approval Testing. I’m pretty confident in these tests, so I’ve made a second video showing some initial refactorings I’d do to get this code cleaned up a little.

One of the techniques I’m using is called ‘Lift-Up Conditional’. It’s a manipulation of a long complex conditional statement that will let you group together all the statements related to one particular conditional. I haven’t seen this particular refactoring described in the literature before - it was Llewellyn Falco who showed it to me originally. It’s perfect for the Gilded Rose code which basically comprises one big complex conditional.

The other star of this show is IntelliJ. It has a lot of automated refactorings that come together to make ‘Lift-Up Conditional’ easy and it makes really short work of cleaning up this code.

This is the second screencast in the series. My aim is to show that with the right tools and refactoring know-how you can quickly become productive with the code, even without fully understanding the byzantine business rules.


Part 2: Refactoring item logic using ‘lift up conditional’


This is a trilogy. See the first blog and video and the third one


Related Stories

Related Stories

×

Testing

Succeeding with Continuous Delivery takes hard work, and not least, great testing.

Get started with Serverless Jenkins X

A crash course in Jenkins X and how to test it out on a local Kubernetes cluster