Skip to content
452: Hotwire Essentials with Steve Polito episode artwork

Dec 24, 2024 28 min

452: Hotwire Essentials with Steve Polito

from The Bike Shed Hosted by thoughtbot

Stephanie is joined by follow thoughtbot-er Steve Polito as they discuss his latest GitHub resource, Botcasts. Find out why Steve was so keen to make the app, what he learnt about Hotwire in the process and why he thinks you should stop listening to the show in your current pod-catcher and pick it up in Botcasts instead! -- Try building Botcasts for yourself over on Github! Your host for this episode has been thoughtbot’s own Stephanie Minn, and was accompanied by Steve Polito. You can find more of Steve’s work over on GitHub, or read what he has to say about his work on thoughtbot’s blogs. If you want to connect with Steve you can do so through LinkedIn. Interested in birds instead? Why not check out Stephanie’s book recommendation! If you would like to support the show, head over to our GitHub page, or check out our website. Got a question or comment about the show? Why not write to our hosts: [email protected] This has been a thoughtbot podcast. Stay up to date by following us on social media - LinkedIn - Mastodon - Instagram © 2024 thoughtbot, inc.

Episode details come from the podcast's RSS feed.

Embed this episode

Ready to play

452: Hotwire Essentials with Steve Polito

0:00 28:47
of matches

Transcript Auto-generated, may contain errors

Hello, and welcome to another episode of The Bike Shed, a weekly podcast from your friend at ThoughtBot about developing great software. I'm Stephanie Min, and today I'm joined by a very special guest, Steve Pulido. Hey, what's going on? Happy to be here. So, Steve, you are a fellow ThoughtBotter and maintainer of one of our open-source gems, Suspenders. Is that right? That is correct, yes. I've been here for about three years now, and yeah, just enjoying everything I can do here. So, Steve, what's new in your world? Yeah, I'm happy to announce that today is day two of Ralphapalooza, which, for those of you who don't know, is just our end-of-the-year celebration at ThoughtBot.

We break up into teams. It's kind of like a hackathon. code on things, write blog posts. One team's doing baking, so some stuff has absolutely nothing to do with coding. It's a lot of fun. And I actually went into Boston yesterday in a co-working space with some of the other Thoughtbotters, which was a lot of fun to actually see people in person. So that was a fun day. Cool. I didn't realize you did that. I clearly need to catch up on what else is going on outside of my Ralph Palooza group. Yeah, it was fun. It was very exciting. I never had a chance to work in the Boston office, but we were, I think, like a block or two away from the Boston office, so I could...

pretend that I knew what it was like to make that commute and whatnot. So yeah, it was a fun day. Glad I got to see some people. Yeah. Pretend you were a Thoughtboter from the 2010s era. Yeah, exactly. Exactly. For anyone who doesn't know the Thoughtbot lore, Ralph of Ralphapalooza fame is the Thoughtbot robot logo. So the little robot guy's name is Ralph. Cool. And yeah, Stephanie, how about you? What's going on in your world? So I went to a little holiday party earlier this week and I participated in a white elephant gift swap. Do you know what that is? Have you ever done one before? I do, but fill me in here. Is this the same thing as a...

Yankee swap or is there like a crucial difference between the two? I don't know Yankee swap. I've never heard that before. So I'll explain it to you and you can let me know it's the same thing. It's basically like a kind of gift party game where everyone contributes a gift that's wrapped and then people go in order and pick a gift and unwrap it. Or you can steal a gift that someone else has already unwrapped and everyone goes until all the gifts are unwrapped. Everyone kind of sees what is on the table and then...

That's, I think, when the fun really begins because you can, it ends up being that the stealing really ramps up around that time. And eventually everyone gets like either to have a gift that they are happy with or maybe a gift that they had to steal for or something that they are kind of mad about, but no one got to steal it away from them. And it's a, I don't know, just kind of like a fun little way to. celebrate the holiday spirit, especially with, I think, like a friend group or even in this case, it was for a co-working space that I'm a part of. So it was people who didn't really know too much about each other. And the types of gifts that were on the table were very fun. That's awesome. If you don't mind me asking, what did you bring? So this is why I wanted to talk about this on the show, because I think I'll never forget this. So I brought a book called The Field Guide to Dumb Birds of North America. And it is like a birding field guide, but it also is kind of silly and quirky and makes fun of birds a little bit. So I just figured there would be some like nature person.

