Taming Complexity in Ruby with Flog

Rafael A. George Duval
2 min readJan 6, 2023

--

Every sizable system will contain a large amount of logic and complexity. The primary goal in managing such complexity is to organize it so that a developer knows where to look to find things and needs only understand the directly affected complexity at any given time.

While rework in the manufacturing metaphor leads to cost, rework in design leads to value. Software work and making software clean are two very different activities. The problem is that too many of us think we are done once the program works. We need to switch to the other concern of organization and cleanliness. We move on to the next problem rather than going back and breaking the overstuffed classes into decoupled units with single responsibilities.

Maintaining separation of concerns is just as crucial in our programming activities as in our programs. You keep software soft by leaving as many options open as possible.

The options that need to be opened are the things that support the application. Everything unrelated to the Business is considered implementation or technical details. Technical details are separate from the Business. They will change at rates and for reasons that are independent of other aspects of the system.

There’s a lot of code out there with nasty conditionals. The tendency is often to go into excessive preferences about how the code should be structured.

Ruby’s Flog

Flog is a complexity metric. A metric is a crowdsourced idea about something. Flog is an ABC metric; it scores assignments, branches, and conditionals. It counts things and adds them up.

Higher scores are worse. Higher scores state a more complex code that will be harder to understand and reason. Flog is an excellent starting point for discussing complexity in a code base.

Replacing conditionals with small objects could be more explicit. Tools like “Flog” identify the where and the why. Reduce the cost of changing complex code by measuring it before tackling it.

[¹]: Robert Martin(2008): (Clean Code: A Handbook of Agile Software Craftsmanship)

--

--

Rafael A. George Duval
Rafael A. George Duval

Written by Rafael A. George Duval

✍🏼 Building a Solo Digital Media Company 🧪 Snippets of Text [https://snippetsoftext.substack.com/subscribe]

No responses yet