Donald Knuth Rips On Unit Tests and More
eldavojohn writes "You may be familiar with Donald Knuth from his famous Art of Computer Programming books but he's also the father of TeX and, arguably, one of the founders of open source. There's an interesting interview where he says a lot of stuff I wouldn't have predicted. One of the first surprises to me was that he didn't seem to be a huge proponent of unit tests. I use JUnit to test parts of my projects maybe 200 times a day but Knuth calls that kind of practice a 'waste of time' and claims 'nothing needs to be "mocked up."' He also states that methods to write software to take advantage of parallel programming hardware (like multi-core systems that we've discussed) are too difficult for him to tackle due to ever-changing hardware. He even goes so far as to vent about his unhappiness toward chipmakers for forcing us into the multicore realm. He pitches his idea of 'literate programming' which I must admit I've never heard of but find it intriguing. At the end, he even remarks on his adage that young people shouldn't do things just because they're trendy. Whether you love him or hate him, he sure has some interesting/flame-bait things to say."
Well, not if you do it right.
Sure, breaking out a loop body because "OMG I HATE LONG METHODS" is stupid.
Usually, however, you can identify what you're actually trying to do, and put that into verb form. Then it doesn't matter how many times you call it, the code is nice and legible.
For example, let's say you have a complicated loop that iterates over all the rows in a database, checking various constraints on different columns of each record.
You could do this as one big series of nested loops with switch statements, or you could boil it down to one loop that iterates over the database, which calls a polymorphic method or something with a sensible name like, "isValidBananaSpecies()" or whatever.
The problem comes when the methods begin to become divorced from the logic, and are just put there to tidy away code. Of course, often the reason you're tidying away code is because you're trying to do too many things in one body of code, and then you're actually doing it right, just without realizing it.