TDD and design methodologies

March 7, 2006 at 1:24 pm

(something I posted on our internal agile alias, in response to a question about how design works in TDD…)


There’s an underlying assumption in software engineering that “more design == better design”, despite that fact that the vast majority of us have worked with baroque systems that answer a bunch of questions that nobody ever asked.

 

The traditional theory is that if you don’t do the up front design, your code will be poorly architected, inflexible, and you’ll be in trouble when you try to maintain it. Which is true. But it’s also true that up-front design – especially the “spend a milestone” type of up-front design – often leads to the same result.

 

The ideal architecture is a minimalist one. It provides all the features that are needed and no features that aren’t needed (I mean “features” in the class method sense, not the user-visible sense)

 

The up-front approach attempts to do that without the data around which features are needed and which ones aren’t needed, which always changes along the way.

 

TDD says, “We’re going to figure out what we need and how to put it together along the way. We know we’re not going to get it exactly right the first time, but with our tests we can refactor as necessary

 

Comments?

Practical Tips For Boosting The Performance Of Windows Forms Apps

March 7, 2006 at 12:18 pm

Practical Tips For Boosting The Performance Of Windows Forms Apps

Over-updating…

February 24, 2006 at 12:23 am

Raymond writes an interesting post about how some programs run faster if you hold down the mouse.


This is a classic situation to get yourself into – I’ve probably seen it 5 times, and hit it again recently.


When we’re burning a DVD, the burn engine calls back into the UI layer so that we can update the progress bar. To give the user a single monotonically-increasing progress bar, we (well, Dean, actually) have to play some games with our progress tracking, which means that sometimes we get progress callbacks once a second, and sometimes we get them 100 times a second.


The progress dialog looks fine, but if you look a profile of the burn, you’ll find that a fair amount of time is being spent in the UI code updating. In this case, it’s not a big deal, but I’ve seen cases where programs are spending 90% of their time updating the UI. That takes a 10 second operation and makes it take 100 seconds, which is pretty bad.


The fix? Well, there are two good ones.


The simplest one is to simply update every <N> calls. I traditionally start with N=10, which is guaranteed to same 90% of the overhead, and usually works fine.


If your callbacks are sporadic – as they are in the DVD Maker case – it works better to timebox the updates. Whenever you update the UI, record the time, and then don’t update it again until a specific time has gone by. I usually find 1/4 second to work well.


 

Resistance to pairing

February 3, 2006 at 11:54 am

Paul wrote an informative response to my post on collaboration.

I’ve just been writing some stuff about where I think our group should go in the future, and I’ve decided to downplay pair programming. Not because I think it’s a bad idea, but more because I think that opinions around it tend to be a bit religious.

Instead, I’ve decided to advocate an open environment where pairing can happen in a natural way

Collaborative development, pair programming, etc.

January 31, 2006 at 3:28 am

There have been some interesting discussion on our internal “agile” alias around pair programming, with some advocates and some skeptics.

I wrote something in response to one of the skeptical posters, who (to paraphrase badly and perhaps miss his point) said that he was an introvert and preferred to work alone. Not that I’m advocating forcing something like pair programming on anybody.

Here’s what I wrote, slightly edited to protect the innocent.

*****

The introvert/extrovert concern is an interesting one. I like to be left alone at times, and I’m also a big fan of flow state.
 
But I’m also pushing for us to *experiment with* pair programming in our next cycle. Why?
 
Well, I’ve been on a lot of projects in my career, and I see the same bad things happening over and over again. Code reviews that don’t happen. Important components that one or fewer people on the team understand. Overly grandiose architectures. Re-inventing the wheel. Solutions looking for problems. Bad bugs that are really expensive.
 
Who is at fault? Well, we are.
 
For example:
 
You’ve just finished adding a new feature, and to do so you had to do a bit of re-architecting to fit it in. Do you ask one of your co-workers to review what you’ve done before you check it in?
 
Reasons you get the review
  1. It’s the right thing to do
