Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. Show all posts

Friday, April 11, 2008

Kitchen Remodeling as Computation

I once had an opportunity to observe a kitchen remodel from start to finish, interacting with the general contractor who was heading up the remodel along the way.  And I must say, if you consider yourself to be a competent contractor or handyman and are looking for a career change, all I can say is...consider computer science.

In my limited sample of one well-executed kitchen remodel, I submit that the knowledge and skill set that makes one excel in managing a kitchen remodel are not so different from those required to excel in computer science.  While the generated artifacts are different — cabinets, plumbing, and countertops as opposed to applications, data structures, and algorithms — the thought processes and mindsets toward making high-quality versions of these artifacts are very similar in the two endeavors.  Heck, the term “architecture” is meaningful, and even congruent, in both areas.  That’s got to count for something, right?

As the contractor walked me through what he was doing — start with setting appliances aside, demolish the old kitchen, go on to rough electrical and plumbing, mount the cabinets, [almost] finish the electrical (but not the plumbing), measure out the countertops, paint the area, install the countertops, install the sink, reinstall appliances (or install new ones), and finally finish electrical and plumbing, all with periodic cleanup at appropriate in-between periods — I found that everything made sense, and fell into place in much the same way that variables, subroutines, objects, and modules connect and build upon each other to form useful (and reusable) software.  Indeed, as he explained what was going on (and why), I found that he was using many of the same concepts that computer scientists use in designing, studying, and choosing among algorithms:
  • Priorities: “We need to relocate the refrigerator first so that food storage is disrupted for the least amount of time.”

  • Pre- and post-conditions: “I can’t start the cabinets until we’ve settled the rough electrical and plumbing, since the cabinets might get in the way.”  “The cabinets aren’t right until they’re completely plumb and level from end to end.”

  • Fault tolerance: “It doesn’t make sense to order the countertops until the cabinets are completely laid out — that’s the only time that we’ll know the exact dimensions of the counter surface, since all kinds of adjustments and tweaks might happen during installation.”

  • Scheduling/load balancing/optimization: “There’s no rush to pick out the sink or install the glass panes in the cabinet doors, since you can do that while everything else is going on with plenty of time to spare.”

  • Efficiency: “If we cut the cabinet skin in this way, we’ll be able to use more of it to cover off these areas, with the fewest gaps.”

  • Tradeoffs: “I can make that adjustment if you’d like, but it will delay this next step and cost a little more money.”

  • Side effects: “While we can move the refrigerator, we can’t move the valve that feeds the ice maker. So we’ll need to shift these cabinets a little so that they can accommodate a connector between the fridge and the valve.“

  • Constraints: “The countertop can only go this far through the kitchen pass-through, because the material won’t be strong enough to support itself past that.”
The list goes on — and every step of the way, I saw what was going on and why, and even though one might wish that things would go faster, or that some decisions were easier, I couldn’t help but appreciate how the big picture, and all of the factors involved, really compelled the work to proceed in a certain way.  The contractor might even have been slightly surprised at my demeanor, as he started telling me horror stories of how other jobs got derailed due to unreasonable demands or fickle decision-making.

In the end, it came down to one thing — we were thinking about the task and its components in very much the same way.  Thus, a good contractor would make a good computer scientist.  And, if a computer scientist somehow learned to deal with a nail gun, circular saw, and plumber’s dope, then that computer scientist might make a good contractor!  :)

Let’s take it a step further, in fact — for what endeavors or fields would considerations like those listed above (and numerous others from the computer science realm) not be useful at all?  Of course, I may be biased, but I think one can make a pretty strong case that almost every facet of the human experience would benefit from some kind of computational proficiency — and I mean “computational” in the general computer science sense, not just the numeric manipulation that most folks would associate with the term.  In the end, wasn’t the contractor really “computing” a new kitchen, based on the “input” provided by the homeowner?

A music professor once told me that a quality shared by all good music, regardless of genre, was that it was “logically compelling.”  He didn’t mean that good music was mechanical or overly structured; he meant that good music always seems like it must go to a particular place, and no other destination seems like it would do.  This is what makes pop songs “catchy,” and what gives arrangements an excellent “hook” — when you hear them, the sounds and silences that come before seem destined only to lead to the sounds and silences that come after; anything else would be wrong, or else just not-as-great.

The notion of “logically compelling” certainly resonates with me regarding good software design, both internal (the code’s structure) and external (the user interface).  On both counts, high-quality designs “compel” that code be written in a certain way or that a user’s intuition match what a user interface presents — all because factors such as priorities, pre- and post-conditions, fault tolerance, optimization, tradeoffs, constraints, and other core elements of computation are brought to bear upon a situation.

And now, after observing a kitchen remodel up close, I would say that a well-executed kitchen remodel is also “logically compelling.”  Indeed, if everybody knew a little computer science, how many more day-to-day human activities would share that property — a sensible result due to sensible decisions made based on sensible reasons, with sensible (and acceptable) compromises.  Would you trade some extra time and resources off for that mid-life adjustment?  Or better yet, start ’em young.  After all, I don’t know of anyone who doesn’t appreciate a brand-spanking-new kitchen.  :)

