Previous | Table of Contents | Next |
The contents of a classic Smalltalk virtual image include the classes that make up the standard, predefined Smalltalk class library. The contents also includes objects that provide the implementation mechanisms for all elements of the Smalltalk language, including class definitions, methods, variables, and blocks. These objects implement protocols that support the dynamic creation and modification of Smalltalk program elements within the virtual image. Using these protocols, Smalltalk code can be written that cause new classes and methods to be dynamically created. This process of using Smalltalk code within a running image to dynamically modify and extend itself is called reflection. Typically a Smalltalk programmer does not need to manually write the code to create new classes and methods because the virtual image also contains classes that implement high-level, interactive programming tools. It is the implementation of these tools that most commonly make use of reflection. Normally a programmer interacts with these tools to create new classes and methods.
When we discussed class definitions earlier, we mentioned that different Smalltalk implementations use various forms for describing classes. One of these forms is that which is presented by the interactive programming tools. Classic Smalltalk systems include a tool called a browser that presents class definitions in the context of a highly structured user interface. Another form used by classic Smalltalk for describing a class is a message that causes a new class to be created. Using reflection, a class can be created by a message such as this:
Object subclass: #NewClassName instanceVariables: x y z classVariableNames: poolDictionaries: .
The message is sent to the intended superclass of the new class. This example would create a new class named NewClassName that is a subclass of Object and whose instances contain instance variables named x, y, and z. Additional messages would then be directed to the class object, NewClassName, in order to create instance and class methods. Although this general mechanism is provided by all classic Smalltalk implementations, the exact message selectors used for these operations vary among implementations.
Program creation through the use of reflection within a virtual image is a powerful implementation technique. However, it introduces complications into the software development process. One of these complications is the issue of how to prepare a virtual image containing a completed application for deployment to the users of the application. In most cases, it is not desirable for the deliverable application to contain the interactive tools that are used for Smalltalk programming. In addition, most programs only make use of some subset of all the predefined classes in the Smalltalk class library. Any unused classes within the deployed virtual image potentially waste system resources. Finally, most deployed applications do not require the use of reflection during execution of the application, yet its existence can have negative effects on application performance. Classic Smalltalk systems address these issues by providing various tools that are aids in removing development tools and unused classes from a virtual image in preparation for deployment.
Some recent Smalltalk implementations attempt to address these issues by treating the Smalltalk language in a more conventional manner. These implementations do not use reflection to implement a development environment that operates within the same virtual image as the application under development. Instead, they implement the development environment as an independent program that is separate and distinct from the application under development. In such implementations, a Smalltalk program is simply a set of class definitions that may be compiled into an executable program file. Whether this compilation process takes place incrementally or in batch mode, or whether it makes use of some form of reflection, is considered to be a characteristic of an implementation not a characteristic of the Smalltalk language itself.
Standard Smalltalk defines the Smalltalk language in a manner that can accommodate both the classic and the newer style of Smalltalk implementation. Standard Smalltalk defines the attributes that must be specified when creating Smalltalk language elements and the required semantics of language elements. In does not, however, mandate a particular syntax for writing complete Smalltalk programs. It does define the execution semantics of a complete Smalltalk program. A implementation of standard Smalltalk may choose to map the definition of language elements into a concrete syntax, reflective message, or the user interface of an incremental programming environment. These are all valid, as long as the required execution semantics are followed. To facilitate the interchange of code between implementations, standard Smalltalk also defines a program interchange file format. This format is not intended to be directly read or written by human programmers. Instead, it is designed such that any standard Smalltalk implementation, regardless of whether it is based on reflection or uses a virtual image, can translate its internal representation of a Smalltalk program to and from the interchange format.
Goldberg, A., and D. Robson. 1983. Smalltalk-80: The language and its implementation. Reading, MA: Addison-Wesley.
Kay, A. C. 1996. The early history of Smalltalk. In T. J. Bergin and R. G. Gibson (Eds.), History of programming languages (pp. 511-579). New York: ACM Press.
The X3J20 Committee. 1997. Draft American national standard for information systemsProgramming languagesSmalltalk: Working draft. Washington, DC: National Committee for Information Technology Standards.
Previous | Table of Contents | Next |