in this group who would be into it. And then the gift that I got back was two birding field guidebooks, which is really funny to me. I don't know how that happened. And the guy who contributed the other birding books got my book. And so I think it really worked out for both of us. Yeah. In the history of the world, I wonder, that might have been the first time that ever happened specifically, swapping very similar books between two people during White Elephant.

I do. Yes. And I do think I got the better end of the stick because I got two for one. So I have somehow found just an infinite energy source, apparently. Yeah, it's perfect. Yeah, I just got to keep going to White Elephant gift socks and see how many bird books I can multiply. Right, right. Or money. Maybe bring like a $20 bill to the next one, see if you can make $40 or something. Well, one of the reasons that I was really excited to have you on the bike shed is because you recently, with the help of working with another thoughtbotter, Sean Doyle, created a new resource that we published on...

Hotwire. Do you want to say a little bit about that and tell our listeners what it is? Yeah, absolutely. So it's a Rails application called Botcasts, you know, to go along with like the ThoughtBot theme, right? And it's a podcast player, which we thought would be an interesting thing to highlight the Hotwire ecosystem, specifically because like when you're navigating between pages, you want the audio to keep playing. And we thought that would be kind of a great way to highlight what you can do with, you know, the Hotwire ecosystem. And then in addition to that, we had an ambitious goal of like making

the application itself sort of a self-serving tutorial which ended up i'm glad we did it but it ended up making it we started this project two years ago so it's like actually pretty old and i think part of the challenge there was because we wanted to make this really good app and then also make it a tutorial in order to do that we had to have like a pristine git history so that you could see the diff would basically serve as the tutorial and i don't regret doing that that was fun and i'm happy we did it that way but it took a while so that's what it is it's an application but also a tutorial on the application itself Yeah, we will definitely link to the GitHub repo in the show notes. I was actually going through the tutorial right before we got on together and I finished the first two lessons. Actually, I'm going to tell you about my process and you can tell me if this was how I was supposed to do it. So you had some really great like setup instructions. So it was really easy to clone and get running. And then, you know, I saw like, OK, I'm ready to follow the lesson plan. And I started at lesson one and then I was reading through it. You have like kind of instructions about the lesson when you're adding like a hockey to search in the search like episodes.

in the podcast player, right? And, you know, you're showing like, okay, like this is what we're going to do. And here's the changes you're going to make to the files. And I realized that as like you were saying, because it is like a commit by commit, you are also walking through the tutorial. And I ended up checking out to, I think the, maybe it was like the get, I think it was the commit called getting started and then branching, creating a branch from there for me to just commit my own work. Is that kind of how you see most people following along? Yeah. And I'm glad you brought that up because we had this ambitious goal to do something kind of like, I think it's Ruby cones. I've never actually had to say it out loud before, but I think it's Ruby cones.

That was the inspiration. Like it teaches you Ruby by getting a set of tests to pass. So initially that was the goal too. So you would check out at a particular branch, it would be in a failing state and you would get the tests to pass by getting introduced to some Hotwire concepts. But we found that that was like really challenging to maintain. And it wasn't like the best user experience possible for like someone trying to learn Hotwire just because dependencies and whatnot. So we scrapped that part of it. But what's left behind is...

that curated commit history which yeah lent itself basically to what you're doing and i'm excited to hear that you actually checked out a branch at that point to kind of like get to a passing state. In the past, we had a script that would do that for you, but it was like too challenging to maintain. But to folks listening, I would say there's no like right or wrong way to go through this tutorial. Some people just might want to look at the source code and the source code alone. Kind of use it as a reference, right? So it's not like the kind of thing where you have to go through, you don't even have to look at the tutorial at all if you don't want. You can just look at the source code and it can just be a reference. Or if you want to kind of take a deep dive and maybe get a better feel for some of these concepts, then yeah, going through the tutorial is helpful. And even just looking at the diff might be all you need.

