ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

What in the world is "Refactoring?"

(1/3) > >>

CodeTRUCKER:
What is Refactoring?

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

FYI - the whole paragraph abve is a link to "www.refactoring.com".

Ok, I read this.  Can someone please translate it into something I can tell my children (and I can understand)?

KynloStephen66515:
simply put

whole new code, for the same results.

kind of like this:


--- ---<b> in HTML will give you bold text

now, if you was to change that to BBCode (the stuff you use here)


--- ---[b] would give you bold text.

Different internal code, same external results.

It could get more technical, but its along those lines :)

mouser:
whoever wrote that is trying too hard to make something sound complicated, kind of like people try to do when they are writing their resume and want to make their job sound important.

When people talk about "refactoring" their code, what they really mean is going back into the code and improving the way it is written (typically without adding functionality).

In other words, it's when you take the time to reorganize your code and use better data structures, and make it work better, and usually make the code cleaner and more stable.

CodeTRUCKER:
Ok, so when an language/IDE advertises it has "excellent refactoring" it is saying that it will rewrite the code I input to make a more concise programming verbiage?

worstje:
I think mouser gave a good description of refactoring. However, as an example, think of a function that does a ton of things: get the data from a website, loops over the characters, tries to extract content, perform calculations, etc. Think of a monster that's multiple screenfuls in length.

Such functions can pretty much always be rewritten to be more understandable. How? By splitting it up into smaller pieces that take care of those other pieces. As a bonus, if you need said functionality in the future, you won't be tempted to copy paste, but can use a simple function-call to the same effect... except any bugs only need to be fixed in a single location. So rather than multiple screenfuls, you'll end up with several smaller functions that (as a general idea) fit on a single screen, easily understandable. And the big monster you had before that suddenly fits on a single screen too (again, as a general idea) with all the different tasks explaining themselves (content = GetWebpage(), number = SearchContentForNumber(content), number += 5)...

Of course, that is a bit too simplified, but that is what it in my experience comes down to.

And regarding 'excellent refactoring' in IDEs... it more-so comes down to for example selecting a few paragraphs of code, and immediately putting it in another function with proper parameters, or other often-used tasks to improve code health.

Navigation

[0] Message Index

[#] Next page

Go to full version