Yesterday's cold kept me delightfully bed-ridden all day. I lay there most of the day, sometimes draped over a chair like a wet towel, sometimes prostrate on the bed like a dead hooker, but always impossibly listless. I ended up reading all day, and I feel a little bit sorry for the book I demolished - Prodigy by Marie Lu - I would have probably enjoyed it more if I'd read it in a non-zombified state. Still, it was enjoyable if not quite enjoyed. It was as expected, not quite as interesting as Legend (the first book in the series). This is pretty typical of dystopian trilogies; the first book is about starting a revolution, earth-shattering realizations, the death of ignorance, and the next N sequels are about war and hypocrisy and all kinds of nonsense dealt with better in books that deal solely with war and hypocrisy. Prodigy did better in that respect than Hunger Games, Divergent, and the Matrix sequels, but it still suffered from the same side-effects.
I learned a new object oriented programming pattern today that provides a cool way to follow the open / closed principle.
In case you don't know, the open / closed principle says that you should design things to be extensible but not modifiable. Meaning you don't want people modifying your diaper design, but you do want people building plugins for it. The original design, once complete, should only modified if something is broken. And this seems to apply on many levels, from objects to systems. Now onto the pattern, called The Visitor.
The Visitor pattern basically has you build in an uber-simple but multi-purpose socket, that you can later build things to plug into. The socket doesn't need to know beforehand exactly what will be plugging into it, a vibrator or the Omega 13 device, it's the job of the Visitor implementor to build plugs for those devices. The result is that once you have the socket set up, you're virtually unlimited in what you can plug into it, without ever modifying the diaper.
Neat, though it seems a bit hacky to me. It appears mostly to be used when you want to take a function that might apply to many different objects, and encapsulate all the variants into an object. This object, which is called a Visitor but should really be called a DirtyDirtySlut, then plugs into those objects and provides a single service, albeit adapted per their needs. So you might have a ShaveVisitor object, that defines 10 different variants of the function visit(): bear.visit(), chicken.visit(), patrickRothfuss.visit(), etc, and when the bear or the chicken decide they need a shave, they call in the ShaveVisitor to visit (shave) them. And of course everyone who shaves, lives in perpetual fear because they have no way of knowing who the ShaveVisitor shaved before them, and because there are rumors going around that there's a new Butthole object which likes to get shaved all the freakin' time. And who wants to be the next one shaved after that?
Showing posts with label object oriented. Show all posts
Showing posts with label object oriented. Show all posts
Saturday, July 20, 2013
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.
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.
Labels:
design patterns,
drawing,
object oriented,
octopi,
octopus,
programming,
relativity
Subscribe to:
Posts (Atom)
