Build a hackable library

Posted 2025-01-263 min read

When I was at university, I was taught that the best way to build a nice library is to make it hackable. Over the years, I've tested whether that was true. Every time someone showed me an "opinionated" library, it was immediately obvious that it needed to be hacked in some way to make it work for specific needs. You really can't predict what people will do with a library, so you should make it as easy as possible to extend.

Almost every bad library or framework that was built is not hackable at all. The biggest example was Next.js — always wasted developer time by imposing their opinions. When they added the app folder to fix some of the legacy assumptions they made it even worse by forcing server components and continuing to force developers to run JavaScript on the server, which you almost never need if it isn't a blog. Most file-based routings aren't hackable either, since you can't opt out of it. A few libraries do better, but many fall short.

Always give people a way to opt out of your "opinion." It shouldn't remove all the benefits of the library — sometimes you just want to change a small part of it while keeping the rest. For example, it took a year of complaints before Expo Router allowed a custom folder for routes, which was a big deal for many people. The world is beautiful and full of different people with different needs; embrace that.

I once found myself in a highly competitive dev tools project on a small scale. I had easy access to most of the developers who were interested in it, but I faced heavy pushback from incumbents who owned the media. The original library was hugely opinionated and not hackable at all — you were forced to use it in a specific way, which wasn't good for many developers. I built a hackable library instead, and it turned into a huge (though small-scale) success. Everyone switched to it, and none of the negative media coverage mattered because developers knew it was beneficial for them. That library has remained evergreen for several years without any major rewrites.

When GraphQL was taking off, many libraries were built with strong opinions on how to use it, which wasn't ideal for many projects — people often had to write extra glue code to make things work. React, on the other hand, is a good library: it's hackable, and you can do anything with it, even replace the renderer if you like. Some of Meta's libraries — like Recoil or Relay — were needed but weren't hackable enough to be adopted widely, and they're now nearly abandoned. Python libraries are usually very hackable to the core, but LangChain is a huge mess that isn't hackable — you can't even change prompts in some cases to make it work. It's so bad that Anthropic recommends avoiding it.

Building a hackable library is usually easy; don't skip that step, and people will reward you for it.

@ex3ndr@ex3ndr@founders@ex3ndr
Everything is in Public Domain