Showing posts with label design patterns. Show all posts
Showing posts with label design patterns. Show all posts

Tuesday, July 23, 2013

Tongue leprosy

I'm proud to say I haven't coded any new functionality in the last week. I've been exclusively redesigning and tinkering with old code. The code is looking a lot better, I think, but there are still design problems I don't feel equipped to solve. I have this one case where I can't figure out an elegant way out of a circular definition. I have a sort of abstract factory class Synchronizer which has two subclasses, ResourceSynchronizer and CollectionSynchronizer. As they are separate AMD modules, the subclasses need to import Syncrhonizer in their "define" statements. But then there's no way for Synchronizer to have a getSynchronizer() method that will return an instance of one of the two subclasses. In order to have such a method, it would need to either import the two subclasses in its define statement, completing the circle, or return a Promise to return a subclass, which would make getSynchronizer() undesirably asynchronous.

Another problem I've run into is when I try to separate out a logical chunk from a bloated module and it turns into a seesaw and goes out of control. I'll be happily migrating things and then realize that I've gradually moved everything into the new module. Then I start to wonder if the separation was a good idea in the first place or if the code is just experiencing separation anxiety. On the other hand, the seesawing also doubles as a sifting process; as I move the code back and forth, it seems like it gets cleaner. Maybe if I do it enough, the code will disappear and everything will still work.

I think something's wrong with my tongue. There's a spot on the left side, roughly a centimeter in diameter, that's behaving like it's been severely burned, producing a numb tingly feeling when under the slightest pressure, and hurting when I bite it as hard as I can. I've studied it in a mirror and I think there might be a tiny alien trying to claw its way out. It looks cracked like parched land, and generally unwholesome. Maybe I'm allergic to something. Maybe it's not my tongue at all and it's actually someone foot with athlete's foot.

Thursday, July 18, 2013

Programming your octopus's celibacy

The last few days, I've been reading up on good programming practices, design patterns, object oriented thinking, and how to draw arms, legs and breasts. When later I went back to look at my code, I was somewhat horrified. First of all, there were no breasts in sight. Second, some of the modules were getting a little too friendly with each other. So I've spent most of today trying to rewrite some of the more inappropriately intertwined modules, if they can even be called modules any more. Is an octopus having sex with another octopus still an octopus? It's definitely still half of two octopi, but visualizing separating one out might just give you that aneurysm you've been saving for something more special. Not to mention you might distract the lovers and wind up as part of the brainteaser. The only sane thing to do is to kill them both and start over, using chunks of their dead bodies as raw material.

Turns out, when you've been building stuff for months, it's hard to rewrite it all in the span of a couple of hours. It's kind of like a second pregnancy is at best twice as short as the first; after that you get into all sorts of relativistic paradoxes like Einstein himself showing up to cram that baby back up your vagina, after which one of the twins turns out five years older than the other. I took special relativity in college, I know what I'm talking about.

Hmm, I don't know if it was something I said or wrote or thought, but as soon as I stopped typing a second ago, I knocked a cup of warm water right into my crotch. It didn't feel half bad for the first 5 seconds, but now it feels...wet. And clingy. I may have to take off my pants and put them on backwards.