DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > What Refactoring Is, And What It Isn’t

What Refactoring Is, And What It Isn’t

Swizec Teller user avatar by
Swizec Teller
·
Apr. 19, 12 · Java Zone · Interview
Like (0)
Save
Tweet
7.22K Views

Join the DZone community and get the full member experience.

Join For Free

Nikos Maravitsas writes about What refactoring is and what it isn’t over at Java Code Geeks.

Sometimes a programmer will come to me and explain that they don’t like the design of something and that “we’re gonna need to do a whole bunch of refactoring” to make it right. Oh Oh. This doesn’t sound good. And it doesn’t sound like refactoring either….

But that other guy before me was stupid! He did it wrong! All wrong! Wah wah wah …

Definitely something I’ve been guilty of throughout my coding career. Even went so far as justifying it in a blogpost where I asked Are you a boyscout coder? The gist of my question was whether clients should be charged for refactoring work or not.

More importantly, what level of refactoring work is on par for getting any work done in a foreign codebase and what’s taking aesthetics too far.

Refactoring, as originally defined by Martin Fowler and Kent Beck, is

A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior… It is a disciplined way to clean up code that minimizes the chances of introducing bugs.

/…/

Refactoring is supposed to be a practice that supports making changes to code. You refactor code before making changes, so that you can confirm your understanding of the code and make it easier and safer to put your change in.

And that’s the gist of it. You are allowed to refactor as much as you want so long as the outside interface doesn’t change and you make the code demonstrably easier to work with in the future. I think any client would be happy to pay for making their development process cheaper.

Nikos goes on to explain how to refactor:

Refactoring is simple. Protect yourself from making mistakes by first writing tests where you can. Make structural changes to the code in small, independent and safe steps, and test the code after each of these steps to ensure that you haven’t changed the behavior – it still works the same, just looks different.

But there’s a difference between refactoring things as you go, just polishing up some function names, changing a variable here and there, making things more readable. Those little things you have to get in order to make everyone’s lives easier before you implement a new feature … and changing the architecture of the whole system.

“Large Scale Refactoring” changes can be ugly. They can take weeks or months (or years) to complete, requiring changes to many different parts of the code. They need to be broken down and released in multiple steps, requiring temporary scaffolding and detours, especially if you are working in short Agile sprints.

This isn’t refactoring!

Call redesigning and/or rewriting what it is – redesigning. If there’s a business case for it, go ahead, if it makes sense to redesign now before things get messy, go ahead. For the sake of yourself and everyone around you, just don’t do these things in the name of Refactoring.

Published at DZone with permission of Swizec Teller, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Major PostgreSQL Features You Should Know About
  • SQL GROUP BY and Functional Dependencies: a Very Useful Feature
  • Are All Kubernetes Ingresses the Same?
  • Blocking Ads on Your Network Using Raspberry Pi 3 + Fedora + Pi-hole

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo