Martin Probst's weblog

Packages, Classes, Methods - Scopes?

Sunday, April 1, 2007, 16:57 — 1 comment Edit

I wonder why there is a distinction between the concepts of packages, classes, and methods. If you think about it a bit, it’s all just scopes. You could simply drop the distinctions.

A scope is an basic building block in a programming language that has

Scopes can be instantiated - in the case of packages, it’s loading the package. In the case of classes, it’s actually instantiating the class. In the case of methods, it’s calling the method. Instantiating a scope will initialize the non-static fields to something and yield a a scope instance - the activated package, an object instance or the functions stack frame/closure. The scope instance can then be passed around and members of it can be called.

To make it look nicer, you would probably end up providing some syntactic sugar like how function calls return their ‘return value’ member by default or something. But there doesn’t really seem to be a big conceptual difference here. Packages are currently not used or implemented in this instantiation way (or are they? OSGi?), but I think this might be really beneficial…

The idea probably doesn’t hold up, but whatever, it sounded nice at first :-)

I agree it is all just scope. However, each scope has its hard coded semantics and VM behavior, which make them quite different.

The OSGi takes the package scope very serious and adds a fourth scope: the bundle or JAR file that provides visibility rules and additional meta data for the other scopes.

Kind regards,

Peter Kriens