Andy Maleh on Ruby, Rails & Software Craftsmanship | RailsConf 2014

• UGtastic Archive

Andy Maleh on Ruby, Rails & Software Craftsmanship | RailsConf 2014

Loading this player connects your browser to Youtube.

Full Transcript Available
LIVE CC UGtastic Archive

Press play or click any turn in the transcript to start real-time synchronized playback...

📼 FROM THE UGTASTIC ARCHIVE (Recorded on-site at RailsConf 2014) Archival conversation with Andy Maleh recorded on-site at RailsConf Chicago 2014. Recorded during the 2009-2015 software craftsmanship and developer community movements, this archival interview captures early ideas, debates, and community organizing in real time. --- 🏛️ ORAL HISTORY RECORD: • Series: UGtastic Technical Conversation Archive (2009-2015) • Recorded: RailsConf 2014 (2014-04-22) • Guest: Andy Maleh • Interviewer: Mike Hall (UGtastic / https://www.just3ws.com) • Legacy UGtastic Archive ID: QZaSffPuB58 📖 FULL ARCHIVE & ORAL HISTORY: https://www.just3ws.com/interviews/ 🏷️ TOPICS: Andy Maleh, RailsConf 2014, Ruby, Rails, Software Craftsmanship, UGtastic, Mike Hall Restored and preserved by Mike Hall (https://www.just3ws.com)
The Guest

Unattributed voices

UGtastic archive transcript with speaker attribution pending

The Presentation


Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Hi, it's Mike with UGtastic. I'm here at RailsConf 2014, and I'm here with Andy Molle, who did a talk this morning on ultralight and maintainable rails wizards. So, ultralight and maintainable rails wizards, that's a very specific topic. What brought you to wanting to talk about that?
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, I mean, building web wizards is one of the oldest problems of the web. Almost everybody's experienced it, especially, I mean, the oldest example is the shopping cart. Sort of multi-step. Exactly, like basically breaking things down for the user to avoid entering.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Instead of filling in a form that's this large, you break it up into like step one is one page, step two is the second page, step three is the third page. It helps with usability and user experience to avoid people dropping off if they see an overwhelming form. Whereas if you see that many fields only, and you break the problem down for them, then you help them accomplish their goal without leaving your site. And it's a bigger pain to break that than people might realize.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Of course, because it's not just a straight single, you know, page form. The typical, you know, like way you, like the typical Rails MVC thing is, you know, you have a view that has a form. You submit, you submit, if it's a create, you know, you create, otherwise it could be an updating, there's new, there's edit. That's the basic rest.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
That's crazy partial state you have to deal with. Exactly. You have to persist the state across the steps as you go on and on. So, like, you're going to capture, say, the user name and address, next step is maybe more personal details about the user, and then finally maybe payment details, and so on and so forth.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, yeah, so, I mean, my last experience building a wizard was during some Java development, as well as doing some maintenance of some Rails projects. But then two years ago, when I was, when I got commissioned to be a software architect at earlyshares.com to help them launch a new, brand new Rails website, they had two onboarding wizards, one for investors and one for business people, and their needs were kind of tough because they were bootstrapped, so we had, like, time limitations. I only had one junior developer helping me on the project. Right.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
I was brought in as the Rails expert, and also that the design of those wizards was not finalized, so, like, he told, like, the CTO, who was kind of designing or coming up with the requirements, told us, okay, you know, like, the business project, business project contributor onboarding wizard might start with four steps, but we might grow it to nine steps. So, obviously, so, obviously, so, obviously there were needs for flexibility and extensibility that were going to happen really soon. Also, he said, I want you and the junior developer to be productive and work in parallel and finish something fast, and not, like, he didn't want us to block in a way where if I'm, because we did pair programming, but there were occasions where we would just throw things at the junior developer while tackling more difficult architectural problems. So, yeah, it was a pretty tough situation, and it was my first time solving this problem from scratch.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, I mean, at first, I just went online, stack overflow, and Google, whatever, I Googled articles on building wizards with Rails, I Googled gems, thought it was going to be an easy thing. But then, every one I looked at would either be encouraging doing conditional validations on the model, which gets really dirty, meaning, you know, validate the name and address on the first step, but don't validate on the second step. So, you end up with a lot of if L statements or if. And state machine, you'd have to have probably some kind of state machine in there to say, okay, I've updated, now I'm at step two, and then you're doing these.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
That's another approach that I saw at state machine, which the issue with that approach is a lot of, like, the frameworks that would encourage it would end up forcing you to add a column to the database on the model for a presentation concern. That is the wizard that has nothing to do with the actual business domain model. I mean, if I'm just building a project model, me having doing it on the presentation level with four steps or nine steps should not affect how I had that model. I mean, I should just have project work with that.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, yeah, and I mean, there's the session or hidden variable accumulation technique, which is very popular. I don't know if you've ever experienced that one, where you store things on the session every step of the way, and then once you reach the final step of the wizard, you actually. Oh, so you build up a little hash and that sort of stuff there. Exactly.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
You actually grab all of that at the end of the last step and load it to an active record and save it. That issue is just, you know, and it forces you to write fat controllers that manage that session data. Right. I mean, you can also add some of that to, I guess, a submodel or a service object, but I was not satisfied.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
It felt like you're either breaking MVC or breaking REST. Like, one other approach I've seen was on code basis is basically have four controllers, like one per step. Right. Which, and they end up almost looking the same and, like, it's the same code.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
It's very repetitive. So, yeah, it's either, like, you're not dry or you're breaking REST or you're breaking MVC. So, what gives? So, I was really frustrated.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
I'm like, let me solve this from scratch. The CTO was a bit frustrated with me when I was spending some time on this because he's like, why are you trying to invent a new way? Like, just write some straight Braille's MVC code. Like, he was, like, almost encouraged me to, like, write five controllers.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Like, whatever. Who cares? He's like, who cares? Like, we're just a startup.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
I'm like, no, I need to make sure that junior developer can maintain it because I was commissioned for three months only. I mean, it was right before I moved out of Chicago. And, yeah, I told him, you know, I need to make sure future developers maintain it. I need to make sure that I will be able to add steps to it quickly and change it quickly when you ask me to change it because we're still doing tests on the user experience.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
We weren't sure we weren't completely committed to that design, like with any new project. So, fortunately, after one day of me brainstorming and thinking about the problem, I stumbled on a design that seemed to work really well. And the junior developer happily and productively delivered. And then later on, when they brought another senior developer that was remote in Brazil, he liked the approach quite a bit and actually sent me an email congratulating me on it.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, what was the, what's kind of the gist of the approach that you, that you, I'm presuming you talked about this approach in the talk. So, that's what the talk was about. It was pretty much me going, doing a survey of all the older or existing techniques. And then the one I've stumbled about and how it satisfies REST, MVC, OO, and CleanCode principles.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
I have a blog on it on antimalay.blogspot.com. Okay. There's a blog post on it. I plan to release a gem for it soon called Ultralight Wizard.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Okay. I was going to ask, is this something that is more like a pattern or a gem? It's more of a pattern, but I might be able to encode it into Rails generators so that we'd help people by, you know, you just give it the names of the steps and the generates a whole bunch of, like, the bare minimum files needed for it. It's not like a new DSL or something like that.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
There might be some DSL elements involved as well. Okay. There is a gem out there called Wicked that solves part of the problem well, and it's almost the same solution I stumbled on. Okay.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, that was reaffirming when I saw that gem later on. It was not available at the time, but I discovered it, like, a few months later, somebody, I think, came up with that gem. And so, I plan to just fill in the rest of the solution. Yeah.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
And at the very least, it sounds like kind of one of the themes that DHH brought up this morning about reading code is that it's probably a good idea just, even if we don't use your gem, to go and read it and understand how... That's why I recommend just Googling Ultralight and Maintainable Rails Wizards. You'll stumble on my blog post. Okay.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
More about it. It's about code samples. Why? What is actually going on in there?
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Yeah. So, I mean, the gist of it is the following. Okay. So, when I was thinking about the problem, I'm like, people blow it out of proportion when they think of state machines, first of all.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, the moment I was thinking about a state machine, I'm in the computer science domain. I'm not in the business domain anymore. Right. So, I've already separated from the ideas of domain-driven design, which is the whole idea of writing code that is as close as possible to your business concepts so that you can maintain it more easily over time.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, I mean, I didn't like even starting from there. Like, I felt like that was wrong to begin with. So, I figured, what is a wizard really doing? And I asked the audience today that question.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Yeah. It was cool to see what the audience would say. Like, some people said, oh, it's just the wizard's goal is to acquire data. But I asked him, oh, but, you know, a single form would acquire data.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Like, why wizard? And then some people were like, yeah, it breaks it down and organizes it into multiple steps to help the user. So, I'm like, okay. I'm like, okay.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
And what's the end goal? Like, what happens when you finish the wizard? And they're like, it builds an object. I'm like, yeah, bingo.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Basically, a wizard is nothing but the good old builder design pattern or builder. Builder. So, it's a multi-step builder. So, when I thought of it that way, then the next question was, what is a step?
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
And then it turns out a step, if you think of it, forget the code, forget computer science concepts. I mean, that kind of fits with DHH's talk, I guess, today. If you just think about it naturally, it's really just a wizard gives you, at each step, a view into the model at a time. So, if I'm customizing a car that I'm ordering off a site, one step will have me look at the exterior of the car.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, that's one view onto it. Another step is the interior. If I want to customize the leather inside, the color, the dashboard panel, so on and so forth. And then, say, a third step could be the engine.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, really, it's just data views. So, and then I had a few other, like, goals behind my designs. You know, I want to avoid conditionals. I want to avoid having if-else statements in the view.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
I wanted to say things like, if step one, show this field in the form. If step two, show that. So, it ended up being very easy after laying that foundation. It ended up being nothing but two restful resources, basically.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, the main one is project. And then, the second one, every step of the way in the resource is really just a project part. That is a nested resource under project. So, if you have four steps, then you have four project parts.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, the step name is the ID of the project part. So, then the route is nothing but, you know, slash project 51, for example, slash project part, slash step one. Okay. So, it ends up, so then you just have two controllers, one to kick off the wizard, as well as, once the wizard ends, it shows you the landing page of the project or the final confirmation page.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
It's a shopping cart. And then, the second wizard is the one that edits project parts. That one only has edit and update on it, and it walks you through each step. But, it reads them all the same, because all it is, it's just a different ID for each step.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, then what you do is render each step's page polymorphically based on the step name. So, instead of rendering an edit view, you would just render the ID of the project part, which ends up being step one dot html dot erb, step two dot html dot erb. So, yeah, basic info dot html dot erb, details dot html dot erb, documents dot html dot erb. So, you're able to gradually reveal the implementation of a full instance of that final object in piecemeal form.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Yeah, like, so you end up being able to maintain the views separately, very cleanly, so each view has its own form. The beauty of it is that it's simple, though, because all of them have their form links to the same model, so it's just project. But, you're just editing a different part at every time. Now, the second challenge that I need to overcome is how do you deal with validations on each step?
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, the solution that I just stumbled upon, like, while trying to solve that problem very quickly, is create four presenters for project, where each one gives you a data view of, representing a data view of one step on the project. So, that's, like, the presenter pattern or view model pattern. And it includes the validations for that step only. So, then you're able to segregate, so then the project model has associations, any common business validations and rules, but then you can separate specific validations on each step onto the steps.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, you can, and then in order for those steps to read the project data, I just cheated and had them extend project. So, like, I had a basic info.rb that was basic info extending project, so it ended up getting automatic access to all the columns of projects. When you write this code, you're writing pure Rails project validation code. You're not writing anything special.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
So, that made it work really well with junior programmers. They didn't have to feel like they're doing crazy domain-driven design, advanced, you know, object-oriented programming stuff. They just wrote Rails validations for each step in a separate file, as well as wrote a different form for each step on a separate view. And then the controller code was uniform.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
It polymorphically loaded the right step presenter, as well as the right step view, based on the step name. And from that point on, yeah. So, it was very dry. We covered a lot of technical stuff here.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
It probably would be best for people to, what was the, what was the term they should go Google for? Ultralight and maintainable Rails wizard. Ultralight and maintainable. And the project that I'm planning to launch it under in GitHub is ultralight wizard.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Which I already, I already created, but it's empty right now. I might actually complete it during this conference. Okay. I already found a potential contributor that will help me, help pair program with me on it.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Oh, great. Well, thank you very much for digging. You're welcome. I appreciate it.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
And just so everybody knows, I'm a Rails developer. Andy's a Rails developer. And Andy was actually my first official trainer when I was converting from being a .NET developer to Rails. And I just want to say that I feel like I've grown in my career like your beer has grown in the world.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
And it's really an honor to be here with you and in the magnificence. Well, you'll always be my young kind of one. All right. But, yeah.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Thanks again. You didn't mention what I do, though. I'm the VP of Engineering with Big Astronaut right now. Oh.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Big Astronaut. A remote software consulting company where we have presence in Chicago, Denver, and Montreal. So, Big Astronaut. Mm-hmm.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Okay. Thank you very much. You're welcome. User groups with lots to say, interviews, and more.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
No way. Sharing great ideas in the tech community. Fascinating conversations. A plethora of information.
Unattributed voices UGtastic archive transcript with speaker attribution pending ▶ Speaking
Find out for yourself today at ugetastic.com. Thank you.