Saturday, December 8, 2007

Learning to Let “Goto”

Have you ever had a conversation like this before:

“So, how do I get from my office to the restaurant?”

“Well, you take the 10 freeway and go east. Then when you hit the 405 interchange, head north.”

“Head north. So stay on the left lane on the off-ramp?”

“No, actually, the right lane.”

“The right lane??? No way. You’re going east on the 10 and so if you want to go north, you’ll have to be on the left.”

“No, the right lane of the off-ramp goes north.”

“That’s impossible. North is on your left when you're going east.”

...and so on. While a conversation such as this might not necessarily have earth-shaking consequences — at worst, this insistent instructee may have to turn around and lose some travel time — it does reflect yet another situation that may be different if more of us knew a little bit more about computer science.

Some may be surprised to realize that the central object of study in computer science is not the computer. On the contrary, the computer is merely a tool for creating, studying, and making use of the real star of computer science: the algorithm.

While there are many formal definitions for an algorithm, in keeping with the “daily life” tone of this blog, let’s stay relatively informal: in essence, an algorithm is a set of instructions. It’s a “how-to,” a “1-2-3,” a “step-by-step guide.” And yes, to borrow yet another catch phrase, in many respects an algorithm is meant “for dummies.”

No, this doesn’t mean computer scientists are dummies — it means that computers are. The “dummy” aspect of algorithms lies not in their discovery, definition, or creation — that‘s squarely in the realm of computer science, and certainly not for “dummies” — but in their execution. An algorithm should include all of the information necessary in order to complete it successfully — no more, no less. And this is why computers are the ideal “algorithm executives” — they rely completely on the information provided by the algorithm, and nothing else. No questions asked. If an algorithm’s instructions will make a computer “freeze,” then the computer will “freeze.” If these instructions will make a computer produce a convincing facsimile of Angelina Jolie playing Grendel’s mother, then that’s exactly what you get.

In other words, computers follow instructions, and the information provided within those instructions, without injecting (or needing) any other information. There is no “insight,” or “intuition,” or “experience,” or “understanding” involved. The bottom line: much as we tend to anthropomorphize computers, they actually operate in a manner that is almost contrary to how we do. One can argue that the previous four concepts — insight, intuition, experience, and understanding — are fundamental to being “human.” And yet, they have nothing to do with the amazing things that computers can accomplish; in fact, they may even get in the way.

Which brings us back to the conversation above: the driving directions being given in that conversation can be viewed as constituting an algorithm — an algorithm for traveling from one’s office to some restaurant. The recipient of this algorithm, however, is a living, breathing human being...who appears to know better. Indeed, prior experience and an understanding of directions does make these directions seem incorrect: north is to your left when you’re going east. So of course it would be the left lane of an offramp that would head north.

Right?

There are two ways to go here: first, one can be “more human” and state that no, the person receiving directions does not actually have enough understanding nor experience. Sometimes, offramps do turn in opposing directions — it just depends on how the roads were built. So it is possible to head north by staying on the right lane on an eastbound offramp.

But wait — the would-be restaurant guest was already being told to stay on the right lane in order to head north on the 405. The issue was that, because said guest had “understanding,” “experience,” and “insight,” he or she was doubting the instructions being given. This guest is human, after all. Had these instructions been given to a computer, then no questions would have been asked, and the computer would have arrived at the restaurant sooner than the human.

Now that you’ve come this far, you might think that this entry is some sort of invective against that which makes us human — if this were The Matrix, I’d be rooting for Agent Smith, or if this were Terminator, I’d be squarely on Arnold’s side. And why not — I’m a computer scientist after all, right?

On the contrary, this entry is actually all about the perks of being human: we have a choice. We can choose to invoke our insight, understanding, and experience...and, when the situation is right, we can also choose not to do so. In the case of the dogged dinnergoer, he or she probably should have recognized that the directions’ provider was authoritative, and his or her instructions should simply be followed. There will be other times to invoke one’s sense of direction or navigation; this probably was not one of them.

With this perspective, you can probably think of some other times when it’s better to just put our “computer faces” on and follow instructions. Even without inborn culinary aptitude, one can probably whip up a decent meal as long as he or she sticks to a good recipe (and executes its instructions correctly). I’m also sure that teachers everywhere have, at one time or another, asked their students to “just please follow the instructions.“ And how many times have negative consequences, ranging from the comic to the tragic, emerged due to a failure to “use as directed?”

A little computer science provides the perspective and the skill set to discern when to invoke our human gifts (i.e., develop the algorithm) and when to simply let go, and follow instructions (i.e., perform the algorithm). There are right and wrong times to behave one way or the other, and for the moment, only a fully-realized human can compute that correctly.