Opinion on explicit vs implicit types

On explicit/implicit types, I think just like there are night owls and morning larks, there are people for whom types help and hurt.

We gotta start by agreeing that aside from extra safety and docs, types also demand extra work, and can distract a reader from following a story.

You may say that any up front work is justified in service of fewer bugs, but you probably don’t believe it. There’s definitely some line you draw, where loss of productivity and sanity is too much. Some people draw that line at explicit types.

Explicit types force you to think more horizontally than vertically. Instead of focusing on where data comes from and where it goes (most programs have 3-4 entry points and 3-4 destinations), you focus on the data itself, in a vacuum. But data is not in a vacuum, it’s on a path.

By spending so much energy on annotating what data is in a vacuum, you take energy away from clarifying what path the data takes. In my experience, codebases that are explicitly typed are easier to reason about in small fragments, but harder to piece together overall.

If you put more focus on the data flow, then you invite a different way of reading your program. It makes you pay attention not to what data is, but the context: where it came from, where it’s going, and how it’s transformed. Personally, my brain is more wired to think like this.

Some of the safety you lose by not having explicit types you regain by having shorter, more concise code that tells an easier-to-follow story. And then you can test the heck out of that story, which you would probably do anyway.

Background

37signals decided to remove TypeScript from Turbo. This caused community backlash. I have long been leaning towards implicit types and away from explicit. The amount of backlash made me want to lay out some of my thoughts on why I prefer implicit types in dynamic, expressive languages. I posted my thoughts as a bunch of tweets, but saving it here for easier linking, preservation, and sharing on other social networks.



Date
September 7, 2023