Discover this podcast and so much more

Podcasts are free to enjoy without a subscription. We also offer ebooks, audiobooks, and so much more for just $11.99/month.

359: Serializers

359: Serializers

FromThe Bike Shed


359: Serializers

FromThe Bike Shed

ratings:
Length:
44 minutes
Released:
Oct 25, 2022
Format:
Podcast episode

Description

Chris Toomey is back! (For an episode.) He talks about what he's been up to since handing off the reins to Joël. He's been playing around with something at Sagewell that he enjoys. At the core of it? Serializers.
Primalize gem (https://github.com/jgaskins/primalize)
Derek's talk on code review (https://www.youtube.com/watch?v=PJjmw9TRB7s)
Inertia.js (https://inertiajs.com/)
Phantom types (https://thoughtbot.com/blog/modeling-currency-in-elm-using-phantom-types)
io-ts (https://gcanti.github.io/io-ts/)
dry-rb (https://dry-rb.org/)
parse don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)
value objects (http://wiki.c2.com/?ValueObject)
broader perspective on parsing (https://thoughtbot.com/blog/a-broader-take-on-parsing)
Enumerable#tally (https://medium.com/@baweaver/ruby-2-7-enumerable-tally-a706a5fb11ea)
RubyConf mini (https://www.rubyconfmini.com/)
where.missing (https://boringrails.com/tips/activerecord-where-missing-associations)
Transcript:
JOËL: Hello and welcome to another episode of The Bike Shed, a weekly podcast from your friends at thoughtbot about developing great software. I'm Joël Quenneville. And today, I'm joined by a very special guest, former host Chris Toomey.
CHRIS: Hi, Joël. Thanks for having me.
JOËL: And together, we're here to share a little bit of what we've learned along the way. So, Chris, what's new in your world?
CHRIS: Being on this podcast is new in my world, or everything old is new again, or something along those lines. But, yeah, thank you so much for having me back. It's a pleasure. Although it's very odd, it feels somehow so different and yet very familiar.
But yeah, more generally, what's new in my world? I think this was probably in development as I was winding down my time as a host here on The Bike Shed, but I don't know that I ever got a chance to talk about it. There has been a fun sort of deep-in-the-weeds technical thing that we've been playing around with at Sagewell that I've really enjoyed.
So at the core of it, we have serializers. So we take some data structures in our Ruby on Rails code base, and we need to serialize them to JSON to send them to the front end. In our case, we're using Inertia, so it's not quite a JSON API, but it's fine to think about it in that way for the context of this discussion.
And what we were finding is our front end has TypeScript. So we're writing Svelte, which is using TypeScript. And so we're stating or asserting that the types like, hey, we're going to get this data in from the back end, and it's going to have this shape to it. And we found that it was really hard to keep those in sync to keep, like, what does the user mean on the front end? What's the data that we're going to get? It's going to have a full name, which is a string, except sometimes that might be null. So how do we make sure that those are keeping up to date?
And then we had a growing number of serializers on the back end and determining which serializer we were actually using, and it was just...it was a mess, to put it lightly. And so we had explored a couple of different options around it, and eventually, we found a library called Primalize. So Primalize is a Ruby library. It is for writing JSON serializers. But what's really interesting about it is it has a typing layer. It's like a type system sort of thing at play.
So when you define a serializer in Primalize, instead of just saying, here are the fields; there is an ID, a name, et cetera, you say, there is an ID, and it is a string. There is a name, and it is a string, or an optional string, which is the even more interesting bit. You can say array. You can say object. You can say an enum of a couple of different values. And so we looked at that, and we said, ooh, this is very interesting. Astute listeners will know that this is probably useless in a Ruby system, which doesn't have types or a compilation step or anything like that.
But what's really cool about this is when you use a Primalize ser
Released:
Oct 25, 2022
Format:
Podcast episode

Titles in the series (100)

On The Bike Shed, hosts Chris Toomey and Steph Viccari discuss their development experience and challenges with Ruby, Rails, JavaScript, and whatever else is drawing their attention, admiration, or ire this week.