Refactoring in IntelliJ IDEA, Live by Robert C. Martin (Uncle Bob)
September 12th, 2011 by Eugene ToporovIt’s still over 3 months before the holiday season, but we just got a great present from our long time friend Robert C. Martin (Uncle Bob) — a live refactoring demo performed by the legendary software expert himself. He’s, of course, using IntelliJ IDEA!
Check out this video where Uncle Bob shows some refactoring techniques transforming a “large and ugly” function into a clean and readable piece of Java code, using such refactorings as Rename, Extract Method, Inline Variable, and others. We learn something new every time we watch experts like Uncle Bob.
You can also watch this video on JetBrains TV.
The video is part of the highly recommended “Clean Code” series of educational “code-casts.” More Clean Code videos are available at cleancoders.com.
Robert C. Martin (Uncle Bob) is the Master Craftsman at 8th Light Inc., 8thlight.com.
As a separate note, Robert C. Martin has recently released a new book “The Clean Coder: A Code of Conduct for Professional Programmers” which we think is a must read for every professional software developer.
Enjoy the demo and develop with pleasure!
-The JetBrains Team
Tags: Refactoring

September 12th, 2011 at 10:09 am
since when does idea tell you why you cannot extract a method? or is that only in ultimate edition?
September 12th, 2011 at 10:51 am
Denis,
As far as I remember the warning about multiple output variables has always been there; the “Extract Method Object” refactoring is new in IDEA 8 or 9. This feature behaves exactly the same in IntelliJ IDEA Ultimate and Community Edition.
September 12th, 2011 at 12:57 pm
Refactoring at 10:18 (makeChildFromTag(HtmlTag) ) has two casts: one on method call where element variable is casted to HtmlTag (which is fine) and other one inside method definition which is superfluous since the method is already defined to require parameter of HtmlTag type.
September 12th, 2011 at 11:14 pm
Link to 8thlight.com is broken
September 25th, 2011 at 7:57 am
It takes so long for him to re-type existing code, why didn’t he copy it…
Also, he selects expressions using mouse instead of using “Extend selection”.
November 20th, 2011 at 9:30 pm
Lol, why is this cleaner?
Some changes were nice but I for once prefer to read 1 method with 15lines than 5 methods with 3 lines each…
I really disagree on most of the changes. Most are just “smartass” changes that actually make the code harder to read for not-so-bright programmers.
August 18th, 2012 at 4:21 am
What are the shortcuts for renaming variables and all occurrences without a pop up appearing? I know shift f6, but he is doing without a rename pop up appearing?
August 20th, 2012 at 2:34 am
You need to have option Settings|Editor|Enable in-place mode on.
August 23rd, 2012 at 12:33 am
Hi Anna, i have the : Settings | Editor | Enable in-place checked, if i select some variable and rename it the occurrences are not updated, if i press shift + f6 the pop up appears, what shortcut i need to press when selecting the var? TIA
IDEA 11.1.3, Build IU-117.798
Apple JDK 1.6.023
August 23rd, 2012 at 12:41 am
Oh sorry, it’s working! I did change the setting but didn’t remember when, after restarting idea i got it with the shift + f6, great! Thanks.
November 6th, 2012 at 3:26 pm
So Uncle Bob is still going strong on his function hell frenzy. :/
“Oh heavens, there are boolean flags being set.”
Yes, … let’s solve that by hiding them and creating a class.
“I made this class so that I could put some of these horrible boolean flags into it, taking them out of the local scope and into a slightly larger class scope.”
At least he realizes he is unnecessarily expanding scope.
If somebody can explain me why his changes are considered to be good, please enlighten me. I already discussed the topic in detail after reading his book ‘Clean Code’ on my blog, but still haven’t heard any proper counter arguments yet.
http://whathecode.wordpress.com/2010/12/07/function-hell/
The only argument I somewhat can agree with is smaller functions are easier to test. But creating dozens of functions without thinking twice about the overall design? It gives me the shivers.