Hacker News new | ask | show | jobs
by jallardice 4596 days ago
The whole problem could have been avoided if the agnostic had just added a simple comment stating that the code intentionally only handles strings of 3 or 4 digits.
3 comments

I really doubt that was the point of the essay. I have seen many a times where different programmer rewrite the entire system and it is not for the lack of proper documentation.
They did. The unit tests covered that piece of functionality. The real issue with the story being why didn't any other the other dev's run the unit tests after making the change?
More fundamentally - why did they change the code in the first place?
Because it was shitty code?
The only thing shitty about it was that it didn't adequately explain the problem it was solving. However, that isn't apparent by looking at the code, the only way we could know that is either by reading/running the tests or asking the original developer. There would be no reason to rewrite until you had a reason.
Except it wasn't.
As far as I see, the behavior of the function is undefined for non-zip strings. There is no 'if digits.size < 3 or digits.size > 5 raise "invalid zip code"' or 'assert(digits.size <= 5 and digits.size >= 3, "invalid zip code")'.

I prefer code to comment in this case. ;)