{"id":630,"date":"2008-09-11T16:00:03","date_gmt":"2008-09-11T23:00:03","guid":{"rendered":"https:\/\/www.reenigne.org\/blog\/?p=630"},"modified":"2008-09-11T15:51:01","modified_gmt":"2008-09-11T22:51:01","slug":"static-scoping-improved","status":"publish","type":"post","link":"https:\/\/www.reenigne.org\/blog\/static-scoping-improved\/","title":{"rendered":"Static scoping improved"},"content":{"rendered":"<p>Many programming languages have a facility (usually called &#8220;static&#8221;) to allow the programmer to declare a variable which is visible only to some particular object but has storage at the program&#8217;s scope &#8211; i.e. its value is the same for all instances of that object and when it changes for one it changes for all the other instances too.<\/p>\n<p>One programming language feature I&#8217;ve never seen (but which I think would be useful) is a generalization of this &#8211; the ability to declare a variable which is only visible in a particular object but whose scope is the (lexical) parent object. I call this &#8220;outer&#8221;. For top-level objects, this would be the same as static but for nested classes the scope would be that of the outer class.<\/p>\n<p>One could even use the &#8220;outer&#8221; keyword multiple times to put the variable in any particular level in the object nesting tree. This doesn&#8217;t violate encapsulation, since members can still only be declared inside their classes.<\/p>\n<p>If you have &#8220;outer&#8221; instead of &#8220;static&#8221; (and maybe a few other more minor tweaks) any program can be turned into an isolated object inside another program &#8211; i.e. you can easily turn a program into a multi-instance version of that program with all the instances running in the same process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many programming languages have a facility (usually called &#8220;static&#8221;) to allow the programmer to declare a variable which is visible only to some particular object but has storage at the program&#8217;s scope &#8211; i.e. its value is the same for all instances of that object and when it changes for one it changes for all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-630","post","type-post","status-publish","format-standard","hentry","category-language"],"_links":{"self":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/comments?post=630"}],"version-history":[{"count":2,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":739,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/630\/revisions\/739"}],"wp:attachment":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/media?parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/categories?post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/tags?post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}