もっとミカドを

The Mikado Method: A Framework for Manageable Refactoring

Have you ever worked on a large refactoring project, library switch, or upgrade that ended up taking weeks or even months to complete? If so, you know the challenges of managing conflicts, fixing bugs, and ensuring performance changes. In such cases, the risk of reverting and abandoning the project altogether is high. But what if there was a framework that could make these types of refactoring projects more manageable?

Enter The Mikado Method, a framework that advocates for splitting complex changes into atomic ones that can be shipped independently. Although not widely known, this method has the potential to revolutionize the way programmers approach refactoring. In this blog post, we will explore the key principles of The Mikado Method and how it can be applied in everyday programming.

Understanding The Mikado Method

The Mikado Method is a framework that emphasizes breaking down large changes into smaller, atomic ones. The idea is to create a visual representation of the project’s tasks and their dependencies, similar to a tree structure. Each task is represented by a rectangle or circle, and the dependencies between tasks are linked together.

Let’s take the example of upgrading a Ruby on Rails application from version 4 to version 7. The first step is to locally upgrade the Rails dependency in the Gemfile. This task is represented by a rectangle, with the description “Upgrade Rails in Gemfile”.

Next, run the unit test suite and identify the failures that occur due to the upgrade. For each failure, create a new rectangle on the paper and describe the necessary steps to fix the issue. If the cause of the failure is unknown, write down the failure itself for further investigation. Link each rectangle to the parent one to visualize the dependencies.

Once you have identified all the failures, revert your changes completely. This means deleting everything related to the upgrade, not just creating a new branch or squashing commits. If the change took too long to revert, it indicates that it wasn’t atomic enough and needs to be split into smaller tasks.

Now, pick one of the failures and try to fix it in the current codebase without the original upgrade. If fixing the problem requires additional refactoring or changes, write them down on the paper, delete everything, and start implementing them. If there are still failures after fixing the initial problem, write them down, link them to the issue you were trying to fix, and delete everything again.

Continue this iterative process for every failure, refactoring, or change that is needed. If you discover a new issue during the process, write it down and delete everything. The goal is to gradually accumulate actual fixes and reduce the number of reverts.

Eventually, you will reach a point where you have a fix that works and passes all the tests. Ship that change and move on to the next failure. With each iteration, you will have more actual fixes and fewer reverts. Finally, when all the necessary changes have been made, you can make the final change to upgrade the dependency version in the Gemfile.

The Benefits of The Mikado Method

The Mikado Method offers several benefits for managing refactoring projects:

  • Manageability: By breaking down complex changes into atomic tasks, the method makes the overall project more manageable. It allows developers to focus on one task at a time, reducing the risk of getting overwhelmed or losing track of dependencies.
  • Safety: The method encourages shipping atomic changes independently. This means that if a change introduces unexpected performance changes or bugs, it can be easily reverted without affecting other parts of the project.
  • Reliability: By shipping atomic changes, developers can test and validate each change individually. This reduces the risk of shipping a large change that contains unrelated or untested code.
  • Flexibility: While it’s important to understand and follow the core principles of The Mikado Method, it’s also essential to adapt it to your own needs and project requirements. The method provides a framework that can be customized and tailored to fit different scenarios.

Applying The Mikado Method in Practice

Although The Mikado Method may not be followed to the letter by everyone, its core ideas and goals can be applied in everyday programming. Here are some practical tips for incorporating The Mikado Method into your workflow:

  • Splitting Changes: Split every task into the smallest possible atomic change. This allows for easier testing, validation, and independent shipping of each change.
  • Avoid Unrelated Changes: When working on a specific task, avoid making unrelated changes in the same codebase. Take note of other changes that need to be made and come back to them once the original task is ready for review.
  • Commit Atomic Changes: Make a habit of committing atomic changes frequently. This ensures that each change has a green local test run and reduces the risk of losing progress in case of a revert.
  • Don’t Be Afraid to Start Fresh: If you find yourself stuck in a fix that seems daunting, consider deleting everything and starting from scratch. This psychological reset can often lead to better and quicker solutions.

By incorporating these principles into your workflow, you can improve the reliability and safety of your code changes, whether they are small bug fixes or large-scale refactorings.

Conclusion

The Mikado Method offers a fresh perspective on managing refactoring projects. By breaking down complex changes into atomic tasks and shipping them independently, developers can mitigate risks, improve reliability, and increase the manageability of their projects. While not everyone may follow the method to the letter, understanding its core principles and adapting them to individual needs can make anyone a better developer.

Have you tried applying The Mikado Method to a large project? Share your experiences and insights in the comments below!

注意

  • この記事はAI(gpt-3.5-turbo)によって自動生成されたものです。
  • この記事はHackerNewsに掲載された下記の記事を元に作成されています。
    A Plea for More Mikado
  • 自動生成された記事の内容に問題があると思われる場合にはコメント欄にてご連絡ください。

コメントする