Wednesday, July 16, 2014

Coding backwards - a design technique

The worst design formula I ever encountered was by courtesy of a group of interns, ten years ago. When given the problem statement, they proceeded to convert the top level business entity names into classes and the verbs into their methods. Needless to say, what came out of the exercise was an abomination: it looked beautifully elegant as a class diagram, but lacking any consideration of how the thing might work at implementation level, it (and the code it inspired) had to be thrown out with prejudice.

I have seen many such formulas over the intervening decade. They all had one thing in common: they were formulas. In that they substitute the hard work, i.e. the thinking, with a series of steps based on some theory (or worse yet, based on a collection of  buzzwords masquerading as a theory). I myself have tried to come up with a few over the years. Not because I dislike thinking, but as I have come to realize, because I hate chaos.

A design technique, in my opinion, should not try to reduce the amount of thinking required. It should instead try to reduce the amount of chaos in the process so that the developer can do his thinking methodically. Here I outline a process that I have been using for the past four years. It has worked equally well with C++ (my mother tongue of ten years), PHP and especially JavaScript (my recently adopted second language).

Tuesday, July 15, 2014

Micro-disassembly of a DVD player

Armed with a Phillips screwdriver, a pair of tweezers and a 300x digital microscope, I decided to delve into the innards of this three year old Chinese-built DVD player. What follows are some of the interesting things I found inside. If you like, you can skip the regular teardown and go straight to the microdisassembly section at the bottom of this article.

The device
The device: a run-of-the-mill DVD player with the usual bells and whistles. Cheap, Chinese and claimed irreparable by the friendly neighborhood repairman.

Step #1 - under the hood
First look under the hood
The first look under the hood. I'm immediately out of my element: being a software engineer, no amount of the likes of me would traditionally be able to screw in a light bulb. Also, growing up in a family that wasn't exactly swimming in cash, we had to make all our purchases count. Taking something apart to satisfy my curiosity and not being able to put Humpty back together again was not an option for me as a child. And so I developed a hardware phobia. In fact, these teardowns are partly an attempt to cure myself of that fear.

But I do have something going for me: first principles and a good deal of reading. Let's see how far that gets me:

Right off the bat, I can see the drive (1), with a Russell Peters disc I need to liberate in the process of taking it apart. Everything connects to what is obviously the main board (3). Going by how they align with the various bits on the outside, I can identify: the surround sound outputs (2) coming in through it's own little board, as do the microphone/karaoke inputs (4). The USB slot gets its own little connection to the main board (5). Interestingly, the SD card slot seems to connect to a dedicated reader (7). The front panel connects to this (6) board, which I'm guessing houses the buttons, seven-segment displays and whatnot.