tags:

views:

540

answers:

14

Expanding this question on how I learnt to pass from problem description to code Two people mentioned TDD.

Would it be good for a starter to get into TDD ( and avoid bad habits in the future ? ) Or would it be too complex for a stage when understand what a programming language is?

A: 

Yes! Definitely.

Andrew Stein
+7  A: 

TDD is meant to be simpler than the "traditional" method (of not testing it till the end) - because the tests clarify what you understand of the problem. If you actually didn't have a clear idea of what the problem was, writing tests is quite hard.

So for a beginner, writing tests gets the thinking juice going in the right direction, which is contractual behaviour, not implementation behaviour.

Chii
A: 

I think it's not good for someone just learning programming. How will that person know what to assert? :P TDD is for design, not for testing. Once a person knows how to program, it'll be a good thing to start studiying the TDD approach.

cruizer
A: 

First you need to understand how to code well. Read, study and practive that until you have a good handle on it. Once you have that, look into test driven design - it's very powerful.

SoloBold
+3  A: 

I wish TDD were around when I was first learning to program, and that I had picked it up before getting so entrenched in the 'old way' such that it's very difficult for me to learn TDD...

Erik Forbes
Valid point as well.
Jon Limjap
I agree. I consider myself a fairly experienced programmer but I am finding the TDD learning curve to be unbelievably steep. It's easy if you're writing a math function library but testing real-world business problems is where TDD seems to come unstuck.
Damien
+1  A: 

it's certainly a lot to take in, but having said that I wish I started out writing unit tests. What would actually have been good was if I had a mentor at my workplace who could have guided my TDD progress. I've been self learning TDD on and off for about a year and there's a lot to cover and the more you do it the more involved it gets, but it's really starting to pay off now for me.

lomaxx
+1  A: 

I think this comment illustrates that it can be a very good thing for beginners to learn straight up.

Geoff
A: 

An important benefit of TDD is defining doneness. In simple algorithmic programming, if you come up with a couple scenarios where correctness is easily asserted, its easy to enumerate them in a unit test and keep coding until they all work.

Sometimes unit testing can be hard for beginners, if there are many dependencies and you start to run into scenarios where mocking objects is necessary.

However, if you can make a simple statement about correctness, and it is easy to type out, then definitely write it down in code.

You may also note that if a simple statement of correctness is not easily described, you may not fully understand your problem.

Good luck...

Nathan Feger
+3  A: 
def self.learn_tdd_and_programming_together?
  if you_have_tdd_mentor_sitting_next_to_you?
    "go for it"
  else
    if language.ruby?
      "it's possible, there is quite a bit of good stuff out 
      there that could give you a chance of learning programming 
      with TDD from the start. It's sort of in the ruby culture"
    elsif language.dot_net?
      "learn TDD after you learn the basics of .NET"  
    end
  end
end
ryw
A: 

It really depends on your definition of a "starter". If by "starter" you mean someone with absolutely no programming background, then no, I don't think TDD is a very good way to start out. A programmer needs to learn the basics (avoiding infinite loops, memory allocation, etc.) before worrying about refactoring and test driven development.

Kevin Pang
Yes, someone that attempts to open Microsoft Word to write code.
OscarRyz
That kind of starter
OscarRyz
+1  A: 

My programming motto is:

  1. Make it run -- the program solves the problem
  2. Make it right -- the program is designed cleanly and there is a small amount of duplication
  3. Make it fast -- optimized (if needed)

Test Driven Development handles the first two.

I think a beginner should be taught TDD so that he knows how to make programs run. IMHO, only then can good design techniques be taught.

jop
A: 

code is code whether it is the thing you're trying to spike out, or a test.

Learning TDD at the very beginning has a lot of value. It's one of those skills that should be a habit. There are a lot of us out there that understand and like the value of tdd but years of programming have instilled some some habits that can be hard to break later on.

As far as TDD being for contract design/code implementation/testing it's all of those things. Will TDD bring you to the perfect code? No, experience and studying the craft will help you mature your coding approaches. But TDD is a very important tool for every developer.

The use of TDD will hopefully help bring you to a design that is testable. And a design that is testable is in theory well encapsulated and should adhere to the open closed principal.

In my opinion as long as people view TDD as something that's a niche tool or is somehow optional while writing code, those people obviously don't get the value of TDD.

+3  A: 

Experiencing TDD Rules All

I also think that ideally TDD would be very helpful in the early stages of learning. In hindsight I know it would of helped me approach the problems in a completely different light.

What I'm perplexed about is that when one is learning, there are so many new concepts being absorbed that confusion can start to set in very early. Therefore, while I do think TDD would be super helpful, I don't think it can be something that's learned successfully by one's self.

Just like anything else in life we tend to learn best when somebody is physically teaching us. Showing us how they approach the problems in a TDD manner can do so much more than reading about it in books or on the web. I mean, this can't hurt but it's not a substitute for a mentor that can truly show you the ropes.

Experiencing TDD is everything so if you can have somebody teach you how to TDD during those early stages, I think learning as a whole would be accelerated beyond what anyone would expect.

Scott Saad
+1  A: 

I think yes. Studies even found that the benefits are largest for beginners. It gives you more guidance for writing the code. You know what the results and behavior should be, and write the tests. Then you write the code. Tests pass. You're done. And you know you're done.

phjr
I'm not sure if I agree. I think it can often take an enormous amount of knowledge and skill to be able to describe a problem as a test.
Damien