You don't even have to read the corresponding pros that go with it. That makes a lot of sense. I was just thinking that too, because I went down the path of checking out my own branch and then following the instructions and literally hand-typing the changes, because that's how I wanted to learn this time around. And yeah, I like the way that it's kind of choose your own adventure. Another thing I noticed while I had been playing around with Botcast and had it set up on my local machine was that you actually seed in the database both the giant robots smashing into other giant robots podcasts that ThoughtBot does, and the very podcast that we all are listening to, The Bike Shed.

That's right. So for folks listening right now, I would strongly encourage you to go to the repository, clone it locally, get it set up, and then stop listening to your podcast player of choice and then just listen to it locally on your browser with podcasts. Yeah, it can be a very meta experience. Yeah, who needs Stitcher or Spotify or Overcast or any of those things? What you need is podcasts running locally on your machine. Exactly, exactly. And it pulls from our RSS feed, is that right? And should new episodes just show up? Yeah, when you run bin setup, it will pull from the RSS feeds. So yeah, as I said, if you're listening to this right now.

then that means you should be able to one bin set up, pause the episode now when your podcast gets your choice, one bin set up, and then resume playing it on localhost 3000 through podcasts. Yes, that's clearly what you should do. I also want to talk about the idea of progressive enhancement, which I think is a really, really... good value proposition for hotwire right and i feel like the way you formatted the progression of some features in the app kind of feel very aligned with that idea yeah i want to give sean a lot of credit too because he was he was instrumental in that foundation and maybe we can talk about one of the examples because i didn't appreciate how simple this progressive enhancement was when i was first working on this with sean which is just i think it was a lesson you had mentioned just like a keyboard shortcut it's like frustratingly simple where it's just before we even do introducing any JavaScript or anything like there's a button on the page that takes you to the search page and that's as simple as it can get so the next step to progressively enhance that is to just like automatically have that button clicked through JavaScript when you when you issue a keyboard shortcut command and you know there's a library that does that for you where you can just wire up the element to like receive that event and it clicks it for you but at the end of the day all you're doing is still clicking the link and you don't have to change a whole lot about

You don't have to really change anything about the markup other than telling the JavaScript what element to click. And I kind of keep going back to that lesson because, like I said, it's almost frustratingly simple. And I guess that's the mindset you need to be in for progressive enhancement, specifically with Hotwire. It's like, how can you leverage forms and links in HTTP as much as possible? And if you use those things the way they're intended to be used.

Adding the progressive enhancement of Hotwire is almost like... It's underwhelming, I guess is what I'm looking for. It's not always as interesting as you would think, which that was like the biggest revelation for me as I was working alongside Sean with this. Yeah, that makes a lot of sense. When I checked out that getting started commit, it had pretty much no JavaScript in it, right? And I had spun up the app and I was interacting with it from that state. And I was really, I don't know, just like appreciative of how well the app worked and how I could do everything I needed to. I could click in the individual episodes and start the audio player from there. I could search. And I think you even have it designed. I don't know if you got like a designer to...

help out with the initial look of the web app. But I think that link that you mentioned that takes you to the search page, it's in the sidebar that also shows up on all the other pages. So it feels very slick and kind of modern the way that we see a lot of heavy user interaction apps on the web, but with no JS really at all. And I think that just kind of goes to show that with a lot of that forethought and almost maybe like mastery of a lot of just fundamental native web. features, you can already do a lot with it. And maybe that's something I think that's gotten lost in the past few years. Yeah, exactly. And I'm also finding the more you go back to basics, like truly understanding when and how to use forms and links.

focusing on that and semantic markup. One, it's going to be a better user experience for a variety of users, right? People use screen readers, keyboard navigation, but then it also makes interacting with these hotwire concepts even more seamless because they rely on a lot of these principles anyways, like HTTP and like using identifiers, like, you know, IDs, right? To like with turbo frames and things like that. And if you start with a very simple semantic foundation, it makes the hotwire experience even more easy. And again, it makes it almost like underwhelming when you actually add the hotwire.

