4.5 Comparisons to Other Languages4.5.1 Tcl
Tcl programmers rely heavily on dynamic evaluation (using 4.5.2 PythonPython offers a weak form of closures: a subroutine can pick up variables only from its immediate containing environment. This is called "shallow binding," while Perl offers "deep binding." Mark Lutz's Programming Python (O'Reilly, 1996) shows a workaround to achieve deep binding, by setting default arguments to values in the immediately enclosing scope. I prefer the environment to handle this stuff automatically for me, as Perl does. 4.5.3 C++C++ supports pointers to subroutines but does not support closures. You have to use the callback object idiom wherever a callback subroutine needs some contextual data to operate. If you don't want a separate callback object, you can inherit your object from a standard callback class and override a method called, say, "execute," so that the caller can simply say callback_object->execute() . 4.5.4 JavaJava offers neither closures nor pointers to subroutines (methods). Interfaces can be used to provide a standardized callback interface so that the caller doesn't have to care about the specific class of the object (as long as it implements that interface). |
|