Summaries > Technology > Rails > Modularizing Rails Monoliths One Bit...

Modularizing Rails Monoliths One Bite At A Time By Marc Reynolds

TLDR Restructuring code into packages, declaring dependencies, and maintaining public interfaces are crucial steps in addressing 'spaghetti code.' The conversation emphasized using tools like Packwerk for static code analysis to enforce boundaries and ensure modularization. It also highlighted the challenges in identifying privacy violations, resolving complex dependencies, and maintaining documentation for long-term efficiency and sustainability.

Key Insights

Addressing Spaghetti Code: Utilize Packwerk for Modularization

In dealing with spaghetti code, the use of tools like Packwerk can bring significant benefits to software development. Packwerk, a static code analysis tool, enforces code boundaries and helps in modularization, leading to clearer code ownership and increased efficiency. By integrating Packwerk into the CI pipeline, privacy violations can be detected, eliminating the need for manual code reviews for every PR.

Restructuring Code: Align with Business Perspective and Declare Dependencies

To effectively restructure code into packages and declare dependencies, it's crucial to align the code structure with the business's perspective. Utilizing event storming to plan and name feature sets can aid in this process. Moving classes into packages, eliminating unused code, and utilizing YAML files for declaring dependencies and adding metadata to files are essential steps in this phase.

Creating Stable Public Interfaces: Avoid Privacy Violations and Complex Dependencies

Phase three involves making hard decisions, identifying privacy violations, and creating stable public interfaces for other packages to use. It is essential to use heavily commented public interfaces, avoid leaking private methods or classes through return types, and utilize plain old Ruby objects instead of exposing Active Record objects. Furthermore, categorizing packages into infrastructure, common tooling, and feature sets can aid in resolving complex dependencies.

Managing Code Reviews: Maintain Public Interfaces and Listen to Feedback

Using automated tools to manage code reviews and detect issues like privacy violations and circular dependencies is crucial for maintaining a clean and efficient codebase. Additionally, maintaining public interfaces, keeping documentation up to date, and actively listening to feedback, including from support teams, are vital aspects of effective code management and improvement. Emphasizing the importance of enjoying the development process and striving for clarity in the code base, the speaker advocated a phased approach and reiterated the goal of building software that solves hard problems.

Questions & Answers

What are the challenges of dealing with 'spaghetti code' in software development?

The challenges include confusion and inefficiency in software development.

What is Packwerk and how does it help in software development?

Packwerk is a static code analysis tool that enforces code boundaries and helps in modularization. It can be integrated into the CI pipeline to avoid manual code reviews for every PR and to detect privacy violations.

What are the phases of addressing spaghetti code?

The phases include examining features, organizing files into packages, defining package dependencies, and maintaining the codebase to ensure long-term efficiency and sustainability.

What is the importance of aligning code structure with the business's perspective?

Aligning code structure with the business's perspective is important for planning and naming feature sets, as well as for moving classes into packages and eliminating unused code.

What does phase three of addressing spaghetti code involve?

Phase three involves making hard decisions, identifying privacy violations, creating stable public interfaces, and using heavily commented public interfaces.

What are the important considerations for managing code reviews and detecting issues in software development?

Using automated tools to manage code reviews, maintaining public interfaces, and actively listening to feedback from support teams are important considerations.

Summary of Timestamps

The conversation discussed the challenges of dealing with 'spaghetti code' and its impact on software development.
The speaker shared their experience of building a new rails microservice and how it eventually became difficult to work with due to bloated controllers and models.
The discussion then focused on Packwerk, a static code analysis tool that enforces code boundaries and helps in modularization.
The conversation primarily focused on the process of restructuring code into packages and declaring dependencies.
Phase three involves making hard decisions, identifying privacy violations, and creating stable public interfaces for other packages to use.
The speaker discussed the importance of using automated tools to manage code reviews and detect issues like privacy violations and circular dependencies.
They emphasized the need to maintain public interfaces and have conversations about the usefulness of abstractions and domain models.
The speaker stressed the importance of enjoying the development process and not giving up on achieving clarity in the code base.

Related Summaries