Skip to search.
testdrivendevelopment · Test-driven Development

Group Information

  • Members: 3502
  • Category: Software
  • Founded: Feb 7, 2002
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

  Messages Help
Advanced
The simplest thing doesn't work   Message List  
Reply Message #31608 of 34997 |
Re: [TDD] The simplest thing doesn't work

Going back to the original post:

> In short, because we wrote simple code in the beginning and didn't think
deeply enough about
> what the needs were, a significant amount of redesign ends up being required,
resulting in a
> lengthy turnaround time for implementing a simple feature. The nice part is
that our tests tell
> us what stuff needs to change. The lousy part is that so many things need to
change. This
> seems to be a frequent occurrence here where something comes up requiring a
day's detour
> to redesign something (and everything around it) that previously seemed just
fine.
>
> I'm thinking the solution is BDUF, but that's a bad word here. Is there a
better solution?

Let's forget about "simple" code (which sounds like it was
"simplistic", which is different.)
You have legacy code. Legacy code will make adding new features incur
unpredictable
amounts of work because the existing code is not well-factored. To
quote Joe Rainsberger:

"In systems with high technical debt, the cost of repaying that
technical debt dominates the cost of a story."

To make the code more well-factored (paying down the technical debt),
whenever you need to integrate a new feature into it, you should pay
close attention to code smells in both the new code and the old code
and consider refactoring to deal with each smell as you recognize it.

You can do refactorings in small safe steps (even in C++) manually.
Very closely follow the instructions in Fowler's book on Refactoring
until you learn them by heart. Eclipse with gcc has a few refactorings
that actually work: Extract Method and Rename. Rename understands
scope, so it is safer than search-and-replace. Extract Method and the
other refactorings in Ecipse might be buggy, so be careful when you
use them. For things like changing a function signature, "lean on the
compiler" to show where changes have to be made.

You also need tests to make sure the refactorings are not damaging the
existing features. Feather's book on working with legacy code has lots
of techniques for adding tests to legacy code.

On a higher level, code smells are violations of good design
principles. For example, the Single Responsibility Principle (SRP)
says there should one purpose for every class / method / module. There
are principles about coupling and cohesion and managing dependencies,
etc. It's often easier to detect a code smell than it is to apply
these abstract principles. "Large Class" and "Large Method" are
remedied by "Extract Class" and "Extract Method/Move Method", though
knowing SRP helps in deciding what parts of a class or method should
be extracted.

Perhaps the most important design principle is "Tell, don't ask": keep
functionality and data together.... bad code often has the
functionality in one place, and gets the data it needs from other
places, creating problems with dependencies and lack of locality --
symptomized by "adding a new feature requires changing lots of code".
The code smells "Shotgun Surgery", "Feature Envy", "Long Parameter
List" are applicable here.

Getting fast feedback will allow more refactoring, which will
(eventually) allow faster development of new features. Try to get
parallel builds happening (distributed compilation). Try to get
smaller source files and smaller header files. Reduce the complexity
of header files - use forward declarations, avoid inline code, try to
keep only one class per header file / source file. Using the "pimpl"
idiom widely can decrease compile time by 10%, but it can also
disguise the "Large Class" and "Feature Envy" code smells.

The advantage of refactoring instead of rewriting, is that you always
have working code. If your manual and automated tests are good, then
you should be able to ship the code, even if it is a half-way state
between a bad design and a good design.

I wrote an article on refactoring legacy C++ code here:
http://www.stickyminds.com/BetterSoftware/magazine.asp?fn=cifea&id=75

I'm also one of the authors of Industrial Logic's elearning
(particularly the C++ content). We have albums and workshops available
in C++ on Code Smells, Refactoring, TDD and microtesting legacy code.

--
C. Keith Ray, IXP Coach, Industrial Logic, Inc.
http://industriallogic.com      866-540-8336 (toll free)
Groove with our Agile Greatest Hits: http://www.industriallogic.com/elearning/
http://agilesolutionspace.blogspot.com/



Sat Aug 22, 2009 7:47 pm

attkeithray
Offline Offline
Send Email Send Email

Message #31608 of 34997 |
Expand Messages Author Sort by Date

Alan, Yes. But do that change gradually. Don't try to make it one huge change. That's too painful and too dangerous. One day you'll suddenly notice that...
George Dinwiddie
gdinwiddie Offline Send Email
Aug 21, 2009
7:10 pm

... Let's forget about "simple" code (which sounds like it was "simplistic", which is different.) You have legacy code. Legacy code will make adding new...
Keith Ray
attkeithray Offline Send Email
Aug 22, 2009
7:48 pm

... The crux of the issue is how do you discover each such new need? How much increase in up front planning will actually eliminate what percentage of these...
Steven Gordon
sfman2k Offline Send Email
Aug 20, 2009
4:39 pm

... Um, how about k*M planning will eliminate M*N work. M*p work remains regardless of approach. ... Yes... ... I was just thinking that myself. Good idea. ...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 20, 2009
4:59 pm

... Consider that it may be in chunks that are too big, and do too much. You may find extractMethod and extractClass to be extraordinarily valuable. ... Or...
George Dinwiddie
gdinwiddie Offline Send Email
Aug 20, 2009
7:09 pm

... We found one that kindof worked, but it made Visual Studio so slow we threw out the product. Most stuff just chokes somewhere in the parsing process. ...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 20, 2009
7:21 pm

... Yes, but I suspect much less frequently. So the gain would be less rework. ... Ah, as it happens I am working on algorithmic stuff in the realm of...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 19, 2009
12:38 pm

I think what you have is a well known (and pretty stable) domain model. Curious, when you do your simplest-thing-first, is it still in line with that of the...
Franz Allan Valencia ...
favs77 Offline Send Email
Aug 19, 2009
3:05 pm

Wow that is intense! Domain model: I don't know about well known except here, but yes it's entirely stable. But I take domain model to mean that which...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 19, 2009
4:24 pm

Pardon, I don't know anything about computational geometry and the whole thing sounds to me like well known mathematical formulas to solve such problems :-) ...
Franz Allan Valencia ...
favs77 Offline Send Email
Aug 19, 2009
4:41 pm

Well that's an easier question to answer. We use the standard algorithms of course. But the problems are much more intricate that just finding the maximum...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 19, 2009
4:49 pm

I see. The reason I asked because from your other replies, it seems as though another cause of what feels like excessive refactoring is due to the changing...
Franz Allan Valencia ...
favs77 Offline Send Email
Aug 19, 2009
5:05 pm

... I suggest considering the domain model to be both that which persists, and the operations performed on that which persists. Bundle both of these into your...
George Dinwiddie
gdinwiddie Offline Send Email
Aug 19, 2009
6:09 pm

I think the solution there is simple - refactoring. TDD is TFD + Refactoring. The make-the-simplest-thing part is in TFD. But as you've probably already ...
Franz Allan Valencia ...
favs77 Offline Send Email
Aug 19, 2009
4:48 am

I'm fairly certain that Alan understands the role that refactoring plays in the TDD cycle. Refactoring doesn't change the behavior of the code. Refactoring...
Adam Sroka
adamjaph Offline Send Email
Aug 19, 2009
5:03 am

Hi Franz, I deleted the first part because it seemed like good advice and I had nothing to add. Question about below: You propose replacing "Big Design Up...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 19, 2009
12:53 pm

[SHORT STORY] By DUF, I mean just an overview of the business rules or the architecture. Just to get the big picture. Or if you want, you can drill down on the...
Franz Allan Valencia ...
favs77 Offline Send Email
Aug 19, 2009
3:00 pm

Hi, Alan, Don't expect to be perfect! 8^) Here is one tip I give to all of my teams. For each new feature, do a quick design session (see pp 69-70 of the...
Gary Brown
gb70840 Offline Send Email
Aug 18, 2009
9:51 pm

... Yes I continually fail to meet that expectation. ... Access violation: "pink book" does not refer to any local objects. Press any key to reboot. ... ...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 19, 2009
1:02 pm

Hello Alan, pink book == Extreme Programming Installed chet co-author pink book ... -- Best regards, Chet Hendrickson...
Chet Hendrickson
suechet Offline Send Email
Aug 19, 2009
1:13 pm

... Hi Alan, One thing you can do to mitigate this, in my experience, is to write both unit tests to drive out the design, and acceptance tests to tell you...
Matt Wynne
mattwynneatf... Offline Send Email
Aug 18, 2009
9:51 pm

Alan, There's quite some distance from BDUF to NoDUF. Perhaps you just need to shift a little bit towards more design. Just enough. If you are saying that you...
Donaldson, John (GEO)
geo_johnfr Offline Send Email
Aug 19, 2009
7:52 am

... Might I humblify that statement just a little: "Tests and refactoring are the best _known_ protection in either case." ... -- twitter.com/olofb ...
Olof Bjarnason
olof.bjarnason@... Send Email
Aug 19, 2009
8:12 am

Humblification accepted ;-) ... From: testdrivendevelopment@yahoogroups.com [mailto:testdrivendevelopment@yahoogroups.com] On Behalf Of Olof Bjarnason Sent: 19...
Donaldson, John (GEO)
geo_johnfr Offline Send Email
Aug 19, 2009
11:28 am

... Could you please reveal the even better but unknown protection? ;-> __________________________________________________________________ Be smarter than...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 19, 2009
12:58 pm

... Yes, BDUF is a bad word here and as a result often prevents us from having reasonable discussions around the idea of doing a bit of up front modeling. It...
Scott Ambler
scottwambler Offline Send Email
Aug 19, 2009
1:13 pm

I don't know why this didn't go through yesterday: ... I've always found incremental design and refactoring to not only give me excellent designs, but do so...
George Dinwiddie
gdinwiddie Offline Send Email
Aug 19, 2009
1:51 pm

It seems to me that in this whole discussion, something pretty fundamental has been forgotten. It could on the other hand be that I have long misunderstood...
extremeprogrammer
extremeprogr... Offline Send Email
Aug 20, 2009
4:32 pm

I understand that, and I claim it is not effective here. IF I develop the new code in isolation, get it to pass, and then refactor mercilessly, that refactor...
Alan Baljeu
alanbaljeu Offline Send Email
Aug 20, 2009
4:53 pm

... What are you saying here ? That you are skipping the 3rd step in the red-green-refactor cycle? ... -- twitter.com/olofb olofb.wordpress.com ...
Olof Bjarnason
olof.bjarnason@... Send Email
Aug 20, 2009
4:56 pm
 First  |  |  Last 
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help