quotes

Feb 08
Permalink

People often say that one’s design should be modular. Sadly, many people take this as meaning «use modules.» Having modules in a program does not mean that the program is modular. This is generally the point where I whip out the strong coupling and zero-dependency diagrams and beat your brain into submission, but my law school exams have been going pretty well so I’ll try a nicer approach today.

You know what’s modular in the real world? Condoms. They can be used as a contraceptive, they can be used to prevent STDs, they can be used as a barrel plug on paintball guns, they can be used to protect a live gun barrel from moisture when wading through rivers, they can be used to smuggle liquids or powders, and so on. And what makes condoms so modular in the first place?

* Easy to set up. Rip the pack open, unfold, perform task. You should nt have to go through a dozen hoops and fill ten forms to get a working object.

* Simple and general concept. It’s an elastic, impermeable, transparent pocket. Although its primary use (the one it’s optimized for) is prevention of insemination, it is not restricted to doing only that. In the same way, when you design a portion of your game, determine if the code you are writing is not overly restrictive. Perhaps it could be used to do other similar things in other places?

* High availabiliy. Condoms are extremely cheap and easy to get your hands on, which proves they have not been designed by your average software engineer. I can see it now:

«The user will only need one condom to get his thing on, right?
— Right. Singleton?
— Deal.»

The fundamental point to condoms is that you can get as many as you need. If you design your objects in terms of “you only need one” then by design you are restricting reuse.

* Standalone. It doesn’t require other things to work. You don’t have to plug it in. You don’t have to use an Adapter pattern to fill it with distilled vodka. You don’t have to set up a render-target window and you don’t have to run a network thread in the background. Have your objects work on their own, like a condom: a condom needs itself, and an object to be placed around. Your modules should need themselves, and a target task to be placed around.