2016-11-15

More API Simplifications in Longevity 0.17

Longevity is the persistence framework to use with Scala and NoSQL. Release 0.17 simplifies the user API in some very pleasant ways. Empty marker traits Persistent and Embeddable are removed. Also, KeyVal now takes a single type parameter instead of two. In brief, this will make defining the classes you want to persist so much easier and more natural, as you no longer have to extend your persistent classes with empty marker traits.


I've been unhappy with the Persistent and Embeddable empty marker traits for a while now, but I haven't been certain enough until now to commit to removing them. My internal thought process was roughly something like this: Right now, the longevity repository class has a signature like so:

trait Repo[P <: Persistent]

If I change that to look like this:

trait Repo[P]

Then it won't be clear that only persistent objects have repositories. But that argument doesn't really hold up, because you can only ever get repositories for persistent objects, as longevity creates the repositories for you. Also, it doesn't even make sense to have a repository for a type that you don't want to persist.

In the end, the fact that these traits were empty, and providing no functionality, was a smell. I was easily able to remove them, and I adjusted my User Manual and Getting Started Guide to talk consistently about persistent objects and persistent components. (I adjusted my vocabulary to replace the term embeddable with persistent component, which is probably more intuitive in users' minds.) The fact that the user manual speaks concretely about these concepts obviates the needs for them to be included in the type system.

So I'm really happy with the way the new API looks. Looking at the sample applications (Akka HTTP and Play versions) and user manual examples, it feels so much nicer! I hope you enjoy the changes as much as I do.

I decided to release these minor changes as a separate release because it might be nice for users to have the chance to adjust to the new API without having to worry about other changes at the same time. Also, my next job will be a deep dive into Scala macros, and it may be a while before I put out the next release!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.