Hacker Newsnew | past | comments | ask | show | jobs | submit | edgo's commentslogin

Unit test are not just for people who write bugs (parent comment), a good start would be to test for the 9th row the problem was asking for. Since you can't test all possible values a representative sample would be good enough.

Just to be pedantic: It's not TDD if he already wrote the functional code ;)


I think that's the point, though. If I were to build this TDD, I would probably make use of the fact that that the value at any point is the sum of the values above it, in the previous row.

I could write a failing test that PT(1) = [1]. I could make it go green easily, and then write a failing test that PT(2) = [1,2,1] and make that pass, using my algorithm. Depending on how much you did in the last step, there may be no more failing tests that you could write. I can imagine maybe one more failing test, but after that you are done.

That's what I meant by "and then there is magic". The "test driven" doesn't really help the "design" at all. Your first test is the trivial case and the second test is "did it work?" I could arguably skip the first test altogether, and whether or not I wrote the second test before I wrote the production code is completely irrelevant because the test doesn't help you write the code.

Now, you might want to "refactor" this to be:

PT(n) = (n.choose(i) for i in [0..n-1])

(This is just pseudo code for a list comprehension that returns an array of n choose i for all the values of i from 0 to n-1). I could then write the code for choose(), but I'm in the same boat -- there is no benefit to writing choose() TDD because your first test will be trivial and you r second test will require the full answer.

While my "refactor" could use the tests I wrote with my "TDD" of PT(), I haven't demonstrated the value of TDD at all because the "refactor" is not related to the tests. I could just have easily written that code first and then written a test to see if it was correct.

Finally, if a bug is introduced to the code, the tests may pick it up, but are almost certain not to shine light on what went wrong because the tests are not related to the design of the code.

This is an excellent example of code that I would not write TDD (and I write 99% of everything TDD). I might not even write it test first depending on my mood.

Trying to be slightly diplomatic, the point of my post was that in all likelihood, a person who gives you this programming problem to demonstrate your TDD abilities has no clue about TDD. The alternative explanation is that they intentionally picked a problem that doesn't work well for TDD and wanted the person to explain why this was a sucky problem.

If you weren't very familiar with TDD, I could imagine this tripping you up pretty badly. You'd think, "what the hell test am I going to write?" As you point out, it doesn't really matter -- you can write any test that will sort of test that your code can grossly come up with the right answer. After that there's not actually anything beneficial you can do.


Code Complete has 960 pages, not in the short book category


I beg to differ. There is always design work, you made design choices and even if they were careless choices you always have a final work that might be great or just poorly designed.


Practice helps if you can learn from the good and bad moves on both sides of the board. The article mentions analysis, have you tried that? Great players draw from a big pool of previous experiences and not only their own.


That's why it is very important to touch the company culture topic during the interview and find out if it's a good match.


This could be improved with natural language processing but I guess it is just a quick and dirty "15 minutes" kind of solution


Maybe, but can it detect sarcasm?

    d59b0a8 - Oh, this shit is case sensitive. Awesome.


He is called out right there in the post: Andy Clarke.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: