Hello and welcome to another episode of the Bike Shed, a weekly podcast from your friends at Thoughtbot about developing great software. I'm Joel Kimville. And I'm Sally Hall, and together we're here to share a bit of what we've learned along the way. So Sally, what's new in your world? Well, as a recording, we've got a major storm coming up on the east coast next weekend. I live in the
south, so we're just not built for that. So I've been spending a lot of time this week trying to prepare, you know, not doing the like can't-ic buying of all the milk and bread because I don't actually consume that much milk and bread, making sure that I have like, you know, salt to put down enough dog food to get us through if we're all stuck at home for a while and things like that. To be clear, when you're talking about a storm, this is specifically snow slash. Yeah, it's a winter storm. So it's going to be snow and ice, probably more ice than snow, which is just terrible down here because it melts during the day but doesn't fully evaporate, and then freezes overnight, and then all the veristrates are covered with black ice, which you don't see a really rare car on it. Yeah, that's not good. Yeah, and we'll possibly lose power.
This will be the- we moved a couple years ago, and this will be the first like winter storm we're experiencing in this house, and so I don't know what it's like to be in this house without power. So that'll be fun to discover, but I mean, thankfully we've got blankets and dogs keep us warm, so we'll be okay. Have you ever lived anywhere that gets snow regularly? I went to college in Pennsylvania, right? It's up at Philadelphia, which I feel like for New Englanders probably feels like this out still, but coming from the actual South, right? It turns out I want a winter coat.
I thought I did, and I got up there, and my friend from Boston was like, oh honey, that's not going to keep you warm, and I had to teach me how to dress for the warm. So I spent four years in a place that was more than cold enough for me and more than snowy enough, and then fled right back to the South. So you've experienced all the actions you need to take to be prepared for a winter. I mean, a little bit. It's kind of different. Preparing for winter is a 19-year-old in a college
dorm, as opposed to, you know, a full-grown adult in the house. Uh-huh. The homeowner's stuff is a little bit different. It is. It is. Yeah. And we actually, our house has a hot tub, which is awesome,
but also is just like another complicated thing that involves electronics and plumbing that could freeze. That's true. An adventure. We'll see though. Good luck. Yeah, you've always lived in cold places,
right? That's right. Yeah. So this is nothing to you. We're also expecting a lot of snow in Boston over the weekend. Although I think I'll believe it when I see it. Yeah. I feel
like every year a big storm is forecast. And oh, we're gonna get a foot of snow or something. And then we end up getting like a half inch that melts overnight. Yeah. But potentially I will spend my weekend shoveling. Well, good luck. That sounds unpleasant. Art infrastructure is so not ready for
snow that like, I don't need to shovel. If I shovel my driveways, it's not like there's anywhere I can go beyond that. So. Right. Right. You just don't want your car sort of locked under a block of ice
when this is over. Yeah. That's true. That is true. Hopefully it's all nothing and we come out next week and bear some of the amount of salt we have that we didn't need. You can't have too much. It's
good to be repaired. Yeah. Yeah. What about you? What's new in your world? I've been doing some
interesting work on my project where we've had to interact with relationships that effectively form a graph, a graph in the computer science sense of the word. And we've had to think about how we want to encode that when we store it in a postgres database. Can we pretend for a minute that I don't remember from college webograthas. Obviously I do. But right. For listeners. Yeah. Yeah. Yeah.
So a graph is basically just a bunch of entities that are connected to each other with relationships. So it's very sort of loosely defined. The computer science terms for these are nodes and edges. And sometimes those edges can have a directionality to them. So instead of just two things being connected, they might be sort of connected via an arrow. And the arrow implies something. And we use these all
the time and software under the hood for a lot of things. And even just when we're thinking modeling about things, if you're drawing boxes and arrows on a whiteboard, it's probably some form of graph in the computer science sense. But like any type of like dependency work that you're doing is going to be modeled as a graph. In this case, modeling, what's effectively like a subcontracting relationship. So different contractors and subcontractors, those end up sort of forming a graph or one, I guess agency subcontracts and other, which they might subcontract different things to different subcontractors. And so you know, this whole like web of interconnected entities. And then
how do you represent that in Postgres? And how do you query that was the problem that we were facing? Interesting. What would be the problems you would run into if you didn't really think about it and just kind of built it the way you would like more simple relationships, you know, like a company has multiple contractors, a contractor can have multiple subcontractors. Where do you run into issues when you don't really think about it as a graph in plan ahead?
So you could do it as a sort of like many to many relationship in rails. What you then have to figure out is how to query descendants. And so if I'm saying, hey, for this contractor, what is the entire like graph below them? And what you end up having to do is effectively a recursive query, where you say, well, all right, well, get all of this contractor subcontractors. And then for each of them, get their subcontractors and keep going until you like exhaust the chain on every branch. And you could write that as a loop in Ruby that
would get very expensive because you're making a lot of queries. You could write that as a Postgres recursive CT, a commentable expression, which is much more performant. That is the way you'd want to do something like that. But it's a little bit awkward to query. And so there are other forms where you can serialize and query more easily. But what you trade off is the ability to
have a single source of truth. Okay. So some of these approaches where you say, hey, we sort of build a table structure that's much simpler to query. You can just query with regular like where clauses. What they end up doing is sort of their denormalized versions of the data. And so
if you ever need to change something, now you need to change multiple rows to update them all. Oh, yeah, that does sound tricky. Yeah, which is not what you want for a database, ideally. So oftentimes, the recommendation is to you start with a table that is a single source of truth that is encoded for normalization. You could probably do something with a many-to-many relationship. The traditional way
to represent this is what's called an adjacency list, which is just a list of the table that includes just all of the connections. It's effectively what your join table would be in that many-to-many relationship in Rails. And then maybe start with a recursive Postgres query over that. And then once you start finding issues that maybe look at fancier things. The nice thing about that adjacency list or join table approach is that there's a single source of truth, which makes it really easy to write. If I want to add a connection between any two entities, I'm writing one row. And everything else
will just sort of work. If I want to sort of move a subgraph under a different entity, insert a new contractor in the middle, whereas like A and B used to have a direct contract relationship, and now they do it through an intermediary, I can just delete the direct connection between A and B, introduce the intermediary and then add a connection between all those. That's one delete and two rights and the whole thing works. As opposed to one of these approaches that you can use where you're sort of creating a table that has a bunch of duplicated values, but it's easier to query and the fancy term is a closure table, then you're writing like a ton of new rows that you have to modify and all that to just to support things. So how are you handling it in the empty of the working on? So we're doing a combination of both. The fancy term for this is materialization,
which if you've worked with a materialized view before, I worked with one this morning. So I was interested in this to realize that materialization is a more broad term in the database world, not just applied to views, but it does refer to these sort of like derived, denormalized tables that you can work on or data sets that you can work on. That makes sense. And so in this case, what you're doing is you're taking your source of truth, which should be that joint table, the adjacency list, and you're materializing it into this other table, it's easier to query, but that's not necessarily your source of truth. And at any point, you should be able to just delete that closure table and regenerate it from the from the adjacency list, which is the source of truth.
Okay. Yeah. So like abstracting from a materialized view to just the concept of materialization in general, it's the idea. It's like, it's something, it's data that is already in other tables and exists there, but you're writing it to a new table or view in a way that makes it easier to query. Right. Right. And in this case, specifically in a denormalized form.
Yeah. I guess that the sense of the mental model that I have is that with a materialized view, it's almost like automatic materialization, and that the view is itself defined with a query, and you can just like trigger that to sort of regenerate itself. Whereas if I ever wanted to truncate this table and regenerate it, I'd have to write a script or something like that. My heuristic for understanding these two ways of doing things is that materialized views and auto materialized table, if you will, versus like just a regular Postgres table that I'm like building from the other one is a manually materialized table. Okay. Yeah. So that would be something that like,
you generate an add to and modify an update in a way other than this, you know, more or less giant database query that's stored in a file. Right. Right. So this particular case, all the rights happen through a Rails app. And so what I'm just doing is at the points where we're writing, I'm writing to both tables. Yeah, that makes sense. You know, if somebody happens to
write to one table and then forgets to write to the other, it's possible there's drift, and then I have to make sure that we only ever rely on that source of truth table, and maybe I do need to regenerate. So that is something that's important to remember is a constraint to the architecture. I feel like a lot of people might hear that and go, ah, I should use an active record call back here. And that's not necessarily a bad idea. I think you could say, hey, here are the ways that I want to modify the materialized table whenever the source of truth table is modified. I'm doing it through
something that's closer to like services. So like at the point of writing, or even just in the controller, like, I only have one or two places where I write to this table. So I say, like, when you write to this, you also write to this other thing, but it's not done at a callback level. Yeah, that makes sense. The important thing is you can't rely on all of these to be sort of competing source of truth.
I've been in apps that do that where they have the same fact can be ascertained through different tables. And then when the tables don't agree, you have to decide who's truth, you believe. And that's not a good time. Man, this is interesting. I feel like I could talk to you about this for a long time, but I don't think this is what we plan to talk about today. No, no, we should probably do a
dedicated episode. I went on a deep dive, not just for graphs, but also trees and how we represent them in Rails apps in Postgres, some really fascinating things. I have a draft blog post that I'm working on that I'll probably put out the next few weeks. And yeah, we should definitely do a future episode that's a deeper dive on. Graphs and trees and serialization in general. I love discovering
new ways that Postgres can do what feels like magic for me. You know, sometimes I'll, I feel like often I've found this pattern of me trying to do something in Ruby, and it's expensive and frustrating. And then I figure out that you can have Postgres do it and it's beautiful and kind of what it was made for. Postgres is a wonderful piece of software. Yeah, it really is. I think that,
you know, we're talking about these data structures. And I'm sort of thinking of the different ways we use data structures in our day-to-day code. And oftentimes, they're sort of abstracted behind primitive types, at least the like class of data structures that you would see in a Cs class, whereas like, oh yeah, well, our like strings and arrays and hashes and things are all sort of implemented on top of these core ideas, but we don't tend to have to deal with them as much directly in our code. Does that sort of match your experience as well? I think so. My brain really likes examples.
Can I have an example, please? Yeah, so there's a lot of different ways to implement like strings and hashes and arrays that are, you're doing them just were optimized for how that data structure is used. I don't know for sure exactly how Ruby implements all of these. Sometimes it's about setting things and like, continuously in memory, which is the sort of traditional definition of how arrays are done, right? But sometimes you do sort of clever things. hashes are built off the idea of a hash table,
which is a classic structure, which is what we call them hashes in Ruby. Other languages call them, you know, maps or associative arrays or hash maps or the data structure that has too many names. Yeah. You can implement hashes effectively as a tree, which is what a lot of functional languages do for their equivalent of that. So elms dictionary type, which is effectively a Ruby hash is, I forget the name of this data, I think it's a hash array mapped try, which is like specialized form of tree.
So when you dig into a lot of these different data structures, the primitives that we have, what you find out is they're built on a deep understanding of these classic computer science data structures, because you know, you want your string operations to be fast. You want your array operations to be really fast and efficient and all of that. And so it's really open, like, I open it to dig into them sometimes. Something I've heard you mentioned before, that I don't totally have a grasp on, but seems interesting is the idea of primitive obsession. What does that mean?
So primitive obsession is the sort of overuse of primitive values, so things like strings, integers, arrays, hashes in your code, oftentimes contrasted with having sort of a richer domain object that could represent that thing. So it'd be like, if I'm building a, you know, retail application, and I use an array for a shopping cart and just put things on it and map over things like that, rather than having a shopping cart object. Exactly. I have a maybe alternate definition that I'd like to pitch to you. Okay. And that is primitive obsession happens when,
as programmers, we project implicit additional semantics onto a type. So an array sort of definitionally, if you don't know the context in which it's used, it is a list of multiple pieces of data in order. That's all it is. If the reader of the code has to know implicitly that, oh, this array actually is a shopping cart, and there's like certain types of operations you can do on it, if you know it's a shopping cart, that would make sense for all arrays. It's not about list type operations anymore. It's not about iteration. This is shopping cart specific stuff. So like
calculate tax, you can calculate tax on a shopping cart, but it doesn't make any sense to do that on a right, just in the range, I don't know. Right. And maybe even there's some like magic knowledge you have to know about it. So maybe the last item in the shopping cart array is always the tax value. And that's just the thing you have to know. Yeah. And maybe you comment that in your code.
But that's a lot of like implicit knowledge and sort of implicit additional behavior that we're as programmers projecting onto something that is a much lower level concept. Yeah, I could see that causing a bug or two, some confusion, some frustration. It also causes your logic to sort of leak everywhere, because now what you're doing is you're passing an array around the app all over the place. And each sort of calling site has to implement some shopping cart related logic. So maybe some places trying to calculate the subtotal. The map for doing the subtotal is going to be at the call
site. So maybe in a controller somewhere, maybe in a view, you're trying to do a report, maybe in some service somewhere. And now if you're having to calculate the subtotal in a couple of places, you know, do you duplicate that logic? Do you like extract some sort of like helper that can be passed around everywhere? Now like the helper has to be passed along with the array. Whereas if you have
a shopping cart object, now all of the operations that you would do on a shopping cart get to live with your data. Yeah, so no matter where you're doing it or what service or flow or whatever, it's part of, it's going to calculate the same way every time using exactly the same code. And now you get to lean into all the goodies from object orientation. So you might decide at some point, hey, we've realized that there are some performance issues with using array for the shopping cart. We would like to switch to a different data structure under the hood. If it's wrapped in a
shopping cart object, then you can change the internal representation and none of the callers need to care. They're still like asking, they just say, hey, I have a shopping cart operation, giving me the subtotal. They don't care if you're iterating over an array or doing some fancy stuff at a hash or, you know, fetching it from the internet. And so having that encapsulation is now all of a sudden an advantage that you have in terms of the ability to refactor. Yeah, that makes sense.
Is this strictly an object oriented idea? Like if you're not working with an object oriented language, it's primitive of section of thing. I think the term is much more visible in the OO community. But it's absolutely a thing in other language types as well. So I've done a lot of Elm and it's very easy there to rely on things like strings and integers and things like that. And I think it's
really fun. Elm is that it's got a great type system and a type checker that will verify consistency of a lot of things in your program. And if you use more domain specific types for things, all of a sudden you've sort of upgraded the intelligence of your type checker. And those types are sort of like an object? Yes, yes, you're sort of distinguishing that this thing is not like another thing. So maybe your shopping cart array is not the same as a
list of names array and the compiler can now tell the difference. This happens a lot for simpler scalar values as well. So things like strings and integers. I find this is really important for measurement. So if you're just passing around numbers, but they're for different physical quantities, the type system doesn't know the difference between, let's say you're building out a payment system, right? And you're saying, hey, I need to calculate,
payroll for this person. This is their hourly rate. This is their number of hours they've worked and how much do I pay them? It's very easy to just give it two numbers to that function and maybe swap the order. You pass in hours and rate versus rate and hours. And we'll be trying
to protect ourselves against that a little bit with keyword arguments and you can do something similar in Elm. But another thing that you can do is give these things a separate type and say, hey, this is a rate and this is a monetary amount. Then the compiler can say, wait a minute, you can't just want the first argument to be a rate and the second argument to be a monetary amount, you pass the other way around, go fix that. So it's the idea of the units matter rate. Yes. Right. It's not just a number that is an abstract number. It is a number that has a
specific meeting with a specific unit concept encapsulated in it. Units and then more broadly, I think the almost dimension of it. So you can say there's a difference between feet and inches units, but they're just different sizes of the same type of quantity. They both amounts of distance. So in theory, I can have a value in feet and I can have a value in inches and I can add the two numbers together. That is a valid thing to do. I just need to make sure
to do the conversion so that I don't end up in some weird number. But if you have a value in feet and another value in hours, right, you can't add those two things together. It's a nonsensical thing to do. And if everything is just numbers everywhere, then you can easily get yourself into weird place where you're making mistakes and the types of some keeps you want us to. I feel like I'm having flashbacks to times when I've worked in co-bases like this and been like, what does Thor mean or what? Uh huh. It's great for documentation as well. It can be really nice
when you also have domain operations on a value. So when you want to interact with it, you don't want to do all the math or whatever yourself. I think a great example of that is the time class in Ruby. Always comes back to time with this. It always comes back to time internally, right?
It's a number of milliseconds since 1970. And you could, that is an integer. You could just pass integers around your code everywhere. And now anytime you want to print it, you've got to do some math on it. Anytime you want to do like addition on it, you've got to make all the conversions working, all that. And who wants to do that? Who wants to duplicate that all over their code base?
And who wants to deal with the potential bugs of making mistakes there? Yeah. Like all the I was adding seconds and the underlying representation is in milliseconds. But they're both just giant numbers. And I can't tell just by like looking at the code. So it passes the code review. Yeah.
That is what the timestamp is actually a time duration. Oh, yes. And so having a time object that encapsulates that and just says, you know what, you don't need to care about the underlying number. We've wrapped that. We've given you a bunch of operations you can do on that internal number and we'll manage the number for you. Beautiful thing. And you mentioned duration, right?
Action support duration. Wonderful concept. I love it. Yeah. I feel like a lot of this is just reminding me of how much I love the quote, magic of Rails. It's a lot of this. A lot of the value
of like stepping away from that, like not only do you have a bug, you have documentation that allows you to work and write code in a way that is much more sort of human friendly. Again, any sort of work you're doing with duration and time in Rails is really user friendly because of that interface. Because what you're now able to do is you express your code in domain terms. You're saying, hey, I want to add a duration to a time. I want to advance time by a certain duration. And you can do
that instead of, you know, I've seen scripts, I've seen code in other languages where you are just passing around like timestamps and numbers and trying to do the math yourself. And that's a whole different experience. Yeah. Suddenly you're spending half your day calculating a duration or converting it into another time zone or whatever, instead of solving the problem you're actually trying to solve. I think in theory, all this sounds really good. It's hard to do in practice.
What is that we're talking about here? So we're writing a higher level domain objects instead of reaching for a primitive. Yes. Okay. Yeah. And oftentimes, because I'm the author and I'm writing
the code and I know what I mean, it's very easy to like project extra meaning onto a primitive and not realize that I've done that. Yeah. And it's easy to tell yourself, I don't need a whole object for this. It's just a number. I can just store like this. It's fine.
So how do we catch that? What does that smell like? Oh, I got one of these things that's top of mind right now. And it might be a bit shocking, maybe a little bit controversial. Oh, I love it. Give us the spicy take.
I'm going to say complex blocks, like blocks that are more than a few lines are a smell for primitive session. If you have, let's say, I'm going to say maybe not in each block where like in an ERB file, you're doing a bunch of things, right? But something like a map or a reduce. If you've got a giant map block where you're saying, Hey, for each item in this list, I want to do this other thing, probably what you want is to have whatever the contents of that block is actually be a method on the object itself. Yeah, that makes sense. And sometimes what you have is an array of magic integers,
you just have to know. And you're saying, okay, well, you know what, I should actually wrap these integers into an object and now I have methods I can call on them. Yeah. Sometimes I'm going to stretch the idea of primitive session here where I say like primitive session is just projecting extra semantics on a type that doesn't represent that. Maybe you have some kind of object that is sort of intermediate level. It's not a raw string, but it's some other type of thing that you're trying
to add extra meaning to. Maybe you need an object that sits on top of that to represent that high level concept. This feels like a thing that can happen easily with a user object. Yeah, because like a user at its most basic, it's just, you know, the unique identity of someone using your application. But then you've got, well, is this user a employee or a client or a contractor or all this other stuff? And it can be easy to assume that there's meaning on that, you know, any user
with an email that ends in thought about calm is an employee. So we're just going to check that every time when actually what you need is to just go ahead and make yourself on a play object there. Yep. There's an article by Chelsea Troy on why users are terrible concept to start with. And we should be considering some of these other ideas of sort of how this user interacts with things. And what are the teas apart the elements of like, what does it we actually care here?
Right. Is this identity for sign in? Is this a role within the system? Is it like three or four different dimensions we might care about in teasing that apart? So that's a thought for looking article, we'll link it in the show notes. It's worth reading. Once again, this is you handing me
a word to describe a thing I've thought about before, but having had a way to describe. So this is exciting for me from the obsession. I've been slowly building up a like web of notes in my note-taking system on primitive session. And I'm like, slowly connecting it to various other topics. And I think one of the like big breakthroughs for me, I made a connection between primitive session and a lot of patterns that we reach for when we're dealing with null or nil and Ruby.
Okay. And a classic pattern that we're all told to reach for when we're dealing with nil and Ruby is the null object pattern. The classic example there is say, hey, you're using nil to represent the idea of a guest user. Why don't you just create a guest in your app? And here I am thinking about things. I'm like, wait a minute, nil really just means absence. And if you need
special context to realize that nil in this context means guest, what are we done? We've projected context onto a or predicted semantics onto a lower level structure. That's my definition of primitive session. Yeah, because nil inherently doesn't mean guest. Right. It means absence of data.
Yeah. And I think we're as programmers, we're really bad at just letting nil be absence of data. Because oftentimes absence happens because of certain contexts, but we never encode that into our programs quite so much. Just every coder who deals with that has to know that, oh, yes, well, in this flow, if you encounter a nil, that means this. Yeah, I found myself struggling with that yesterday. I was trying to represent, you know, is a user allowed to do this thing. And it's a
really complicated check for whether or not a user can do that thing. And the way I had written it first would sometimes return nil instead of to a false, which, you know, if you don't think about it, then basically that turns into that false move on. But sometimes when it returns nil, it actually meant true. Oh, that mind-bending. It is mind-bending. And I was like, okay, so I wanted to just sort
of decide that nil meant false and have that carry that information for me, but turns out I was wrong. So I have to figure out why this is returning now, like what I actually needed to be instead, and do a whole thing there instead of just being like, okay, nil is false. Yeah. I'm trying to understand like, what does nil actually mean in this context? Right. Yeah. It turns out nil meant I was not calculating things correctly and was passing
very values that were unexpected. And so I was just spinning back out nil as a way of panicking and refusing to do what I asked it. Yeah, sometimes nil means error. Yeah. But there's a difference between like even when you're processing data, right? There's a difference
between no data and an error occurred. And there's a difference between no data and zero and an empty string, although some languages would make all of those falsie. Well, they're all falsie, but they're not all the same thing. Right. No, they're all different. And depending on the language,
they might have different levels of falsiness. Yeah. Yeah. Cough Cough JavaScript. Look at you, top script. Always looking at you. I always love the
this matrix that shows like all the things that are like double equals versus triple equals versus like just general falsiness in JavaScript. And it's slightly different than what a lot of other languages do. It's very easy to trip yourself up on that. So we've talked about what a primitive obsession is and why it's a problem. I'm wondering like, how do you combat that or how do you talk to other developers about primitive obsession? So you're reviewing a PR and you see some red flags
that make you realize that's what's happening. How do you approach that conversation? I think one of the things that's really nice with the refactors removed for the recession is that they give you a really nice interface to use. And so that's a little higher level. And so yes, we can talk about things like, Hey, if we expected an object here, we had better encapsulation, better reusability, all of that. But then also what I can do is say, and also the call site here where we have this like
gnarly map block or something, if we did it the way that I'm suggesting would now look like this. And that code is typically like very elegant. There's something just aesthetically pleasing. And I think that that often helps make the sale. That's true. I get pretty excited when I make a PR with something
complicated and usually gross. And then the code review fairy in whatever form that might take says, Hey, look at this beautiful and elegant way you could do this. Imagine a world right where someone has a PR where they've just got a bunch of raw timestamps and they are iterating over them. They're doing some kind of select block where they're trying to find all of the timestamps that are in the future. That's something that's blocked and they're doing some math to try to figure out today's timestamp versus that other one which one is greater. And you leave a comment
on that PR that says, Hey, if all of these were time objects, we could just say map, use the symbol to proc syntax and just say future question mark. I feel like that would make the sale right there. Yeah, yeah, I guess it's really not hard to convince when you've got the alternative. Sometimes thinking of the alternative is hard, right? So you're like, Okay, so what is the like underlying domain concept that's lying around there? And you have to think for yourself about
like, what is it that what does Neil really mean in this context? Maybe even need to talk to product people about like, what is it we're actually trying to do here? What are the edge cases? But oftentimes I think when I do that exercise for myself and then I pitch a solution, there are technical considerations where I'm like, Hey, this, you know, get our encapsulations better, reusability is better, all this stuff. But it's hard to be being able to just put a little snippet that says, and this call site now looks sort of high level and beautiful. And don't you
wish we could do this. Yeah, I feel like sometimes I will get into the situation where I'm doing something that feels like it should be a quick change or a quick feature. And part of my brain is like, should this be an object? And the lazy part of my brain is like, you don't need that. Let's just throw numbers around. It'll be fine. And training myself to remember is actually far
easier to make this an object than to handle all the grossness of this pile of primitives you're creating, I think has been difficult. Because sometimes it feels like making a whole new object type is a big thing. Yeah, agreed. And so it's it can be, I can find myself resisting that for longer than I should. I think oftentimes an easy way to start, if you want to sort of ease your path there, is to do a struct or a data class. Because those you can just do in line and they're there and they
like, they give you a start and they give you an interface. And then later on, you can say, you know what, now we're trying to have a lot of behavior and we want this to be a full on object. And then you turn that into a class and it's good. Yeah, so you can take baby steps away from the primitive. Yeah, yeah. Anyway, we're talking here generally in terms of like what makes code
composable and easy to read and all that, there's a cost of all of this, which is objects are a little more memory read than primitives. Objects also add a little bit of indirection, depending on how you compose the boundaries. So be careful with that. There's more method calls. And so that's a runtime cost as well. But we're writing Ruby because it's a language that allows for expression in a higher
level that reads closer to English. And where not every choice is built on extracting the maximum performance out of the code that we write. Yeah. And I feel like if you're writing code that is hard to read and hard to maintain, but very performant, all you're really doing is generating bugs faster. Oftentimes these things are just adding performance in places where you get no value for that. So you're
paying a cost for no value. But you know, be aware that if you go like all in on this, you might end up having a path where you might want to refactor some things for memory usage, unlikely, because there are so many other things that might trigger that first. But I don't know, I could imagine a world where you're like, you've got a pipeline for processing a very large file and then like every line you're creating a giant web of objects and maybe that becomes memory expensive. Like everything it depends. It depends. I would say those are caveats to keep in mind. But in
general, try to work at the sort of highest level of domain term that you can. You know, this thing is not a magic array of the shopping cart. And maybe you even name your variable shopping cart. You know, shopping cart equals this array. If you're doing that, maybe consider an actual shopping cart object. If you're already giving it a name in the code to explain to other people what
this magic array means, what if we had a dedicated object that sort of described that idea? Well, I think I have a new obsession here. An obsession with not obsessing with primitives. Right. We've got a domain object obsession.
Yes. Yes. There we go. I like it. All that note. Shall we wrap up? Yeah. Sounds good.