rtm@christmas.UUCP (Richard Minner) (11/27/90)
In article <207@thor.UUCP> scjones@thor.UUCP (Larry Jones) writes: >I don't know about Doug, but *I* sure reguard callbacks as both tangled >control structures and unstructured braches. In fact, they seem to be >very closely related to the "altered goto" which seem to be held in more >or less universal contempt. Mind you, I'm not saying they aren't USEFUL, >just that they're very hard to follow! Yep, qsort() is awfully confusing. But seriously, I think I understand what you mean, and indeed I have seen some horridly unstructured use of callbacks, and of function pointers in general. But I can say the same about data pointers used to make incomprehensible data structures, or almost any other language feature. Very few things are *inherently* unstructured (not even goto's!). The spaghetti is put there by the designer of the code, not the designer of the language. (Granted, some languages make it a lot easier than others.) Also, a function call of any sort is very unlike a goto of any sort, because a function call *returns* (barring longjmp()). Which brings up... I'm hoping that it was the longjmp() out of the callback that prompted the charge of `spaghetti' from Doug. I'm not sure I'd immediately call such a longjmp() spaghetti (though I might), but I do strongly recommend that callbacks be specified to return normally. (It never occurred to me before to specify it explictly, but I probably will in future.) Function pointers, including their use as callbacks, are not just useful; they are *extremely* useful. This mainly applies when your goals include reusability, generality and extendability. If the functions pointed to are reasonably constrained, callbacks and the like really aren't that hard to follow, once you get used to the idea. -- Richard Minner || {uunet,sun,well}!island!rtm (916) 736-1323 || || Island Graphics Corporation Sacramento, CA ||