Library patterns: Why frameworks are evil

https://news.ycombinator.com/rss Hits: 1
Summary

Library patterns Why frameworks are evil This article is a follow up to my previous blog post about functional library design, but you do not need to read the previous one, because I'll focus on a different topic. In the previous article, I wrote about a couple of principles that I find useful when designing libraries in a functional style. This follows from my experience with building F# libraries, but the ideas are quite general and can be useful in any programming language. Previously, I wrote how multiple layers of abstraction let you build libraries that make 80% of scenarios easy while still supporting the more interesting use cases. In this article, I'll focus on two other points from the list - how to design composable libraries and how (and why) to avoid callbacks in library design. As the title suggests, this boils down to one thing - build libraries rather than frameworks! Frameworks vs. Libraries What is a difference between a framework and a library? The key difference is how you can use them and what kind of code you need to write. Frameworks. When using a framework, the framework is in charge of running the system. It defines some extensibility points (interfaces) where you need to put your implementation. Libraries. When using a library, you are in charge of running the system. The library defines some points through which you can access it (functions and types) and your code can call it as it needs. You can see the difference in the diagram. A framework defines a structure that you have to fill, while library has some structure that you have to build around. Of course, the separation between the two is not complete. Some components have aspects of both - you call it as a library, but it has some holes (e.g. an interface) that you have to fill. Why are frameworks evil? If you look at the diagram above, you can already see some of the problems with frameworks. In this section, I'd like to say a few things about three of the problems (before looking at...

First seen: 2025-04-17 07:24

Last seen: 2025-04-17 07:24