Masterclass

Refactoring to Immutability

About

Delivered across 2 days, this workshop is for developers looking to improve their software designs by better managing state and removing mutability.

It has been said that immutability changes everything. But what does that mean in practice? What does it mean for existing code that looks more like the mutant apocalypse than an elegant application of mathematical thinking? Mainstream programming languages are normally grounded in imperative styles — from updating local variables to updating records in databases. But although they have grown from imperative roots, languages such as C# and Java are expressive and evolved enough that they can embrace many different approaches. Indeed, trends in the development of many languages have made immutability and the reduction of mutability easier to support.

Immutability is attractive because it makes code easier to reason about, reduces the possibility of many classes of bug, improves the testability of code, reduces the amount of validation and error-handling code, makes code more scalable when threaded and makes code more thread-safe. However, immutability can be an ideal that is hard to reach, and much advice doesn’t cover enough of the situations developers find in their codebases. Refactoring, on the other hand, is all about the art of the possible.

Whether you’re working in the cloud or on the desktop, in the mobile space or on the web, steering your code and design style towards immutability offers both short-term and long-term practical benefits. In this hands-on training, we’ll be looking at guidance and practice to help reduce the mutability of state in your codebase.

Course contents

  1. Understand the benefits of reducing or eliminating mutability of state in code
  2. Put these patterns into practice in test-based refactoring hands-on exercises
  3. Appreciate how to write new code in a less mutable style
  4. Learn patterns for transforming common and less common coding idioms to a less mutable style
  5. Identify when and when not to refactor existing code

Target audience and prerequisites

This workshop is tailored for Java and C# developers looking to write better, safer code. The class is delivered over 2 days, and class size is limited to 12 people. You will require:

  • A good internet connection
  • Practical knowledge of C# or Java
  • Some experience of unit testing, ideally in NUnit or JUnit
  • You don’t need to worry about IDEs, editors, compilers and all that as the hands-on exercises will be run online in a browser
1
 - 2 November 2022