Tuesday, October 9, 2007

Distilling some information

Did you know that in the US, it is illegal to distill alcohol. Distillation is the process by which we apply a thermal change (either colder or hotter) to separate fluids with different boiling/freezing points from a solution.

In fact, in the US, it's illegal to ferment alcohol unless one happens to be 21. This means that if you, perchance, drop some yeast into a bucket of sugar water then walk away and it ferments out you _might_ have broken the law (if you're 3 years old). More realistically, what about the 13 year old kid who buys unpasteurized cider, and accidentally leaves it in his or her basement for a month. It will most likely ferment out into hard cider.

Even worse, if he decides "Oh, I don't want to get in trouble for having this" and leaves it with his trash, on a cold winter day, it will distill out into applejack, which is a felony. Seems to me the country has some 'splaining to do, Lucy.

As far as an interesting topic for computer science goes, it's interesting to me that so many people don't look beyond the first five lines of code before they believe they understand everything about the function. A good example is the following:

rcopy - Algorithm 1
void *rcopy(void *dst, const void *src, size_t size)
void *ret = dst;

(char*)*(dst++) = (char*)*(src--);
return ret;

and the following algorithm by Paul Lovvik (as published in the Sun Developer's Network, June 2004)

rcopy - Algorithm 2
void *
rcopy(void *dest, const void *src, size_t size) {
int srcIndex = size - 1;
int destIndex = 0;

while (srcIndex >= 0) {
((char *)(dest))[destIndex++] =
((char *)(src))[srcIndex--];
return (dest);
When comparing the two, most pick algorithm 1 as the faster algorithm. On the surface, sure, it does look faster. But Algorithm 2 has two important differences:
1) It is much more readable
2) It has 1 less mathematic operator. This means that in the long run, it's faster by 1 instruction, which can add up if you're reverse copying a few thousand MB.

Ultimately, we need to take some time to just analyze the costs associated with anything in our lives. Whether it be taking the law into our own hands to enjoy some fresh distilled apple jack at 13, or whether it's the obscure cost of an extra comparison within our code, we need to carefully weigh each nugget of information and compare it with who we are and who we want to be.

No comments: