Filler: That Feeling of Dread You Get When You’re About to do Something Stupid
One problem I frequently run into while writing a bit of code is that, while I have The Way The World Should Be mapped out in perfect detail, and I can see all of the possible links and interactions, I will have trouble encoding those ideas in tests because, well, ChildWindow really has to be able to call methods on TopLevelWindow, even though this necessitates a circular dependency which is bad and so on and so forth. (this particular example is kind of lame, but I hope it carries the point)
By this point, I haven’t even actually started coding anything, and I am already feeling squeamish about actually doing it. I have two options: pace around, think, and maybe talk to the smartest guy within arm’s reach about it until an appealing structure presents itself, or I can stop being such a bitch and write the code that gets the job done so that I can get paid.
By now, I have run across the circular reference problem enough times to know exactly what happens if I take the “suck it up” approach: Testing ChildWindow now requires that I construct a TopLevelWindow (which is a much heftier class), which slows my tests down and bloats my test boilerplate. If the objects in question are not implemented in the same language, it is very easy to create a memory leak in this way, and let me tell you, tracking down a reference leak created by a cycle between C++ and Python objects sucks to track down until you’ve done it a few times. (PROTIP: if
gc.get_referrers(o) returns an empty list, your object is being kept alive by something that is not a Python object. This, unfortunately is the happy path for such a scenario)
I think I have a pretty good handle on this particular “oh shit this can go south” situation, but I am always on the lookout for more, and I am very glad for that feeling of dread I get whenever I am about to do something stupid.