---
title: "Take More Shortcuts"
source: "/writing/take-more-shortcuts/"
---

Article

# Take More Shortcuts

Collin Flynn

June 22, 2020

I'd like to propose a distinction between a _shortcut_ and a _hack_.

### Shortcut

-   Quick, functional progress in the direction of a longer-term, robust solution.
-   Imposes a _functionality ceiling_. A shortcut will eventually have to be revised before further progress is made.
-   Not ideal, but there are reasons to do it.

### A Hack is:

-   Quick, functional progress in the direction of a brittle, short-term solution.
-   It's a _tripwire_. A developer is likely to break it by touching it.
-   Not ideal, and not even advisable.

A shortcut is a compromise that gains immediate partial functionality by deferring a costly (but "correct") choice until the shortcut can be revised, transitioned, or rewritten. It also comes with a known _functionality ceiling._ A day will come when the shortcut is inadequate.

A hack _appears_ like quick progress, but in the wrong direction. For partial functionality, it trades away stability, comprehensibility, maintainability, or circumvents safety measures.

## A Hack

Here's one I've seen too often.

Suppose your application wants to disk-cache the details of the currently logged-in user.

val user: User

You've got various local storage mechanisms at your disposal, but serializing things takes a lot of keystrokes. How about this?

val userAsJsonString = user.toJson()
localStorage.putString(key = "USER", value = userAsJsonString)

_(Here,_ `_localStorage_` _could be android shared preferences or whatever caching mechanism exists on your platform.)_

### Looks like a hack

❌ Brittle. Will crash on any modification to the `User` type.

❌ Circumvents existing safety measures. Other storage solutions such as SQLite bend over backwards to help you migrate on schema changes.

❌ Other developers could break this without knowing it.

## A Shortcut

What about this?

val userId: String = currentUser.id
localStorage.putString(key = "USER_ID", value = userId)

Instead of the full user object details, all we have is an `id`. That's less than we wanted, but also matches a square peg with a square hole. We're not trying to hammer the full `User` into a brittle string representation.

### Looks like a shortcut.

⚠️ Not ideal, but also not broken.

⚠️ Known limitation: you'll have to fetch full user details using the `id`.

✅ Partial functionality towards a more robust local storage method.

✅ Won't break when another developer touches it.

--

Take more shortcuts, write fewer hacks.

_Collin writes software and his personal dictionary of words at_ [_Livefront_](https://livefront.com/)

-   Collin Flynn

    Principal Software Engineer

    Collin Flynn

### Tags

[Digital Engineering](/insights/all/?topic=digital-engineering) [Mobile Apps](/insights/all/?topic=mobile-apps)

### 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/)
