Monday, May 27, 2013

Technical debt paid down, and code better for it

Writing code without unit tests is not a fun place to be, so I've bitten the bullet and paid of the technical debt that was building. I've opted for QUnit as I've used it before and does not suck in other dependencies.


As I've written my tests I've rewritten the code base, which has driven out a better structure for the code in terms of Classes and separation of responsibility across the code.

To make the test harness as close to the live code as possible I used M4 to create a build time include. This allows me to reuse the same HTML across for the test harness, and hopefully avoid any differences in code base.

Although putting in a test harness and unit tests has not delivered any additional functionality, the code is in a much better place to accept changes. The weak point with the tests is user interactions, I expect I will have to face into this as well, though my preference would be to abstract any UI stuff out of the main code base (though it will still need testing!)

The other looming problem is performance, with the initial document complete time going from ~300ms to ~700ms. However I believe that the work I did with M4 could deliver some massive gains here, but that's for next time!




Document Complete Fully Loaded

Load Time First Byte Start Render Speed Index DOM Elements Time Requests Bytes In Time Requests Bytes In
First View 0.692s 0.243s 0.525s 560 33 0.692s 5 9 KB 0.700s 5 10 KB
Repeat View 0.262s 0.000s 0.289s 300 33 0.262s 0 0 KB 0.262s 0 0 KB

No comments: