What makes a Good Library/Framework?
日本語はこちら。
I recently came across this article:
Will SwiftData fix Core Data’s marketing problem? | Pietro Rea
It states that Core Data with the glue code necessary to make it work with the UI though it's merely a persistence framework got a bad reputation and that the aesthetics of the new SwiftData may be able to overcome this.
Core Data’s main problem was not a technical problem. It was a marketing problem!
I don't usually use Swift and thus don't have much experience with either Core Data or SwiftData but this line caught my attention:
If I were to guess, I bet Apple wanted to first roll out Swift macros to create the models with annotations (@Model, @Attribute, Relationship)
Without much Swift experience, I could still imagine how using these annotations (I'll refer to them as "attributes" from here as it's the official name) leads to easier and neater code. I do have experience with attributes in other language so, as much as it's a subjective opinion, I think the usage of attributes in this context are very nice from an aesthetic point of view.
This made me wonder how and why one library or framework could feel better than another one that serves similar purposes. Using attributes like in SwiftData is a good example where it feels better but it's a bit difficult to explain exactly why or what makes it so.
This post will be my random thoughts on this topic like:
Less boilerplate code
Orthogonal
Less things to learn
Let me elaborate on each of these.
Less boilerplate code
This is the most obvious one. If the library or framework allows you to do the same thing with less code than writing it out yourself, it's usually a good one.
The SwiftData example above only requires you to write attributes whereas the predecessor, Core Data, requires you to write a lot more code to achieve the same thing.
It's not to say that boilerplate code is evil. Some major frameworks (e.g. Spring or Ruby on Rails) are so feature-rich and powerful that necessitates writing some. They still allow you to write less code than you would otherwise have had to.
Orthogonal
The word orthogonal is used in mathematics to describe two vectors that are at right angles to each other. By extension in programming, it's used to describe two pieces of code that are independent from each other.
A library that doesn't interfere with the rest of the code is usually a good one. Using attributes in SwiftData is a good example. It's independent from the rest of the code (for the most part) and yet gives enough power to the library to do what it needs to do.
Less things to learn
If the library or framework is designed in a way that you don't have to learn anything new, it's usually better. An obvious example would be one that allows you to express yourself in the same language as you are usually using.
Again the SwiftData example uses attributes which are already part of the language (albeit relatively new). A few other examples that come to mind are SwiftUI and Jetpack Compose. They're both designed to be used with the language you're already using.
(Small caveat: SwiftUI uses "Function Builders" which are still in proposal stage and not part of the language yet. But I think it's still close enough.)
I'm sure there's other aspects that make a great library or framework.
Hope you find other aspects. These points should help in deciding which library or framework to use!