---
title: "Higher-Order Code Smells"
source: "/writing/higher-order-code-smells/"
---

Article

# Higher-Order Code Smells

Collin Flynn

April 20, 2021

Code smells are a [well established](https://martinfowler.com/bliki/CodeSmell.html) idea.

The "smell" part is perfectly descriptive: like opening the fridge after a weekend away. You know when something is off.

There are popular tools to help detect them (_Checkstyle_, _SonarQube_, etc). There are research papers giving them a [taxonomy](https://www.researchgate.net/publication/4036832_A_Taxonomy_and_an_Initial_Empirical_Study_of_Bad_Smells_in_Code) , and to measure their [relative costs](https://www.sciencedirect.com/science/article/abs/pii/S0164121206002780) . As a thought exercise, it's fun to name them and give classifications (and ponder which are the worst), but I'm most interested in how they appear in the wild.

And in the wild, code smells appear in groups. Disorganization spreads disorganization, chaos begets chaos. And different code smells compound into unique, pungent aromas. I'm going to call these groupings _higher order code smells_ where a lot of things are going wrong, together.

I'd like to share one higher order code smell with you today, and who knows, maybe this article will have a part 2 and 3.

_(Edit: It totally has a_ [_Part 2_](/writing/higher-order-code-smells-part-2) _now.)_

## The N-Dimensional Object

> A method or constructor that has many inter-dependent parameters, with some valid and some invalid combinations.
>
> Characterized by: (1) Uncontrolled Side Effects, (2) Too Many Parameters, and (3) Cyclomatic Complexity

An N-Dimensional Object is trying to be too many things.

The wrong combination of arguments will look valid to the eye, but run with side effects (1). It tries to cram all the parameters of different uses into one place (2). And the many varieties of inputs will reach different branches of code, and it's hard to reason about them (3).

The worst n-dimensional objects have a large possibility space: the Cartesian product of the inputs. All of them lay traps. It's like that crocodile dentist game except you're the only player and you're also the crocodile.

Stop hurting yourself.

Here's one.

A model intended to be used with a `Profile` screen, capable of showing an individual `User`, a user group, and/or a few controls for admins:

And before you get confident, no, the documentation isn't up to date.

N-Dimensional Objects show up in places where a simple feature kept acquiring new variations without revising the data model. Or sometimes a series of design decisions lead to a UI with lots of different "flavors", and the permutations got out of hand. Other times it's a UI container, like an Android `Fragment` or `Activity` that has many different modes of initialization.

The fix should be clear given the causes: split the class into distinct types with their own custom-fit arguments. Who knows, maybe even compose it?

Fixing a higher order code smell like this leads to a cascade of other needed fixes: old call sites will now read more clearly, and the UI layer handling will have code paths de-branched. The time investment to make those followup fixes goes a long way to explain how a smell like this can stick around for a while.

That's all for now!

_Collin keeps code lemon fresh at_ [_Livefront_](https://livefront.com/) _, and he thanks you for reading._

-   Collin Flynn

    Principal Software Engineer

    Collin Flynn

### Tags

[Digital Engineering](/insights/all/?topic=digital-engineering)

### Share

-   Copied

## View these next.

[See all](/insights/all/?type=writing)

-   [

    Article

    How To Sabotage Your Project Using Inconsistency

    Collin Flynn

    ](/writing/how-to-sabotage-your-project-using-inconsistency/)
-   [

    Article

    Unit Testing race conditions by creating chaos (Swift)

    Sean Berry

    ](/writing/unit-testing-race-conditions-by-creating-chaos-swift/)
-   [

    Article

    UIApplicationDelegate call sequence reference

    Sean Berry

    ](/writing/uiapplicationdelegate-call-sequence-reference/)