components. Yeah, I think I've also heard that, and I'm kind of curious maybe if this was intentional, maybe not, but the first lesson is adding a stimulus controller just for that nice little hotkey situation. But most of the time, it's like those are little sprinkles, like little bits of polish that you can add. But I have even heard that oftentimes you maybe don't even need stimulus at all and you can mostly do what you need to do with just Turbo. Does that feel accurate? Yeah, and I'm trying to think of an example now. So much of it has to do, again, with links and forms in my experience. But yeah, I don't find myself reaching for stimulus.

as much because kind of like you said that's like a javascript concern and typically you can probably solve the problem before even needing to reach directly for javascript like just by figuring out how to maybe craft a query parameter to maybe conditionally hide or show something where like the server might be aware of its own state frames are very powerful too and like those those are using javascript under the hood but you're not responsible for writing that javascript i think i want to make that distinction clear because there's a lot of talk about like oh you don't need to write javascript and that is true but javascript is being executed it's just through turbo yeah it's doing all that heavy lifting for you yeah i think the query param was a good call out because i think another one of the lessons is infinite scroll in which you replace the pagination with turbo, but you are still retaining the page in the query param, which I think is...

I don't know. It's like you can have both, right? Exactly. Yeah. And like, again, if JavaScript was disabled, it would still work. Pagination works when there is a query parameter in the URL telling you like what the offset is and what page you're on. And then Turbo just makes it so those requests are happening asynchronously and like getting popped onto the page through frames. I guess I'm curious what inspired you to create this as like an offering and as a resource kind of in the Hotwire environment. Like what's that landscape looking like right now in terms of learning it? Like what are people's options?

Yes, I think the inspiration I kind of touched upon earlier, I forget exactly all the steps that led to like choosing this particular topic. But I know that we kind of wanted to explore the boundaries of what Hotwire can do. And a podcast player felt or an audio player in general felt like a good candidate because like I said. When you go on Spotify or any other type of audio playing application, you can navigate between pages and the audio doesn't stop. That's kind of mission critical. If that didn't work, it wouldn't be a very good audio playing app. That felt like a good candidate to demonstrate what you can do with Hotwire. I like that a lot because I think it feels more practical in some ways. If you were just to read through a guide or something, I had also noticed that this is a fully flush Rails application. Anyone who knows Rails can figure out how to set this up. It's very familiar.

I guess I was really surprised to see that. It was like, here's this application for you. And yet, we're not going to talk about any of that. We're going to talk about this next, I don't know, iteration of what this podcast player could look like. That was very novel to me. Yeah, I'm happy to hear that. I think that's kind of another side effect or benefit of this resource. There's hotwire concepts in there, but...

It's also just neat to see some of the things we're doing with Rails in there. Like the search page is kind of neat. Without Hotwire, you still need to follow a lot of Rails conventions. Or I should say, the closer you stick to these conventions, the easier it is to do these things at Hotwire. And yeah, I think it's just like an interesting, fun resource. That makes a lot of sense. Because I think I've heard people have trouble with it because they...

maybe are wrestling with existing Rails applications that may or may not follow those conventions. And then to them, it does feel like, oh, I get all of these, a lot of things that should feel easy or are easy in some other JavaScript framework end up being really annoying or just kind of like to figure out with this different paradigm, I guess. And because at Thoughtbot, we do talk a lot about how we are proponents of sticking with those conventions and seeing, like you're saying, what that can actually look like. It's almost like the synergy of that is also kind of... what you're trying to highlight yeah exactly and another example of that it's not part of the tutorial itself but it's a blog post we just released on processing network requests in the background and then displaying that response to the browser through hotwire and like 80 of that tutorial is like showing you how to build it up through rails conventions and then like the last 20 is like oh just use this this hotwire method like you know use this turbo method here

and it just does it automatically. But you needed to have known how to follow the conventions to get to that point. I've said this a few times, but the actual implementation can be very underwhelming. Not the implementation for the framework and library itself, but as the developer adding that last bit of polish through Hotwire, it feels underwhelming because the diff is very small if you're sticking to those conventions along the way to build a solid foundation. Yeah. Underwhelming, but ultimately...

that's nice, you know, it should be small. Or like the fact that it can be small is really cool. Even like for me, when I was going through the tutorial, there was just so many things about just the Rails forms API that I was like, oh yeah, like, so I've forgotten how to use it. And it will say like having that scaffolding was exist already was nice because then I could go kind of, it wasn't that I needed to rely on it, my own memory. I could kind of see it, I can go reference it, find API docs for it, jog my memory, that kind of thing. Yeah, forms are very powerful. And the more I work with Turbo, the more I realize like,

