Formats over Functions
Tags: tech
Published: 2020-03-14 16:21:08

---
title: Formats over Functions
published: true
description: Why we should focus less on Implementation and more on Standardization
tags: Tech
slug: formats
displayed_publish_date: "2020-03-13"
canonical_url: https://www.swyx.io/writing/formats
---

## The Thesis

When we focus our efforts on Formats over Functions, we focus less on **implementation** and more on **standardization**. **This is the key to longer lasting code.**

## Why

"Functions" are selfish - they assume all code is written for them and them alone, and as a result the API bleeds all over the place. "Formats" are more generous - they only assume conventions - and the library/framework code lives *outside* the file so that other libraries/frameworks can write to it as well.

When we write imperative code in Functions, there are a lot of ways we can shoot ourselves in the foot, and it tends to be more verbose. This is why our code tends towards more declarative over time as we better understand our problem space. When we are confident we understand the problem well, we should move this to Formats, which are the ultimate declarative form with no implementation detail involved.

Formats deal mainly in simple values, whereas functions have to be evaluated. Here I am very inspired by Rich Hickey's [Value of Values](https://www.youtube.com/watch?v=-6BsiVyC1kM) talk. The idea is that values have a transitive property - every nested property of a value is itself a value - therefore it is completely static and reliable and can be statically extracted without evaluation, or copied and modified without side effects.

## Examples

Here are examples of successful Formats over Functions:

- `package.json`: Multiple tools can read package.json without getting in each others' way. There is no spec for it though, which is occasionally a problem, but there are [attempts](https://github.com/pkg-json/package-json) and unofficial [guides](https://flaviocopes.com/package-json/).
- Storybook's [Component Story Format](https://storybook.js.org/docs/formats/component-story-format/) frees Stories from the prison of Storybook's proprietary functions, enabling it to be consumed by design tools and other tooling.
- [xState](https://xstate.js.org/docs/) moves state management out of proprietary library/framework functions into the tried-and-tested [SCXML specification](https://www.w3.org/TR/scxml/).
- [Infrastructure as Code](https://en.wikipedia.org/wiki/Infrastructure_as_code) replaces human functions in the loop ([ClickOps](https://m.subbu.org/clickops-3cf0e5bc5ecf)) with code formats - at first proprietary per cloud, and then [agnostic across clouds](https://serverless.com/) (debatable if multicloud IaC is valuable)
- The success of GraphQL: When [Lee Byron and co open sourced GraphQL](https://www.youtube.com/watch?v=783ccP__No8), they didn't open source the FQL/Ent implementation that was used in Facebook. That wouldn't have been very useful to others who don't use XHP/PHP. They *rewrote it from scratch* and chose to solidify a GraphQL spec first, and then write a JS *reference implementation*. This choice helped it stay agnostic of implementation details, and allowed both server and clientside implementations of it to proceed independently, leading to the exponential success of GraphQL as a protocol.
- [libc (thanks b0rk)](https://twitter.com/b0rk/status/1217890878674624513?s=20) is another example of a command standard/interface. Because everyone speaks libc but doesn't have to use the same libc implementation, you can use DNS and it works the same in every language and platform.
- CPU [Instruction Set Architectures](https://en.wikipedia.org/wiki/Instruction_set_architecture) - any two CPU's that implement the same ISAs will be able to run the same code, regardless of their underlying implementation.
- Email. Email works everywhere regardless of implementation detail.
- [Wikipedia has more standards](https://en.wikipedia.org/wiki/List_of_international_common_standards#Reference_for_information): in particular, [BGP](https://www.swyx.io/writing/networking-essentials-routing-5gb7/), Barcodes, ISBNs, QR codes, Uniform resource locators, [vCards](https://en.wikipedia.org/wiki/VCard)

More examples of ongoing movement:

- [React Components -> Redwood Cells](https://www.swyx.io/writing/react-sfcs-here)
- Blockchain development moving from Protocols > Platforms https://medium.com/@lightcoin/from-platforms-to-protocols-c5fe0bdd0fc7
- [Twitter is looking at becoming a decentralized format](https://www.theverge.com/2019/12/11/21010856/twitter-jack-dorsey-bluesky-decentralized-social-network-research-moderation) (actual success to be seen)

## Epistemic Disclosures

- **Epistemic status**: This is a general idea I've increasingly been referring to as a programming principle/design pattern - but I don't pretend to have good definitions and examples locked down yet. But I'm pretty sure the thesis is right - I just have to scope it down to the [boldest correct form of the argument](http://paulgraham.com/useful.html).
- **Epistemic effort**: I've had [a stub post](https://twitter.com/swyx/status/1210298953276645376) on this since October but I figure I better flesh it out a bit - but be warned I know it is a little vague still.