Advantages to modularization in iOS

We’ve already talked about what modularization is, and why a team might want to architect their codebase in such a way. But what are the real life advantages to having multiple units of code to work in? Lets take a look.

Portable

As touched on previously, modules that are loosely coupled to other modules in the codebase are considered highly portable (at least when moving to another Apple related project). Portability is the measure in how easily we can transfer a portion of code from one codebase to another. Meaning a highly portable module that contains a lot of logic could be bought into another project that utilizes the same logic. For example, if you’re at a company working on lots of projects, having a sharable module that contains your networking code could be a huge benefit when considering the alternative of having to rewrite your networking stack each time.

Less toe stepping

Oh the woes of merge conflicts. Merge conflicts are a big annoyance, even on smaller teams. Teams that are all working on a single codebase have felt the pain of wanting to merge your work into main, only to be stung by having to deal with a heap of merge conflicts. These merge conflicts can add additional risk to project, with the uncertainty of knowing if you’ve resolved the merge conflicts correctly, particularly in a codebase without a reliable test suite.

Modularity in a codebase isn’t going to resolve all of the issues with merge conflicts, but it does a decent job at reducing the amount you’re impacted by them. In a project where you’re able to divide the work up in a way that means each team takes ownership of separate modules (or at least, fewer people are working in the module you’re in), you’re able to avoid stepping on the toes of others, and reduce the chances of a nasty merge conflict.

Decreases in build time

Re-compiling is quicker

This is a two fold thing. The first portion of this is that Xcode will only need to recompile the modules with changes in it when doing an incremental build. So if your piece of work only touches the settings screen, which is contained within its own module, then Xcode won’t need to build the code backing the login page.

The other, and arguably more important point is…

Sample Apps

We’ll get onto modularization strategy in later blog posts, but for the time being, if you imagine a world where you have a module dedicated to the login screen. Assume that login module is very autonomous, and handles all of the use cases that a login feature could have.

What this means is you can build a sample app that includes that login module, allowing it to run on its own, without the cruft of the rest of the codebase having to launch, as you’re launching an entirely separate app.

This also gives you the flexibility of writing UI tests against this sample app. A complex topic that we’ll dive into more in a later post, but it is an option that opens up and may allow for less brittle UI tests.

Happier developers

Nicole Forsgren, Jez Humble, and Gene Kim are the trio behind the annual "The State of DevOps Report". The 2022 installment can be found here. These reports, along with their breakdown of the research in their seminal "Accelerate" book, touch on how a loosely coupled architecture can be one of the tools used to create a healthier work environment.

Their research states that a loosely coupled architecture is one of the tools that directly improves Continuous Delivery performance. Having modules with a clearly defined scope, means that making changes to those module become more manageable. More manageable changes mean there is a reduction in stress when it comes to maintaining those modules as you’re more confident in the changes you’re making. The reduction in stress that comes from being a high performing software delivery team is a tangible, measurable metric when it comes to workplace culture.

(As an aside, I put my full recommendation behind their "Accelerate" book, really incredible bit of work).

In Summary

The one thing all of these things share in common is the ability to save the team time. One of the first questions around a modular codebase that is often asked is "Is it worth the effort?". And whilst there is no doubt there is a time expenditure required to work towards a modular architecture, particularly if coming from a monolithic codebase, the pay off in time saved in the long run is clear.

Plus, a potential for a reduction in stress when used with other Continuous Delivery tools, who can refuse that?

  • The Double Edged Sword: Apple Music and Dolby Atmos

    A month or so back I bought “Dark Side of The Moon” on Blu-Ray to finally listen to the Atmos remix and – not to mince words her – it was revelatory. Maybe the most…

  • ImageSequencer – Build a video from a collection of images in iOS/macOS/tvOS

    I’ve been working on Lapsey – an app to make beautiful timelapse’s with – and whilst I won’t be open-sourcing the entire project, I am trying to open-source various components in the app that feel…

  • Get all available cameras in iOS using AVCaptureDevice.DiscoverySession

    I’m working on an iOS project that required finding all of the users available cameras on their device. This used to be simple enough prior to iOS 10, as you could just call: This would…

  • Examples of Use Cases in Swift

    In the last post we went over what use cases are in software development and how they can be used in iOS development. We also went over their origin as a requirements gathering technique for…

  • Use Cases in iOS Development

    Use cases have historically been a somewhat confusing topic to venture into for me personally, and I’m now of the believe that is because they typically have a couple of definitions, depending on who you’re…

  • UML Diagrams with PlantUML and SwiftPlantUML

    PlantUML is an open-source tool used to produce an assortment of diagrams using text. With other diagramming tools, the paradigm is typically a GUI and some dragging and dropping of various objects to build up…

  • Camera for iOS – A Swift Package

    Currently preparing a large post going over Clean Architecture in iOS and how that relates to modularization, but whilst that is in the making, I figured I’d post about my newly released Camera framework, and…

  • Feature Modularization in iOS

    So you’ve decided a loosely coupled, highly cohesive, modular architecture with well defined boundaries, is the approach you want to take with your project. Now its time to go over how to deal with separating…

  • Module Boundaries in iOS

    We’ve talked about what modularization is, and what its advantages are when used in a decoupled, cohesive way. It feels only reasonable that we should dig into the meat of what a modular architecture could…

  • Advantages to modularization in iOS

    We’ve already talked about what modularization is, and why a team might want to architect their codebase in such a way. But what are the real life advantages to having multiple units of code to…