3 ms·
> My first stab at debugging a sort-function would be to write a unit-test. I applaud your discipline, but I can't help but feel like you're punting at writing
by KirinDave 15y ago
> My first stab at debugging a sort-function would be to write a unit-test.
I applaud your discipline, but I can't help but feel like you're punting at writing code when you say things like this.
And the real problem is that unit tests only reflect your expectations. Unless you're familiar with quicksort, you probably won't know what kind of test to write. You'd have to write a very specific dataset: sort(A) ∃ x: A[x] = A[0]. You're probably not using Quickcheck, and the odds of thinking of writing that specific case are slim.
You have to look at the code to get a sense of where the testable edges should be. And in doing so, you should instantly spot this bug. Anyone who can't see it within 60 seconds would be an instant no hire for any but the most junior positions (if I had any say about it, anyways). Even if they don't know Python, they were told there was a bug.
- bermanoid 15y agoWhile I'd tend to agree with you in general, I'd still say that unfamiliarity with Python is enough to blow a minute fretting over semantics - that is not a particularly "line-noise"-free version of quicksort, there's still a bit of non-algorithmic crap to parse (and worry about). As I mentioned above, there's a potential false-bug based on the empty filter statement handling, which is reliant on Python knowledge (it's not at all obvious [and IMO, not a great idea] that a language would auto-convert an empty list to false, some don't, and that's exactly the type of bug that does show up in the real world...). Bump that to a minute and a half for people that don't do Python, or at least give them a clear assurance that they can assume anything requiring specific Python knowledge is not buggy, and I'd say you're right on, though.