Is this functional code?

-

I’m an Object Oriented (OO) kind of guy, maybe a bigot. I have read a very large num­ber of OO books and I’ve writ­ten a fair amount of OO code in my 10+ years in this in­dus­try. I’m afraid my mind is wired for OO at this point, for good or bad.

Recently, I’ve been get­ting in­ter­ested in func­tional lan­guages. The most func­tional guys around here are Wes and Luke, while Dr. T has some­how tran­scended the whole thing.

Here is the text of one of my new­bie emails to Dr.T. I’ll let you think about it for a bit be­fore post­ing his re­ply. The phrase: Is this it?” has to be read as Is this what func­tional pro­gram­ming is all about?”.

/// EMAIL TEXT BELOW

Is this it? I have about four of these delegate tak­ing’ func­tions in my ex­cel addin ….

    delegate bool PredWithPrevious<T>(T value, T previous);
static int CountWithPrevious<T>(IEnumerable<T> en, PredWithPrevious<T> pred) {

int count = 0;
T previous = default(T);
bool isPrevious = false;

foreach (T val in en) {

if (isPrevious)
if (pred(val, previous))
count++;
previous = val;
isPrevious = true;
}
return count;
}

Tags

1 Comment

Comments

Charlie Calvert's Community Bl

2007-02-02T02:52:35Z

Welcome to the twen­ti­eth Community Convergence. I’m Charlie Calvert, the C# Community PM, and this is