Ben Finney wrote: > Jean-Paul Calderone <[EMAIL PROTECTED]> writes: > >> 1) Write unit tests for your code. Keep writing unit tests until >> you have some that _don't pass_. Then fix your code so that they >> do. When you do further development, write the tests first, then >> implement the code that makes them pass. > > Hear hear. > > Be advised, though, that attempting to apply unit tests to code that > wasn't designed with testing in mind may very quickly reveal a poor > design. [0] If you can't easily test pieces of the code independently, > you probably haven't written those pieces to be loosely coupled and > well-defined. >
I will whole-heartedly admit that my code is probably poorly designed. *shrug* Though, I *do* try to write everything in such a way as to be able to easily re-use it later. When I wrote little things just to help me sysadmin, I learned that was really key to making my life easier. Besides, I am lazy... reuse certainly serves my needs there! :-) > > The moral? Writing unit tests *along with* the functional code will > result in a design that is loosely coupled, and probably > better-defined. Also, hopefully, easy to test :-) > I think I have more to learn on the concept of unit-testing. I have never seen a group push the idea so hard. I have read about unit testing before, and even written tests (in other languages) to test modules of library code that I put together once, but that was about it. I need to, I think, get more "into" the concept, though. It isn't something that I am able to just whip out and go "Hey, a widget unit test! And it works!" probably because of my own lack of practice. > > [0] I have no idea whether this is the case for the OP. It's a very > common symptom that arises from people who are first advised to > introduce tests to their code, though. > It is very likely that it is the case. I am, by all means, what I could consider to be a novice programmer when it comes to anything outside of my little world of PHP. I can write web applications in PHP until the cows come home with little to no problem, and I can play with SQL the same way. But, I seem to have problems when I step out of that little box, and so, that tells me that I need to work harder at it. :-) -- Mike -- http://mail.python.org/mailman/listinfo/python-list