Vladimir is a mathematician who found his happiness in programming Ruby and Erlang, contributing to open source and being an Evil Martian. Author of AnyCable, TestProf, ActionPolicy and many yet unknown ukulele melodies.View the profile
About the talk
RailsConf 2019 - Terraforming legacy Rails applications by Vladimir Dementyev
Rails has been around for (can you imagine!) about 15 years. Most Rails applications are no longer MVPs, but they grew from MVPs and usually contain a lot of legacy code that "just works."
And this legacy makes shipping new features harder and riskier: the new functionality have to co-exist with the code written years ago, and who knows what will blow up next?
I've been working on legacy codebases for the last few years, and I found turning legacy code into a legendary code to be a very exciting and challenging process.
I want to share the ideas and techniques I apply to make legacy codebases habitable and to prepare a breeding ground for the new features.
Heroin, I can barely see you again. Now that I would not need sunglasses in Minneapolis. No, it's not a typical weather in town the last one for today cuz I from lightning bugs and so I am I writing some stuff mostly Ruby jams sometimes block boss and sometimes tweets. I'm working for a company evil martians. That is based in Brooklyn New York and Moscow Russia and you probably heard about our open source projects and there are just a few of them which have their own stickers. And now you may be right out block
by the way, that's a brand new boss of Mine released on Monday regarding real steaks and some pictures of it. That's all the funny stuff we do and that's fine stuff is commercial development and they stalk is most about this part of my life to working with clients applications. We working on could be divided into two groups on the most. I like most as they're probably going to have to build from scratch build something you when you have a convulsion you can't do anything but that's a
rare case cases were doing was Legacy project. And that means that we have to fix on hand something that builds someone else and it's doesn't look so shiny. So but I like it anyway, so that's kind of my Jam. What is a legacy project? So I just want to say that but my personal experience Legacy project at 2 years old if that's when that's when you have a bunch of technical to happen and then it best when you don't remember why you wrote this girl 2 years ago. And
everything later, I'm the first one who drawings of Prozac to start working on it. And that's one of my first task is to prepare the code base for others to join actually start working on features that can just drop Hansel developers on a new project and make them. Because well, that's what I am talking about. Why and what to do instead is about the process of dealing with Legacy rails, but you can particular application so that came up during my years at table Martian and a sandwich to three years to
make it easier. That's when I got to talk about today the 1st at at me that one more thing about myself. I'm at BoardGameGeek. I'm a big fan of board games strategy want that's my best shot. If you probably found the title this talk a little bit familiar and I went to cover image. That's not actually the title to Talking Ben rice has inspired by the board game called terraforming Mars. It's got to be pretty new games 2016, but it's for a long time with Board Game Geek website. Now, you should definitely check it out. If you like board games do they have to tell the game
is to make Mars habitable to bring people that from overpopulated Earth and you're in the game you do a lot of stuff like raising extra oxygen level restoring all transplant ingredients and and so long since fallen so far. So once was I was playing this game with my friends the Legacy projects when we start working on that so I come to this thing like terraforming go up there for me application. That's actually what are some of the process of transforming the Legacy code base into habitable, which means that it's a good place to develop new features. You don't expect some hidden dangers
anywhere. It's such a good place to work out to work with So let's start playing this game every game starts with a setup face when you just take everything from the box and you know put on the board on the table and sometimes this process is longer than the game itself and it's not that fine, but it's usually made by one person. I would maybe couple of that with usually want so that's the first thing I'm doing I'm sending out the Project's development. So that's it could take some time and the girl this first space Landing phase is to make it easier to
minimize the number of actions to an amount of time and Squire to start running Royale server luckyleo rail fence or whatever. Let's talk about development alarm at first by development environment. I mean, how old are external things like system dependent phase databases anything not related to Ruby in particular, but we have what we need. roommate application up and running and usually we did something like a basin Project Read me just a bunch of things. Is it up two dates
copy and paste them in your terminal fingers crossed so too much effort and to error-prone. That's why the first thing I do when I'm the project and configuring better configuration better development environment as I think so, Are opinionated about this yet. So musical styles like Duck are and containers and all this is and by the way, I don't think I got to see it. But yeah, it does enough people to school. Am I going to share some major development table and predictable environment it out. So
it's no rush and managers. I'm not using Airbnb for every a.m. Or whatever we M4. I'll forever and ever so I'll just joking Hazard found Docker compose file and that's it allows you to stay in sync with your development environment. So you don't need to update images manually. You just keep changes from the repository. The next time you were on the project. Everything is revealed on you images of food, and you just using what you want to use. You don't need to worry about having different and why am I? Different branches just kind of side effects of this but you
still need to add some convention on it was rushing for example, because you don't have to use latest tech for everything else file. That's where things break. You should have some understanding policy. Well, most popular one is that it's so slow and Mac so cuz you might see how maybe not sorry. I don't say this is Mac as 5 1/2 years old and we just hatin from everybody went from me. It has followed to get Buy's around. Yes, and I'm telling you. There is good enough for developing rails
applications. You just need to take care of you in a little bit so that I have a few tricks like using cast folders all the Ephemeral staff and volumes using NFS file system, which is tricky, but if you need very good performance, you can try it. We don't use it. Actually what an elk can't tell you whether is Yucca good enough for Windows. Sorry. I have no idea about it. Let me add Sherry you want to add that we used to make a development process a little bit easier if we just called you probably haven't heard about it. Let's go
online to read everything. That's how you know, which is more important multiple Docker compose file. So it's kind of provided transparent way. You can figure the cold application cuz it's enough maybe multiple services from one place and it has a useful provision Coke and integration which allows you to run all commands from your console without pretending that was kind of Docker compose or whatever stop displaying the railsea and under Under codes, it will run a container and make it work within a container. So
what are some environmental filtration stop? I figured out what their environment and we are ready to run our applications. So what's going to happen tomorrow you think? Well usually ends history of Space Engineering. Paris Lounge fails reasons but usually they relate to configuration problems. Like, you know, why does someone use database not unlock a house, right? We just are coded everywhere and out code base all the same as red. As for example, we can add and variables everywhere in our code base and don't add them into several configuration. For example of
something that is The goal is to try to fix it. But I fix I mean to follow this principle. So at a sensible defaults minimizing number of external dependencies like API services and other stuff and keeping configuration organized. I'm sensible default means having Saturday. Alexander have change don't have to change it. So you don't have to see this change me or ask me. What is an example configuration files don't have this example configuration file sexually because every wire change the
developer have to major in the project lead to an error to fail her and that could lead to message in slack your man help me. I know what to do. I don't want to be distracted as a family test ballast. So that's why I'm caring about making this process smooth and again coming back to come free with it because you have this configuration file and you have to configure services and give them now where to find each other but other things like external defenses just like for example AWS for storage service
you kind of just can't figure 8 in the repository. Maybe you can but I don't think it's a good idea. Instead I suggest using local service. You don't have credentials for AWS. It doesn't make sense. At least for the first time you working with a project to have everything that you haven't production configured locally. Maybe later you ask me and I'll tell you the credentials. But for the first time you don't need it, especially if it don't work on that part of a vacation or maybe front end developer all the same thing as external IP address
API is not as you're in your hot bath. It's kind of stuff in your application. Just make it now verbal in development by default. First developers to search for condensed milk found where in the vehicle and get whatever I can help. And other places let's talk about how to keep configuration organized a little bit. Since I was a problem I go to an angel and so let's make a situation where an and rails application. There is a lot of variables across the Hulk on
base and Elsa environment checks. I can't production and development and whatever that's so good. And I'm just time to build a laser work of what is going on in your applications and Aunt checks. For example, especially painful when we want to add a custom environments. Then you have to add that everywhere. So that's why we Lemon balm users only two configuration files like development Arby application rvm salon. And will you remove all day and checks was in her place and was custom configuration stating that makes it more readable.
And is it to kind of figure you can even change this setting and production if you want to enable for a while and not to lie on the environment named itself, which doesn't make sense at all. And to make it work through easier to do with this refectory. I will build a castle move a cup cup which detects this unsafe environment variables usage and also later prevent others from doing this when we add this to our CI. Another problem. It's kind of. I'm specific about that gas must have you used for something like this right as you can.
Well if it's half of you and this is a problem and file could be really really big. Enter now that looks like I'm working with the worst applications in the world because I'm here and somewhere else 15 to hack 108 production has become even more, you know, having my location means you don't know what's going on. You need to change something you have to spend a lot of time looking for it. That's why I was thinking about a better way to keep configuration
and rails application and they came up as a Foley. So we have different types of credentials on parameters. So actually have sensitive information. Let's go with secrets and non-samsung device called just configuration settings and we keep them in different places. We can use shells and store our secrets right in their repo just for sensitive data like API Keys secret key base or whatever we can keep anything else which doesn't have any better you like crying. I'm back at 9 a.m. For example that make sense.
You know how it's time for your CD and we can keep it in named ymail config and one thing that we want to have the ability to override any configuration through and if we really need to do to avoid this step of comedian and pushing just changing the environment interaction. One fact about credentials. So on Route 6A got better. Now, we have ability to store fair environment that shows different sets for different environments. And that's actually what the move make meat made me move to this kind of conflagration sit out. I'm using
them cold anyway, see because it handles all the complexity of fetching data for different starches and hide us from you because you don't have to care about it. You can't override anything through and if you want you can override for clam shells or you can just stay start store everything in plain. Yml file rails concert four methods all you can be used with names and glass base configuration which provide additional with you. So check this out if you experience the kind of
hell. Let's stop with this setup face. Finally. We start playing the game, right? So we on Mars and we ready for terraforming and starts with atmosphere in our game and I confirm an atmosphere was test was your test Suite if you have in your application West help so because of a reason actually because I'll bring it without are you will die eventually ratified Fein are kind of effort and running slow jazz require more time you wasting time really fast, like, you know, you're
in real life. So we're space-themed City by breeding there is kind of complicated. You can't believe to unexpected. Consequences. The goal is to make that's reliable and fast do not block the development. Okay, you're probably going to raise your hand everyone. Let me show you I could help you. Actually that will help you to fix this problem a little bit of fast, and this just called is probably heard about it through bi-weekly a few times. What is it
or tool box is actually a collection of different profilers and extensions for test Frameworks even rubico cups to make it easier to factor test to make them faster. So that meant to be used with Legacy cabezas. Actually, it was boring production. So if that's environment protection, so we use another project. We need it to spit out. That's because not because I would like around time actually because I was GI Bill time. It was really really bad and at the end.
Play speed by a factor of 4 and finally we expected it to a gentle test prop. So. How did we do that how we improved out that sweet speed? Well, it started with a choir sutox. Not just a cop that we have left here so I can hopefully I already told about it a few times to the previous year and that's the last one from the Paris RB last timer. Test if hours just to show you that idea behind us improvements. And the first one I liked it must because I just tell The Talk cast really good job, but
it still had this idea of maybe you still need that if it's cleaner well night and I pretended you don't. Especially in newer else it's going to be no need by default because the only problem is why we need That Bass clean or was that system taskbar task to use multiple France and he tried using phone connection in which he couldn't use his actual test for sectional take service use the same connection all frats and we can use transactions and wrote him back
transaction is a fastest and more. Best way to clean up your data. So just use transactional test everywhere and you don't need it. If you're running all the rails even rails 3.2. You can use Bass Pro patch from this package. So it's doing pretty much the same. That's what we used before rails 5 actually. As a problem. If she's quite popular in lightning background jobs in fast by default. Also called psychic Shane. I like this. So. Betty ASG, that's you running all the job by default in lining them in task. Anyways a lot
of time because you have to sterilize the dropped argument actually have to use a few job and my case if you don't need it well in some cases you test my ReliOn in lining. Well just mark them as dependent on sidekick in line for example, using shared contacts for arts. And that's why we had the same problem and I had to ride Another definition to a not going to talk about it today and it's describing this past but it allows you to automatically Mark all the tests which requires and lion psychic online background check with this share contacts and just refactor
everything in freestyles. Not a problem factories. So most people use factories and doesn't matter with it affects regrow actually all fabrication. For example, you still have this problem with extra cascais likely I'm going on record actually involves creating by Breakers or maybe Jose and maybe 2,000 a records. That's so Coat Factory Kaskade. And it's very expensive to create active record object Studio validation. Subject gray shots. Go back to all that stuff not even database calls.
Again, I'm navigating you to Martian Chronicles desperate bar to lock box, which describes how to detect this stuff and how to fix it. And much more things you can read and official documentation website where you can find links to the false and two video talks. It's already told that there was talk about this and I recommend to take a look because it's on the main problems with flagyl test and rails application. I prepared but I'm not going to share with the whole guidance here by the plugin has
checklist. It's available on the website with some will depart what you should take care of what I want to tell hear something new which is the two I was just so it shouldn't be there a story OK and this one star that that's why I was looking for it. So the tool I roll through something else is working title. It's not that good Bachelor lanter what is so it's just one particular problem when you have a unique constraint in your database, but he don't have a proper Randomness in your factories. So even using
Faker for example figure is not for Randomness is just for a few more readable Bailey's something some people suggest not using it at all the test, but I like it because I want to see human-readable stop in my playlist screenshots of a system test unique constraint attributes. You should use sequence. I have to guarantee that's your test won't fail someday just wants maybe a year, but that's could be annoying. That's what this tool does the analyze factories and compare the database and show
you show you where you have this problem. okay, where is the point where I will test not only green but they're not blocking our development of that they kind of Fast fast enough and they do nuts have a lot of like an ass and it's actually ready to bring more people to the projects, but they're forming process hasn't been complete. So can all the terraforming Mars starts with red Mars. Then it's blue Mars where we eat now and then it's green Mars and it's a green Mars. We first of all need to see this cat.
That's like to drink water. Actually, we need to turn ice into water ice on Mars. You know, that means to bring the project to healthy state has a lot of child from Security Academy, New Breed. This room and performance and consistency. So I got to repeat a few security points when I talk about security. I'm not talkin about really real security audit which we do but much later must be before shipping major features. And the first place we just do a quick security analysis using samples feels like band eroded
which is great to I'm actually don't know why we don't have it by default in a trail cam filers you probably at it because it helps you to follow their known vulnerabilities. Discovered and ruby gems and you'll be surprised at the almost every other week. The reason you want to be with you and Ruby world of this one. I think I'm not sure. This is a fresh one. Two weeks out my day. And what's good about this Aruba Community when I go to fix this? Fixed the issue is fixed quickly. So you just have to upgrade
to buy to return unused safe to go. Another Tales to check your application called as well known break until we should scan your code for bad patterns, like using Firearms directly in your fuse. For example on your signal strength Aquarius. And if I don't leave until it's actually not formatting to also be used to check your application post insecure a dangerous rubico, like a sample of Lima Road and set and so on so forth can just run Security Department for real coffin check the code base.
That's what about assistance to him. And what are we talking about? Consistency? We usually main database and that case I won't talk about the consistency between database and your business laws like your mother, you're actually validations and associations. Kevin database in inconsistent stain comparing two small doses easier the most popular problem as I know you have us stream type which is in your migration and you don't have a laugh of the day SHINee your model that could lead to exceptions that you don't want to see it. If you
probably want cash control 500 error to your uterus. That's not good and hopefully there is a tool because well if you know how to do this manually you'd probably build it. So for that and there it is, it called a Basement Systems here about 5 text different text and analyze your mottos at your brother's motels and your database schema and she'll sound inconsistency. For example, you're having a presence validation by you don't have no false come straight in your database, which means that in your database.
All this Row for this column in the row, but from the terms of your application is his embarrassed that could lay it again to undefined method formula example. And another Jam which kind of companion for this database consistency code database validations differently. It's replace rails building that's like belongs to UNI consolidation with database back to versions and he checked that the corresponding foreign keys are present and that you need to be index is present
if you check in for your neck, so it's got to make sure that you're not just describing your logic and your application by ulcer in the database. Consistency you can just keep this question that's called style matter, you know. I'm a big fan of consistent cost to have a Rubicon and all that stuff. I've been using it since early days, but I'm not sure that's a good idea to just added Rubicon fix it when you project to old new projects and you know right now to correct and just push this had to pull request to make
of you are subscribed to don't have it. I will don't follow the rules and stepped we using to live a different thing. So we have a Soto Street configuration sweet mouth. It just enforce a small subset of goats for sale in everything by default and they only those we want to enforce like Security Department some Lynn and testing cops as well like to voice foccus test and bills to not make a spring that test fast, but they actually not trying everything.
That's a big brother. And we always enforce this street. We work out the check and I'll show you prevent deployments Progressive enhancement, which mean that we Add Rubik's Cube Check user pick up checks only for terraform card. So then you lose weight and called by ours or refactor code that we already fixed. That means that we explicitly Define the files to include into a check which could be tricky depends on your user Channel case. We just have a kind of
isolated namespace. Every functionality has been put into but you do Amal DeLand best configuration looks pretty simple another think you look people argue a lot about which topics to choose which style to choose don't do that use standard. So generous kind of new think it's still not why I'm quite all but I think it's going to be white but always going to be my fault you were just tired and use it to every why it has a pretty good base configuration for Rubicon if you can use it as Standalone or as I show here you can integrate of his
yoke system to backup configuration and Does that mean standard don't argue about Coastal? Let's make it consistent between different products. I don't think that wants to eliminate of June. This face is side effect. What kind of side effects? Well, I don't know about only the one of its not Adam actions actions. I know what I mean here so and database transaction broker to pee but you can break it at that location level by doing some non not safe operation stronger than transactions like performing HTTP
calls or thank you in background jobs sign in emails best a typical example. So we we don't know that's a call back after create, and that case and we will send an email to use your given our transaction will not be committed. So that's not a good idea. And in the best case, we just will have an exception somewhere in the sound system and the worst case we will have something really strange is going to be talked to the Bogen find the cause of it. So how to deal with this again one more to do after your bookmarks,
so I want to download to call guys later. Epic Centigrade into different around Frameworks not only active record and it tries to detect dangerous separation from within 50 feet and so on so forth. So I could raise an exception. For example, we use it and fast it were supposed to understand transactional feature. So it's good to use the all you can configure 8 to send notifications to your error notifying system. For example So that's another way to make sure the project is kind of a safe and stable. It doesn't have unpredictable stuff in it. Wellness think I want talk about is
Death code. A white sew it also at some overhead of working with new project because well, for example, you have a debt templates and they working on some templating related feature get on now, whether you have to fix it everywhere and every time played on maybe most of them are dead and now she didn't use her anymore. That's my stupid situation place. I usually left and not only beautiful place. We always have problem with his unused jams, for example, and Wednesday file can say is you know several.
It's going to be easy to just take a look and figure out which one could be remote ones are more than 100. You probably need some help. Tracking Which gems are used to every child not turn out to be kind of complex top. I try different approaches and the best one and the fastest one while the best ones probably would be amusing price point but that's going to be you going to run your tests for example for multiple days and they throw shoes location tracing and ideas to show the damn switch haven't left any
trace and the object face. So that's how I try to tax on used bounce. Yeah, that's totally worth it, the less accurate the results and there are some interesting stuff like from space collection of gems that it requires but doesn't have anything inside itself. But yeah, you can just well for my case out of 132 jams. I had a list of 20 that would be Splendid chance. I can check my Broken controllers sofa lamp with Dad wrote or dad control erections. There was a pretty good and pretty old eight-years-old actually damn cold Trace Road by its works perfectly. Just run it from time to time
and see what's going on in your code base. Animation from my experience. The biggest problem is a few template and ask him out. There is no Netflix. Well maintained down for that. There was one called Flat food or something like that, but it doesn't look up to date. It will probably not work with no reason Resurgence. That's how I got to write a simple implementation again to use that as you noticed. I am mostly using fast not actually surround test but to analyze the code base stats and approach I'm using a lot and development
and used to partials and Towneplace as well. And then something new while I was here in Minneapolis a friend of mine. Send me a link to his new work affects retrace. So this Jam tracks and use factories and Factory traits with X revolve because well you don't need anymore. So that's a no face cream. So our planets palomares looks much more like Earth right about a thousand years ago because we still need to rebuild a civilization, but that's a whole different started.
Can you would like to tell you a few minutes? Yeah, that's enough a little bit more stuff. So we're ready to bring humans on Mars and well we can bring down all the humans about robots because robots could do all the dirty stuff. We don't want to do. And I want to share some to tools. We actually use up again almost everywhere and that's where I found very useful as Call left hook. And music might see it's a good cook manager Yeah Yeahs again. What makes it different from others? First of all, it's kind of a platform language
whatever agnostic While most popular books written for political languages, like now JSO Ruby. This one is not in a language which compiles into binary. I don't want to call the name of the same with you. Probably figure out it and I could be used well pretty much everywhere. Yeah. This is evil martians projects, but it's kind of a project build by the whole team because we were thinking about the shirts and we wanted to build something to be useful for everyone. So it has some things like Stacks to make it possible to disable sound features
some checks for for example, front end developers run only front and back ends on the back and hooks bait to use the same configuration, but they can disable sound things. Luckily. It integrates was darker again and it's cool. We going on now since a little bit later, but you can start using it. Just one more. And another to every like it's called danger. It's not the new one. But it's turned out began. Where are useful. It took helps you to automate gold reviews and actually a spy from the name. It makes call you in
less danger. You don't have to waste time for roofing tacks for for example. You don't need to check whether their schema RB file has been updated when migrations have been at it. This could be done automatically by Space robot and you can focus only on think that matters you can tell you that all GFI luck has been chance check with what has been changing there some other stuff. So you see that a lot of messages weekend. So that's pretty much get the final round landed and we ready to calculate the final scores. So as a result of this
work on Legacy application, so not only this dog came up but I also was repository everything imagine here and some more stuff and it's going to be more and more stuff in there is I just started working on it. So everything I told you about today is available and keep top. So you feel free to start terraforming Yu-Gi-Oh Legacy applications today. I'm not sorry. I just have to do that. Yeah. I'm trying to ride a lot of stuff these days but swell with this conference and whatever. I'm just keeping free draft switch related to this topic was going to be released in the next few miles. Special
Buy this talk
Access to all the recordings of the event
Buy this video
With ConferenceCast.tv, you get access to our library of the world's best conference talks.