I can probably solve this with a form or a hidden field. Knowing how to leverage those tools helps a lot. As a contrived example, if you wanted to hide something on a page through the server, but conditionally, there's dozens of ways to do that. You could have a query parameter where it's show avatar equals true. If that's in there, then in your view, you can have the conditional if param, show avatar is true, then show this, otherwise don't. The state of that URL can be manipulated through forms or through links.

that's not using javascript right that's just http but then when you start connecting that with frames then you could like have a link on a page that says maybe hey show this person's profile and maybe you construct a link such that the query parameter is in there that says, hey, we want the avatar to be shown. So then when it gets brought back to the page through a frame, it's like the avatar is there. But maybe when you click on the link on a different page, you don't want the avatar to show. So you don't include that there. And if you're using frames, you can still reference the same view, and you can update these parts of the page asynchronously. And if JavaScript was disabled, it would still work close enough. You'd still go to that page with a user, but their avatar would or would not show, depending on how the URL was crafted. That's why I've been thinking more. I don't know if that landed or not, because I've been thinking about this a lot.

but it might be a little confusing. Yeah, I could like see your brain worrying as you were like talking through the code. It sounds very composable though, right? It's like you end up, I don't know, just being able to reuse a lot of pieces. Those choices about like, do we want the query param here? Like that can depend on like where you are in the app. That was the other thing I picked up on in the tutorial too, where I think you can like start playing episodes from a couple of different places, but there was a lot of reusability there. Does that sound right? Yeah, and a lot of that is like, you know, Rails conventions.

partials following following those patterns but yeah that part of the tutorial is one of my favorites because yeah you hit the play button on like the bottom of the screen but then if you're looking at the index of episodes the play button turns into a pause button not only on like the fixed player at the bottom of the screen but also like on that individual episode itself on the index yeah when I think about managing that state in something like react for example it's it also be tough because the scope of the kind of state management that you are having to do in the in the podcast app it's like really the whole the whole page yeah exactly and that's another I think it serves as a great candidate because of that, too. You said very well, yeah, it's the whole page. If you're coming from another front-end framework like React or something, that paradigm makes sense. It might be challenging if you're coming into Rails. How do I have this global state like this?

One of the solutions is, again, things like query parameters and the state of a form, things like that. So it sounds like really getting started on Hotwire is also more like reinforcing some Rails fundamentals. Yeah, absolutely. So you mentioned that blog post that you published recently. Are there other places that you feel have been really useful in your journey with this to have such a strong foundation so that all the Hotwire stuff does click more easily or at least feel more seamless? Yeah, I mean, I'll definitely shout out our blog for sure. I think we have a lot of good resources there.

I think just in general, I mean, part of it is practice. Don't be afraid to, you know, we're talking a lot about podcasts, but maybe someone's like, yeah, cool, but like, am I interested in a music playing app? Like they might be focused on something totally different. I would encourage you to maybe spin up your own Rails application and just make a breakable toy. Like try to explore something that is of interest of you and see how you would make it more interactive. I do that a lot with the blog hosts. I make a brand new app every time and I iterate over it.

probably a half a dozen times before I actually get it to a point where I think it's as close to Rails conventions as possible. So that's another thing too, is I just, I practice it a lot. And there's not really a good substitute for that. So that works for me anyways. That makes a lot of sense. And there's a great gem to do that, suspenders. That's true. And I would even say you don't even need suspenders. If you want to keep it like as low level as possible, you could even just do Rails new. And on that note, Steve, it was really great having you on the show to talk about podcasts and Hotwire Essentials. Shall we wrap up? Let's wrap up.

Frequently asked questions

How long is this episode of The Bike Shed?

This episode is 28 minutes long.

When was this The Bike Shed episode published?

This episode was published on December 24, 2024.

Is there a transcript available for this episode?

Yes, a full transcript is available for this episode. You can read the complete transcript on the episode page.

Can I download this The Bike Shed episode?

Yes. Use the download control on the episode player to save the publisher-provided media file.