Small things for small minds - Grin with cat attached
Previous Entry Next Entry
Small things for small minds Nov. 20th, 2002 05:05 pm
You probably don't realise just how happy finding this is implemented:


can make me ;)

(unless you're a coder ;)

From: kaet
Date: November 20th, 2002 - 09:34 am (Link)
Higher order functions are good.

I've just been implementing a FastCGI library in C, based around a single thread and non-blocking but for one select (like the way Zeus does webserving), and I'd not have been able to do anything like that without the idea of the function pointer stored in a variable and event callback.

The other thing I've been doing, is to implement a theorem-prover to check my students' answers (I'm very naughty at dropping minus signs and the like, most people are better, I set them questions with enough working that many (most?) students can do bigger problems than me without doing any writeos). And in there I was using higher order functions like mapping and filtering which involves passing functions around.

Two different pieces of code it's hard to imagine. One grotty networky thingy written in C, and one high-falootin' theorem prover wirtten in Mercury. But both using higher order functions. I don't think it's often you get a concept like that all the way through that range (even variables-as-we-know-it, for example, don't survive into Mercury).

Sorry, I'm waffling, :).
From: wechsler
Date: November 20th, 2002 - 12:33 pm (Link)
Function pointers, or some analogue thereof, are invaluable. I tended to think of web-coding as less complex, a different order of problem, than the embedded C work I used to do. But now I'm finding that a large well-coded system can use just the same tools, and benefit massively from doing so.

In this case it's allowing me to build a properly modular 'plug and play' system, which will work with whichever modules happen to be present. I can just scan the modules directory, run the init code for each module I find, and thus register display/edit/delete functions for each module - and access them without having to hard-code a switch statement. Almost identical procedures to what I was doing in a £40,000 restoration system a few years ago. Strange how the same techniques propogate.