Hacker News new | past | comments | ask | show | jobs | submit login

These are excellent examples of refactoring.

It's strange, however, that the author brings up the absolute necessity of unit tests when refactoring like this, yet says he omitted them for brevity. I've found, however that one of the most difficult and important parts of refactoring is making sure code has proper test coverage, especially when starting with crufty code. It's unlikely that the (not very clean) code he presents came with a thorough set of unit tests.

The first thing I try to do when working with insufficiently tested code is to begin refactoring it into a more testable form. This involves many small steps, and in some cases manual testing to make sure that the automated tests I'm writing are testing the correct thing. I think this article would be better if he moved the parts conducive to that (#6 and #9) to the top and included examples of writing tests (with appropriate mocks).

Further, canvas is a rich and complicated API that is relatively difficult to test against; for this article something simpler might have been more appropriate.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: