Practical Refactoring - How to clean code in many small steps

Llewellyn Falco · 92K views · 2012 · 1:54:31

Open on YouTube

Software practice, open source & careersTesting, debugging & developer toolsdemo

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about refactoring legacy or deeply nested code and, repeatedly, to argue for committing in very small increments.

Recommended by 4 people across 5 different months, 2013 to 2024.

Why Software Engineering Stack Exchange recommends it

Software Engineering Stack Exchange users link it as an approachable, hands-on demonstration of refactoring legacy code in small commits.

Recommended by 2 people across 2 different months, 2015 to 2022.

What it is

A nearly two-hour live refactoring session by Llewellyn Falco and Woody Zuill, who walk through cleaning up messy legacy code in many tiny, safe steps. It runs on a visible two-minute timer to show how small and frequent commits can be.

What people said

Strong rec Chris Lucian · 2013-01 · Stack Overflow · on “How can I effectively use ApprovalTests on legacy code that requires an appserver to run?”

What in your project are you trying to test? If you want to test Forms with Approval Tests you should figure out a way to separate the dependencies from the application and allow the tests to run only against code. The best approach to this is to begin re-factoring smaller chunks of code into unit testable chunks, then the path to separating the display from the data source and dependencies will reveal itself. This video is good for Legacy Refactoring: [this video] (Watch the whole thing its worth it) This video shows a good way to separate the loading of data out from a project: [LINK]

Strong rec Tone · 2016-05 · Stack Overflow · on “Cleaning up pathologically-nested "if { } else { if { } else { if { ... } } }"”

I'd probably approach it by extracting if blocks to methods, going deeper and deeper. This video gives an idea of what I mean Practical Refactoring [this video] (not my video). I've linked to a relevant time stamp but it's well worth watching the whole video. It gives a walkthrough of refactoring some pretty horrendous code but yours might just beat it.

Strong rec hlovdal · 2024-04 · Stack Overflow · on “git reset head --hard deleted local files”

@Code-Apprentice 5 minutes might even be on the longer side, some argue you should never be more than 2 minutes away from checking in and going home [this video] (an excellent video, well worth watching).

Recommends Timothy Truckle · 2016-11 · Stack Overflow · on “Refactoring java switch statement (blackjack)”

first off all format your code using the auto formatter of your IDE. Then assure that same things have same names allover the code. and by any chance repeated consecutive instructions have same order. reduce the visibility of variables to the smallest possible block. That means if you use the same variable in different branches of your switch declare it there separately (and the only inside the if , else or for block where it is used). then select the content of any block that does not contain other blocks but has more that 1 line. in your IDE find the "extract method" refactoring and start it. It should bring up a dialog, that lets you enter a name for the new method where it also tells how

Recommends Filip Milovanović · 2018-11 · Software Engineering Stack Exchange · on “How can I unit test this code”

I was just about to recommend that book in a comment. I'd also found this YT video to be a great, approachable demonstration of how to refactor legacy code: Practical Refactoring [this video]

Recommends hlovdal · 2022-08 · Stack Overflow · on “When to commit and push to a working remote git repository?”

How small can you make commits? Woody Zuill and Llewellyn Falco postulate that you should never be more than 2 minutes away from checking in and going home [this video] (which does not translate directly to unconditionally commit something every two minutes) and they live up to that by having a big 2 minutes timer on display during their refactoring demo.

Recommends hlovdal · 2022-08 · Stack Overflow · on “VSCode deleting staged commits”

You really, really, **really** need to work on drastically changing your commit frequency! Start by watching the Woody Zuill and Llewellyn Falco's presentation/demo where they postulate that you should **never be more than 2 minutes away from checking in and going home** [this video] . This does not translate directly to unconditionally commit something every two minutes, but your commit frequency should definitely be massively closer to two minutes than two hours, *extremely seldom* days, and **never** weeks.

Recommends hlovdal · 2022-08 · Software Engineering Stack Exchange · on “How much time should you spend planning a commit before writing code?”

Yes, commits should be small. Any commit than "needs" planning is fundamentally wrong. Woody Zuill and Llewellyn Falco has a presentation/demo titled 2 minutes to better code [this video] where they present the idea *"Never be more than 2 minutes away from checking in and going home"* (which does not translate directly to unconditionally commit something every two minutes) and they live up to that by having a big 2 minutes timer on display during their refactoring demo.

Cites thepacker · 2015-01 · Software Engineering Stack Exchange · on “Suggestions on refactoring a poorly written ASP.Net MVC web application”

Maybe this is somehow useful to you, I will present one way I work on legacy code. There are many more like extracting fields first. It depends, it is different for each piece of legacy code. If it doesn't work the first time, go back one hour (revert changes), try it a second and even a third time, you will get experience at that, under which conditions to start that way or another. One working way is: At the first step you should categorize the methods you have, e.g. business, controller, data, ui and sort them within the class to group them. If a method can not be categorized properly, it does to much: Extract smaller methods. categorize these methods too. At the second step I try to redu

Cites hlovdal · 2023-09 · Stack Overflow · on “Git pull in IntelliJ without modifying change list”

I can't commit my as it doesn't fully developed Yes, you can and should! You should stop using git stash [LINK] and instead just check in changes as normal, ordinary commits - although mark them as temporary commits [LINK] . TL;DR Replace git stash push with git commit -am "==== temp ====" and git stash pop with git reset HEAD^ # On the same branch as you did the temp commit above! . So assuming the branch you are working on is named my_feature_branch and you currently have some in progress changes: git switch my_feature_branch git status git add $...WHATEVER_FILES_ARE_MODIFIED... git commit -m "==== before pull of teammate's changes ====" git fetch origin gitk --all & # Optional, but lets y