Thursday, October 07, 2004

Set Vs. Procedural Logic

I learned something cool today... something that I actually thought I knew before, but when a more difficult application of it presented, I found out that I didn't understand it as well as I thought.

Set logic!

Note to self: whenever a very data centric problem presents, always consider the a set logic solution before a procedural solution.


Richard keeps drilling this into my head -- but today, magically, a small iota actually registered in my brain, and perhaps found a permanent resting place. Set logic is not the traditional way to solve data-centric application problems. "Most developers", as Rich would say, "will consider a procedural approach first." Our brain is accustomed to solving problems as a series of steps, not as chunks, or groups.

For instance, how would you count the number of people in a hospital bed at a give period of time. Most developers (myself included) would do some variation of the following: Find out what time it is, loop over the beds and determine if there is a patient there -- count it if there is a patient ther, don't count it if there isn't. This is a procedure, therfore procedural logic is used to solve the problem.

The alternative... is going to have to wait until tomorrow.

I'm tired (having worked until almost 1:00 AM developing a set logic solution to the hospital bed count probem.

No comments: