Cursed Code Pilot: Refactoring Base Classes

Watch the screencast

In the pilot episode of my new “Cursed Code” series, I dive into the depths of Ruby code submissions to refactor and discuss best practices. This test-run episode tackles the age-old dilemma of naming abstract base classes.

The Cursed Code

The code in question features an abstract base class aptly named Base. While this naming convention might seem innocuous at first glance, it can lead to confusion and potential naming conflicts, especially in larger codebases.

class Base
  # ...

During the video, I explore the rationale behind this naming choice and propose alternative approaches that can improve code clarity and maintainability.

The Refactoring

One of the key refactoring techniques demonstrated in this episode is the power of composition over inheritance. By breaking down the inheritance relationship between Base and its subclasses, we make the code more flexible and resistant to changes in the base class.

This approach not only avoids the potential naming conflicts but also promotes better separation of concerns and easier testability.

Get Involved

If you have your own “cursed” Ruby code that you’d like me to refactor and discuss on a future episode, head over to the Cursed Code GitHub repository and submit your code. I’m always on the lookout for interesting and challenging code samples to dissect and improve.

Don’t forget to check out the pilot episode on YouTube to see the refactoring process in action and learn more about the “Cursed Code” series.

Stay tuned for more cursed code adventures! ​​​​​​​​​​​​​​​​

Written by

Photo of Gavin Morrice
Gavin Morrice

Software engineer based in Scotland

Work with me

Need help with some code?

In my free time, I like to help people improve their code and skills on Codementor.
Contact me on Codementor