This episode is brought to you by WorkOS. If you're building a B2B SaaS app, at some point, your customers will start asking for enterprise features like single sign-on, SCIM, provisioning, role-based access control, and audit trails. That's where WorkOS comes in, with ease-to-use and flexible APIs that help you ship enterprise features on day one without slowing down your core product development. Today, some of the hottest startups in the world are already powered by WorkOS, including ones you probably know, like Perplexity, Vercel, Jasper, and Webflow. WorkOS also provides a generous free tier of up to 1 million monthly active users for its user management solution.
making it the perfect authentication and authorization solution for growing companies. It comes standard with rich features like social logins, bot protection, MFA, roles, and permissions, and more. If you're currently looking to build SSO for your first enterprise customer, you should consider using WorkOS. Integrate in minutes and start shipping enterprise plans today. Check it all out at WorkOS.com. That's WorkOS.com. Hello, and welcome to another episode of The Bike Shed, a weekly podcast from your friends at BotBot about developing great software. I'm Stephanie Min. And I'm Joelle Kinville. And together, we're here to share a bit of what we've learned along the way. So, Joelle, what's new in your world?
I recently read an article on configuring Capybara, sort of a test UI library that a lot of Rails apps use to interact with end-to-end tests. And there's a bunch of things you can configure on it that I didn't realize that will allow its selectors to just pick up things by name. So by default, you can target any form input by the name of its label or its ID or its name attribute. But a common pattern that you'll see in testing is adding a test ID data attribute to DOM elements. And Capybara accepts that that's a thing that people do, wants to make your life easier. So you can say, hey, the test ID attribute in my app is data test ID or my test ID or whatever it is. And then now when you say fill in the username field with Joelle, it will look up things by either label or name or ID or test ID using the attribute that I supplied. So that's got me really excited to dig deeper into Capybara's selectors. All that being said,
relying on test IDs is a bit of an anti-pattern. So I'm sort of like, I'm excited that Capybara can do this. And also you probably shouldn't do it. Yeah, interesting. So it goes in that order of trying to find whatever element you're selecting on? I don't know what the order is. That's a good question. Yeah. So I was thinking a lot about how React's testing library when I need to do something similar.
assert on or find and interact with certain elements, they have some guidelines about the order of what selectors you should use in order of most accessible to least accessible or least suggested, which I refer to it pretty frequently because I just forget and want to make sure that I'm doing what I can to make things as accessible as possible. But similarly, they have a little bit of a warning that's like only use the data test ID attribute if you have to and default to using a different selector if you can. Kepibara does have this style of configuration, though, for other things. So, for example, you can configure it to look up based on ARIA labels as well, which that is, I think, a thing that's worth doing. If a user can interact using that particular attribute, then it makes sense that we can use it for tests.
There's also a third-party library that you can use that has their Capybar accessibility selectors. So they allow you to look up an element on a page based off of a lot of ARIA states and things like that. The goal of all this being to one-write tests that are easier to read. I'm not a huge fan of reading tests and seeing big CSS selectors. What is that particular thing?
But then also if your test actually, if it's an end-to-end test, ideally it acts as a user and only does things that a user can actually see and interact with. And using CSS electors is often a way to bypass usability or accessibility issues with the markup. So Stephanie, what's new in your world? I also have a testing update. This morning, actually, I participated in a workshop called Good Enough Testing that was run by Lucian Ginda. And I was really excited about taking this workshop because he...
basically kind of marketed it as how do you feel confident in your tests that you're writing enough tests to catch bugs and verify behavior, but not spend an infinite amount of time testing. And I actually think you would really enjoy the content because it reminded me a lot about your talk, The Math Every Programmer Needs to Know, where he kind of gave some classes of types of code you will want to test. Some of the code is maybe more computation sensitive or maybe more logic sensitive, has a lot of conditionals or whatever, or maybe it's... more sensitive to state and state transitions. And he presented us with some different tools for making sure we've kind of covered all of the cases in those different classifications. And for example, if you have a lot of logic in your test, a lot of conditionals and, you know, sometimes things that are not just like if statements, but like guard clauses or rescuing errors, things like that, you can use a decision table, which I think you've mentioned before and even written about in a blog post, I think. Yep. Huge fan. Right. Yeah. And yeah, showed us those tools. But then the other thing that I thought was really interesting is he went.
into this idea of the number of test cases you choose to write might depend on how much risk you're willing to tolerate. So there are like a minimum amount of tests that you can write. It won't test all the combinations of all the conditions, but maybe that's okay because the risk is pretty low. Because once you start seeing in that decision table, like all the possible combinations, it's like, oh my gosh, I might have to write a hundred tests for this one method. It is huge. And maybe sometimes that's what you want to do if it's a really, really high risk kind of an important code that people will.
you know, be harmed if something goes wrong. But I really also liked that lens of here's all the possible conditions and cases you could write. Now let's like also look at it in terms of risk and context. I think having the mathematical kind of approach to show here's how you can have confidence and then being like, and also there's something out there that's like, use your best judgment. I love this very pragmatic approach to writing tests. I think there's a lot of dogmatism in the testing world and a lot of people just sort of blindly copy-pasting advice from other people. And so this is very refreshing to hear this like, hey, here's how to think about the strategy you want to use for testing and also like how much testing you actually need.
Yeah, yeah. Practical is a good word because it did present some theory and then also presented how to apply it. And you don't need to stick to the theory entirely and say, well, my decision table resulted in 125 different combinations. And so I need to write that many tests. So, Joelle, I wanted to bring up a topic that has come up as a consulting company. Oftentimes we're brought into teams who might be trying to rewrite a legacy application and starting from scratch.
hopefully being able to re-implement in maybe in a different technology or just because they're having a lot of trouble with their existing app has become really, really hard to do development and they are wanting to start fresh. I'm wondering, is this a type of project you've been on before? I've done a few of these in a few different variations, which is interesting because my sort of, without any extra context, my default recommendation is don't do it. you know, sometimes I'm brought in like midway through and it's, okay, we started this thing, help us finish it. But if you're considering doing a rewrite and I don't have any other information on your app, my immediate reaction is you probably don't need to. Yeah, and sometimes I think we're luckily enough brought in early to audit whether a rewrite is necessary or not, or if there's another path kind of forward. I think as developers, it's always really tempting to do that rewrite because we see all the pain points in the code right now. We think if we could just do it fresh again with the knowledge that we have from the first write, we could do it better this time. And...
It's really exciting to be able to do it with that fresh slate. And in practice, it just doesn't really pan out. There's not a whole lot of business value that's generated there. And it can take your whole dev team off of active development for multiple months. And it has a lot of risk involved. You might be introducing a lot of bugs that were previously fixed or introduce new ones that you never encountered before.
the cutover might be really challenging. You might lose some data as you're migrating from the old system to the new system. There might be some downtime for customers. So just a lot of risk to consider and oftentimes not as much upside as you'd hope. Yeah, I think actually starting off by talking about what the trade-offs really are when you decide to do a rewrite would be a good place to start. And I like that you pointed out business value because I think, yeah, like while you are rewriting, that means that product is not in front of customers. And so it's not.
generating any value during the time that of development whereas your existing application is like it's already being used and that is i think that's value that gets like overlooked sometimes especially by by developers who you know like you said their experience might just be like oh like it's so hard to kind of innovate or adding features to this thing but it's also there is something to say that like if an app is still kicking then that like that is good so i think that's one of the things that Maybe there's that idea of the grass is always greener, but I don't think that people fully appreciate what a working out business is doing. Have you ever been involved in a rewrite? I have, and it was challenging. One of the things that I experienced was it always takes longer than you think it will. And at the same time, because you may not have a really clear measure of...
value like while you're in that development phase the only thing that you can really show is like look how like you can demo the product right and that kind of ends up being maybe something that stakeholders are measuring progress by i have a little anecdote because One time when I was kind of involved in a rewrite, we wanted to show progress, but there were a lot of things that still weren't hooked up in the backend that would actually make it work. And so we ended up mocking some of the data just to show how the interactions worked. But I actually think that ended up working against us because it kind of left the impression that we had made more progress than we had. And that is, we'll pay for that later, right? When it turns out like there's so many things that still need to be connected, so many problems that we didn't foresee.
And I think the lesson from that was be honest about things that are still needing to be done, even if it looks like it's quote unquote working. It's always so tempting to throw in some like smoke and mirrors into a demo. And sometimes you need to do that. But I think that is definitely the kind of thing that can be, like you said, self-defeating. I've been on projects where people have demoed work that has not been merged into the main branch yet. Like it's on a devs machine on a branch somewhere. And you really want to show that stakeholder that we have a particular feature done. And it's not really done.
It's not merged. It's not pushed to staging. It's definitely not in production. And I always get a weird feeling about those kinds of demos. That's going to come bite us. Yeah. I mean, I'm just pulling these numbers out of thin air, but I almost wonder if it's like sometimes the development work is only like 30% of the work and like 70% is actually.
seeing what happens when it's used, fixing all the bugs that come up, all the unexpected things when real users interact with it. I've definitely seen work that's sort of in the cursed, like 90% done phase, where it's like, it's basically done. It just needs a little more polish or a little extra something. Like I've got the happy path done on my branch and I just need some error handling or something. And then like it goes to review and people find a lot of like edge cases that I didn't take care of or that I didn't quite fully understand the requirements or something like that. And so that's part of the reason why I push so aggressively to scope features down.
and to put PRs up that have small shippable chunks of work that can go out to production because that avoids me of having just a ton of code sitting in that 90% done phase. And then I really had the temptation of saying, hey, I'm going to demo like this grand thing I've been working on for two weeks. It's only on my local machine because I've been shipping something every day. And so I can show you the last two weeks worth of work on staging or on production. And so that's been a much healthier workflow for me. Nice. Yeah, I think maybe the 90% done was kind of the idea I was thinking of. This episode is sponsored by MailTrap, an email delivery platform that developers love. An email sending solution with industry best analytics, SMTP and email API, along with SDKs for major programming languages and 24-7 human support.
Try for free at mailtrap.io. I have another like maybe kind of fundamental question about rewrites, which is oftentimes I think the goal is to have parity with the existing application. But sometimes the existing application is so big that like that parity will not say never be reached, but it's unrealistic to be like, yeah, we want to rewrite this and have the full richness and functionality of the app right off the bat before having it have production traffic. So you're suggesting you almost need to like... bring your app back down to an MVP for the new version and then build back up from there? I don't know. I don't have a clear solution, but I did it in my notes as I was brainstorming for this topic, right? Too big to be right, question mark. Because I think that, I think it's more of a pitfall, right? The expectation that you need to have parity. And it's really tough because yeah, there will be customers who expect the same functionality in the V2 or whatever and might be disappointed if it's not there, but at the same time, if you are.
perfect is the enemy of good a little bit. If you're just trying to get that rewrite to have like everything, it takes so long and you end up then in a spot where you have to kind of maintain both or you're maintaining the existing application while you're trying to add those, anything that might've been added to the old one to the new one. And that is like a really, really tough spot to be in. I think there's sort of two directions you can go with that. Typically when we talk about a rewrite, we're talking about more or less cloning the app that you currently have. It's a feature for feature copy built either in the same or different language, but hopefully implemented better this time. And I think that
you can sort of release the requirements a little bit on either end. So on the one side, if you scope things down, you say it is going to be feature for feature, but it's not going to be the entire app. We're going to scope it down to a subsystem or a particular module or maybe even a class. At that point, changing the internals of code, keeping the behavior the same, we have a word for that. That's refactoring. And we do it all the time. It's a well-understood problem. And when you keep it bounded, it's a safe and effective thing to do. And so if there are...
aspects of the architecture that are challenging for the team. Maybe you can just get away with a refactor. Or maybe you can refactor the internals to fix that performance issue you're having. Sometimes you need a much bigger change to fix the underlying issues, to deliver the business value that you're hoping to deliver with all this. But usually you can get away with some sort of change in place and not have to redo the whole app, not have to stop development on the app or switch people over to a new system or anything like that. Yeah, I like that idea of change in place and you...
That keyword, I think, bounded, lit something up in my brain. Because if you can identify or almost decompose your existing system into pieces, you're more likely to be able to iterate, which we all know and love in software development, and potentially get you similar benefits of what a rewrite you were hoping to get out of a rewrite. Yeah, and having been burned by rewrite or rewrite-adjacent projects a lot, I'm now a huge fan of change in place and change in place that is incremental. So can you make some changes to your architecture instead of like a fresh rewrite of everything? Can you start introducing sort of new components and gradually shift things over? Are there ways where you can get some of the benefits of the new approach to doing things without having to complete the whole project?
So maybe it's a performance issue. Can you do some things where you're like, okay, this is going to involve like rewriting a lot of components, maybe not all of them, but many of them. But do we need to get everything done before we get the benefit of the speed optimizations? Or can we do some things that like, oh, this part of the app is now faster. And then next week, the other part will be faster. Right. I think it's actually smart to do some of that due diligence ahead of time to be able to identify and scope the areas that are causing the most pain, rather than just kind of like throwing your hands up in the air and saying, this whole app is terrible. And when we were kind of brainstorming, talking about rewrites.
you had opened up a thread kind of internally and asked like, what are some rewrite experiences? And one of our directors had chimed in and talked about this idea of obsolescence. And I think if we can just talk a little bit about like why, what's the point of a rewrite anyway, I think it's to avoid your obsolescence for your product. And to me, that means like being able to innovate. And I think that that can still happen in Chunk's recent client that I was on, for example, like a really big part, but not all of their app involved, like a rich text editor and built it in using one technology.
And then that kind of choice was then proving kind of in the future to be challenging to keep up with more kinds of richer features that they were looking to move into. And so they decided to just rewrite the editor piece. And I think just that bit of scoping and boundary can be really, really useful and I think more successful. So I think that's interesting because now you're sort of loosening the other condition. So your options are you could either keep the feature for feature, but scope down and do a smaller piece. Or say we're keeping full app scope, but we're not keeping the requirement to be feature for feature. Think of this as, okay, now we're getting a chance to effectively disrupt ourselves. If a competitor was entering our business space and they were being a startup and writing an app that would disrupt us, what would that app be? And can we be the ones to do it first? But again, now we're talking in terms of business strategy and less about technical needs.
And I feel like with a lot of these things, as developers, we often like, we want to rewrite for sort of internal satisfaction reasons, like personal satisfaction, but just team satisfaction because the code is annoying to work with or whatever. But when you need to think about doing that seriously, you really need to think in terms of like business value. what is the value of doing a rewrite? And I feel like that's the question that as, because we have that product consultant hat on a lot, we end up having to ask clients really often is the, okay, you're trying to do this thing. What is it you're trying to, like, what is your goal here? What is the motivation? I have a question. Do you think there's sometimes some hubris in thinking that a rewrite will solve the problems? 100%. Yeah, I think it's almost like assuming that you know better. And you know, you did mention earlier, like, okay, like, let's take everything we've learned and rewrite this thing. But at the same time,
I'm sure there are reasons why things were the way they were that you certainly did not anticipate or expect that caused you trouble later. And I think that's what ends up making those rewrites take longer, is that hubris of thinking that you haven't all figured out. And I think that applies whether I'm coming in. sort of toxic scenario here is me coming into an app that somebody else has written and me just being like, oh, Stephanie wrote Trash Code. I'm going to rewrite this, right? That's toxic. But on the full other end of this, I write an app. It's version one. We go live. Everything happens. And after a couple of years of maintaining it, I'm like, I hate my own code. I've learned so much over the last two years. I want to rewrite. And even though I wrote all of the code, it's not that I, I mean, I probably do think that Joel from two years ago is a worse developer than Joel of today. But I think there's still a little bit of like hubris in the, I can do it better. And in some ways that's true, but I think there's also some disappointment on that path.
I do want to circle back, though, to the idea of motivation. What are some motivations that you've seen for rewriting code? And what are some that you've found compelling or where you think kind of justified it? And what are some that you found sort of less compelling? Yeah. So I mentioned the idea of ability to innovate and if your existing code is like a real barrier to that and that is a need for your business, for your product to continue to survive. So it's really interesting. You mentioned the...
code being a blocker for innovation. What are some ways that you've seen that the actual code base is a blocker for a team's ability to innovate? Yeah, I think that word is kind of a funny word because I don't even necessarily mean you have to come up with something new, but the idea of like if there is a different, more compelling technology that like you have the choice to choose to adopt it or like pull it in. I think, you know, just building new features could be described as kind of innovating on your product. And if your velocity is...
to for building new features is so slow because of the existing code like that i've seen be drive kind of a motivation towards thinking that a rewrite might help you out there yeah i think so we talked in the previous episode on blockers to working incrementally and some of those can definitely be in your code many of them that were less in the code and they're more of the team or the processes the culture that you've built around So I think those are places where a team might be like, oh, the code is preventing us from iterating faster. And this is where I might want to step back and say, okay, let's actually sit there. Is it actually the code that's preventing you from doing that? Or is it because it takes 24 hours to get a PR review? Or because there's lack of good communication on this team? Or because your test suite takes two hours to run on CI even when it's parallelized? And then those might be some of the actual root cause for the...
the iterations being slower. I think personally, I tend to be a little bit skeptical of claims that the code or the technology is the actual sort of blocking point. In general, I'm a fan of the idea of building with boring technology with a little bit of budget for trying some new things. And sometimes a shiny technology will enable something new or incrementally better than what you're currently doing. But it's rarely the sort of foundational difference to the point where if you have a product in a boring technology, it's usually not worth it.
to go to the shiny new tool even if you get a like slight improvement and i know this is going to make devs on teams around the world very sad to hear me say that because it's we want to work with the new stuff it's it's fun yeah it is fun as the other word that came to mind was flexibility and yeah you know when you have like something totally fresh you're starting from scratch and the world is your oyster you have like infinite but an abundance of flexibility that you don't have when you you know are maybe locked into existing code existing decisions another kind of thought that i had was if you sometimes you know you realize that your entire data model might have been wrong for the problem you're trying to solve and it can be really tempting to want to start from scratch and with a different idea and concept and i think part of the skills that we've developed is figuring out how to move towards that new idea that is maybe more compelling or better suited for this problem as a goal and being comfortable kind of being on that journey and trying to get there but not necessarily saying like okay let's cut our losses entirely and just start something new yeah as you mentioned cutting your losses in some ways a rewrite is declaring technical bankruptcy and trying to start again from fresh i'm curious do you think there's ever a good reason to do that
So I guess we do that kind of in the small when we do something like a spike, right? We're experimenting and we build a thing purely for learning and then we go back and build it for real the right way. I think slightly larger than that, you'll see often when trying out ideas for something more at the product level than just at a feature level, the idea of prototypes. And you have a prototype, maybe you pitch to a bunch of people to do market research or maybe even pitch to investors to get an initial round of funding. But then you might...
scrap that entirely and rewrite the whole thing because the purpose of that prototype was not necessarily to be fully functional working software it was to learn certain things and it did its job and now you can go and write the real thing. I really like that distinction because yeah it's the cost to rewrite is so cheap when you're in those early stages and you're just spiking but yeah like as soon as it's a it's a production application those losses that you would have to cut become like much larger and like we've talked about the value may not may not be worth it in the end. So I feel like I've had a fair amount of experience where things that are full rewrites or rewrite-ish have gone wrong and burned me. But I actually have a story also of the reverse being true. This is a situation where someone came to us with what was effectively a prototype, but slightly more than that, of dubious code quality, no test coverage, written entirely in Express.js, which is sort of the really basic Node.js web framework. And we had a couple of weeks to try to spruce it up and add some extra features and things. And then...
midway through discovered that there were some critical bugs in there. There were some issues with the way the database was structured. It was like corrupting data. Like everything was done on like writing to one table and triggers that overwrote data to another table. And there was no test coverage. So anytime you fix a thing, it would, you could easily like reintroduce a bug.
So we looked at backfilling and test coverage. We looked at a variety of solutions and kind of cobbled something together. But in the end, I think that given that like small bounded amount of time, we would have been able to deliver more value by saying, hey, that's an interesting prototype that you've brought to us. We are going to use that as inspiration and do a fresh write in Rails with some more fully fledged web framework than Express. So you don't have to manually implement a lot of things, especially on tight time deadline. We're going to have tests. It's a language we're more familiar with or a framework that we're more familiar with.
and will structure the database correctly from start using best practices. And it's a conversation that we had pretty early on in that project of like, go, no go, do we rewrite or not? And I argued against rewriting for all the reasons that I talked about on this show. And I think it's the one time where sort of at the end of the two weeks, I look back and I'm like, you know what? I think I may have made the wrong call there. I think that maybe we should have rewritten. And maybe that's just hubris at the end, right? Where I'm like, if I had done the rewrite, I would have looked back and again, thought the opposite. Oh, I made the wrong call there. I should not have rewritten.
But that's one of those times where I'm like, you know what, I think maybe that should have been a rewrite. Yeah, well, thanks for sharing that anecdote and hopefully others learn from our mistakes. But I think the lesson there is that if it's prototype-ish, that's your window of opportunity to rewrite it. Once there are real users of the app, you're generally, like, the more the app has grown and the more users are using it, the bigger your dev team is. So it sort of exponentially increases the cost of a rewrite to the point where it's almost never justifiable. Which is ironic because that's usually the...
driver for why people want to rewrite to begin with so it's always funny to me how paradoxical the solution seems to be yeah you're saying when you've written a prototype all the code is fresh and new so it feels good so you don't want to rewrite and then when the code is big and it's expensive that's when you actually want to because it's gotten gnarly i never thought of it that way on that note shall we wrap up let's wrap up Show notes for this episode can be found at bikeshed.thoughtbot.com. If you enjoyed listening, one really easy way to support the show is to leave us a quick rating or even a review in iTunes. It really helps other folks find the show. If you have any feedback or questions, you can reach us at hosts at bikeshed.fm via email. Thank you so much for listening to The Bike Shed, and we'll see you next week. Bye!