Name: Anonymous 2013-02-27 15:45
Back in the days before Algol, the lambda papers and r0rs, people were happy to program with dynamically scoped variables. While it allowed for some nice things such as executable data that require no linking in advance and non-parameter function options, it gave a little too much power to the variable name. For instance, it lead to problems such as not knowing whether reading a variable x yields the same value as the lexically enclosing function's x? Overall it fell out of favor, and nowadays only a handful of languages even consider dynamic binding as anything but a special case. Many thought it was a bad idea and moved on to lexical scoping.
But did it really disappear from all mainstream programming languages? In most object-oriented languages every method invocation supplies an implicit parameter that refers to the object itself, which often is called
No my friends, dynamic scoping stuck with us right under our noses. Dynamic scoping never went away. Dynamic scoping got the last laugh.
But did it really disappear from all mainstream programming languages? In most object-oriented languages every method invocation supplies an implicit parameter that refers to the object itself, which often is called
this or self. The meaning of this depends on which method it's evaluated in and the dynamic state in which the method was called. Reading it in an inner class's method has a different effect than in the enclosing scope. You might have seen code such as var that = this; used in order to bypass the dynamic nature of this. It's safe to say that you can consider it a dynamically scoped variable, even though it technically might be a keyword, if you accept that you can't access it in non-object (static) methods and functions.No my friends, dynamic scoping stuck with us right under our noses. Dynamic scoping never went away. Dynamic scoping got the last laugh.