473,513 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Refactoring-Feature Article in Better Software Magazine

Refactoring
by C. Keith Ray

Software development on your project has slowed to a crawl. Instead of
adding new features, you and your fellow programmers want to rewrite
the existing code to make it easy to work with again, which of course
frightens product marketing and your boss. How do we get into these
messes? What can we do about it?

Many books and courses teach principles, rules, and guidelines of good
design, but somehow much of the code we write still exhibits traits of
poor design, and poor design slows us down.

Code smells are one such trait of poor design. I will illustrate
several code smells, using real working code from the Mozilla project,
to show you how you can clean up your design by using small refactoring
steps. Then you will be able to identify some of the symptoms of poor
design and understand how it can be incrementally improved.

I've chosen the Mozilla project because it is open source, has a
large code base, and was written over an extended period of time by
people of varying skill levels. It is working code, delivered to
end-users as the Firefox Web browser, the Thunderbird email client, and
various components, libraries, and other applications. I am not a
Mozilla developer, so I am viewing the code with fresh eyes.

Instead of reproducing the actual C++ code from the Mozilla project, I
will translate it into pseudo-code to make it more compact and to let
us ignore various C++ idioms and issues of syntax.

I'm going to start with the code example in Figure 1: the method
GetTextHelper in the class nsAccessibleText. The first two smells
immediately visible are Long Method and Long Parameter List (see the
Code Smells sidebar for the names and descriptions of various code
smells). The original C++ method has twenty-eight lines of text, not
including blank lines. That's not terribly long, but this example
does exhibit some of the same design problems as other Long Methods.

We programmers tend to write Long Methods when we're thinking
procedurally-trying to get all those nagging details right, rather
than moving our thoughts up to a higher level and using abstraction and
composition to divide and conquer the problem. Sometimes a single
programmer writes the Long Method; other times it results from a
sequence of programmers adding one more thing (or one more bug fix) to
what was originally a not-so-Long Method. A Long Method is usually
guilty of several other code smells; eliminating them can often reduce
the Long Method to something reasonable.

To see more: http://www.stickyminds.com/BetterSoftware/magazine.asp

Apr 3 '06 #1
4 1384
"lo*******@gmail.com" <lo*******@gmail.com> writes:
Refactoring
by C. Keith Ray


And it's all about C++

--
Chris.
Apr 3 '06 #2
Chris McDonald opined:
"lo*******@gmail.com" <lo*******@gmail.com> writes:
Refactoring
by C. Keith Ray


And it's all about C++


But it's by *C*. Keith Ray, so it must be OK in c.l.c!

--
Old Grandad is dead but his spirits live on.

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Apr 4 '06 #3
"Vladimir S. Oka" <no****@btopenworld.com> writes:
Chris McDonald opined:
"lo*******@gmail.com" <lo*******@gmail.com> writes:
Refactoring
by C. Keith Ray


And it's all about C++

But it's by *C*. Keith Ray, so it must be OK in c.l.c!


Oh; but was he born in '99?

--
Chris.
Apr 4 '06 #4
Chris McDonald opined:
"Vladimir S. Oka" <no****@btopenworld.com> writes:
Chris McDonald opined:

"lo*******@gmail.com" <lo*******@gmail.com> writes:

Refactoring
by C. Keith Ray

And it's all about C++

But it's by *C*. Keith Ray, so it must be OK in c.l.c!


Oh; but was he born in '99?


Reincarnated, rather, and lovingly known as C99!

--
Be careful of reading health books, you might die of a misprint.
-- Mark Twain

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Apr 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2219
by: Guenther Schmidt | last post by:
Hi, does anyone know a good PHP IDE with refactoring capabilities? Refactoring meaning things like moving methods around from a subclass into the superclass, renaming methods and local...
9
2018
by: Peter Dembinski | last post by:
I am trying to write Master Thesis on refactoring Python code. Where should I look for information? -- http://www.dembiński.prv.pl
4
1548
by: Jack Wright | last post by:
Dear All, I have found some sites on "refactoring" but I would like to know if MS will be integrating some kind of "refactoring" functionality in VS for .Net 2.0? Or do I still have to depend on...
2
2089
by: Sachin Garg | last post by:
Hi, I was trying to find (like many others here) a tool for refactoring C++ code as I have lately been noticing that I spend most of my coding time doing refactoring and some refactoring which...
3
1415
by: Arne Styve | last post by:
Hi, The good old Borland JBuilder has very good support for patterns (GoF) and refactoring. Does such support exsist for VS.NET and C# specifically ? The type of support I'm looking for is to...
8
2000
by: Frank Rizzo | last post by:
I keep hearing this term thrown around. What does it mean in the context of code? Can someone provide a definition and example using concrete code? Thanks.
15
4367
by: Simon Cooke | last post by:
Does anyone know of any tools for refactoring header files? We're using a third party codebase at work, and pretty much every file includes a 50Mb precompiled header file. I'm looking for a tool...
2
1803
by: HendrikLeder | last post by:
Hello everybody :-) Next year I`ll write my diploma in computer science for business (It`s a degree in Germany) and I`ve some questions about the topic. The diploma will handle about refactoring...
13
7910
by: Richard | last post by:
What to do when the best laid plans change and mazes of legacy are abolished, simplified, or built anew for contemporary reality. A preliminary database was developed for tracking material...
4
1624
by: shuisheng | last post by:
Dear All, I have a code developed by former employees. I extract some part of it as below: // definition of class CWNPrimitiveFace, it represent a face class CWNPrimitiveFace : public...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7527
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5090
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.