Friday, December 9, 2016

Refactor

Astute readers may have noticed that the graph I originally posted yesterday demonstrated a bug in the CIS Sampler. Basically, the sampler was not properly ensuring that blocks were only sampled once; that is, it was sampling with replacement. While this is valid in general, the variance computation depends on knowing the number of unread blocks, so it was actually messing up the bounds. It was a fairly easy thing to fix but, in the process of fixing it, I realized that the overall structure of my code is not what it should be. I won't go into details; I'll just state that, if I'm going to make this code public (and I don't know why I wouldn't), I should probably refactor a few things so the object relationships are a bit more clear.

Some of this is the result of porting from C# to Java. I just copied a lot of the code across. I was rather surprised how well this worked; sure the two languages are siblings, sharing C++ as a parent, but I wouldn't have thought that something like three quarters of the statements would copy and compile without any modification at all. Anyway, the stuff that didn't copy was all the LINQ stuff since Java doesn't have comparable functional constructs. Splitting that out into imperative statements compromised the design a bit.

Mostly, though, I'd say it's lack of peer review. I'm used to throwing designs together really quickly at work and then letting the team comment on them. That seems to go faster than trying to get everything exactly right on the first try (and, doing a sort of good job, but still pulling the whole team into a review is the least efficient route). So, in absence of the peer review step, my design has some holes.

Fortunately, it all seems to work and I have a pretty good set of unit tests. Therefore, I should be able to change things around pretty freely and still be able to get it all functioning again quickly.

No comments:

Post a Comment