Reasons you skip the review
  1. You’re an introvert. Given the choice between personal interaction and working on something new, you usually choose something new.
  2. Your co-worker is also an introvert.
  3. Nobody really understands your code because you’re the only one who works on it, so the review may not give useful feedback
  4. You have to get up, leave your office, find the person, and bring them back. Lots of time, and they may not be there.
  5. You get evaluated on the features you produce and don’t feel review pain because of the bugs in your code.
  6. It’s early/late, and you’re by yourself
  7. You don’t want people to say bad things about your code.
There are a lot of factors pushing you to do the wrong thing, so it’s not surprising that the right thing rarely happens.
 
So what about TDD? Well, I think TDD is a great way to get code that has fewer bugs in it, and I don’t underestimate the value in that. But TDD doesn’t address code maintainability issues – you can still write overly grandiose and poorly factored code using TDD. You can still write code that is inconsistent with code elsewhere in the project, or using the wrong library. You can still spend hours trying to figure out something where the group knowledge could have solved it in 5 minutes. And – as I am chagrined to admit – I can still write code that should be under TDD but isn’t because it wasn’t convenient.
 
I don’t think that collaborative development – by which I mean anything from co-location in a big room to pairing – is a silver bullet that is going to solve all these. But I think that it can make a pretty big dent. And as a company, I think we have to figure out a way to stop producing big legacy codebases that nobody wants to work on.

Flow vs. Collaboration

December 16, 2005 at 1:31 pm

I’ve been talking about some agile techniques with one of my co-workers, and one of his concerns about pair programming or not being in separate offices is that he won’t be able to get into a state of flow in that kind of environment.


My limited experience with working on projects in group settings leads me to believe that the benefit you get from informal collaboration is far more important, but I’d like some more data.


What do you think? Is the lack of time for flow a real issue, and if it is, how do you deal with it? Or do you find that the collaboration is more important.

Review: Working Effectively with Legacy Code

September 30, 2005 at 6:40 pm


I’ve read a number of books about Test-Driven Development. There are a number of new ones, but most of them start with a clean slate where you’re writing code from scratch.


Working Effectively with Legacy Code is different. It starts with the assumption that you already have a codebase that doesn’t have tests and need to figure out how to start adding tests as you work on the existing codebase.


The book is organized into two sections. “The Mechanics of Change” are an introduction to TDD, tools, why you would want to do it, etc. The real meat of the book is the second section, “Changing Software”. Each chapter in this section addresses a different question, such as:



  • I can’t get this class into a test harness

  • This class is too big and I don’t want it to get any bigger

  • We feel overwhelmed. It isn’t going to get any better

And each chapter has a detailed discussion of the problem, the strategy or strategies you might use, and the tradeoffs involved. That last point is pretty important – the Agile community has more than its share of zealots, so there’s a lot of dogmatic advice out there. This book is the opposite – the author has clearly spent a ton of time applying his techniques to real codebases, and there are lots of interesting discussions out there. Even if you aren’t sold on the whole Test-Driven approach, there’s a lot of content that will apply to general refactoring.


This is one of the best books I’ve read in the last few years. Highly recommended.

Classic Programming Resources

September 14, 2005 at 3:30 pm

 

The year was 1979. Or maybe it was 1980. I’d been programming for a couple of years, but didn’t have my own computer. *Nobody* had their own computer. But I did have enough for a magazine subscription.


There were only a few serious choices. BYTE was one choice, but it was – even in those years – not terribly exciting. Another option would have been Dr Dobbs (Full Name – “Dr Dobbs Journal of Computer Calisthenics and Orthodontia“), if I’d know that it existed.


The third option was a publication known as “Creative Computing”. IIRC, I forked out the princely sum of $15.98 for a two year subscription, and never regretted it. Creative had a unique mix of information, entertainment, and irreverence. I kept a few articles over the years, but the majority were tossed out.


Today I came across an archive of computer books of the late 70’s and early 80’s at AtariArchives.org, and among those are 3 “Best of” volumes from Creative Computing.


If you’ve been waiting for a good ASCII art version of Snoopy and Charlie Brown, you can find one. Or, if you need a review of Wumpus 2, you’re in luck.  


Now, help grandad back to his rocking chair, will you?

How To Do A Good Performance Investigation

May 27, 2005 at 8:56 pm

More sage words from Rico…


And a followon

Design question

April 8, 2005 at 1:17 am

You need to design the outside of a fish. What is the first thing you do?


 


 


 


You build a scale model.