Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Smalltalk
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Reflection == [[Reflective programming|Reflection]] is a feature of having a meta-model as Smalltalk does. The meta-model is the part of the system that implements the programming system itself, and developers can use the meta-model to do things like walk through, examine, and modify code in the running system, or find all the instances of a certain kind of structure (e.g., all instances of the Method class in the meta-model). Smalltalk-80 is a totally reflective system. Smalltalk-80 provides both structural and computational reflection. Smalltalk is a structurally reflective system which structure is defined by Smalltalk-80 objects. The classes and [[method (computer programming)|methods]] that define the system are also objects and fully part of the system that they help define. The Smalltalk compiler, which is itself written in Smalltalk and exists alongside all the other code in the system, compiles textual source code into method objects, typically instances of <code>CompiledMethod</code>. These get added to classes by storing them in a class's method dictionary. The part of the class hierarchy that defines classes can add new classes to the system. The system is extended by running Smalltalk-80 code that creates or defines classes and methods. In this way a Smalltalk-80 system is a "living" system, carrying around the ability to extend itself at run time. One can even extend the compiler at run-time; indeed this is how the Compiler is developed and maintained. Since the classes are objects, they can be asked questions such as "what methods do you implement?" or "what fields/slots/instance variables do you define?". So objects can easily be inspected, copied, (de)[[Serialization|serialized]] and so on with generic code that applies to any object in the system.<ref>{{cite arXiv |last=Clark |first=A.N. |date=September 18, 1997 |title=Metaclasses and Reflection in Smalltalk |eprint=1804.07272 |class=cs.SE}}</ref> Smalltalk-80 also provides computational reflection, the ability to observe the computational state of the system. In languages derived from the original Smalltalk-80 the current activation of a method is accessible as an object named via a pseudo-variable (one of the six reserved words), <code>thisContext</code>, which corresponds to a stack frame in conventional language implementations, and is called a "context". Sending a message is done within some context, and to evaluate the message another context is created, the first being the sender of the former. In this way the stack is a linked list of context objects, and the debugger is essentially an inspector of this "spaghetti stack". By sending messages to <code>thisContext</code> a method activation can ask questions like "who sent this message to me". These facilities make it possible to implement [[coroutine]]s or [[Prolog]]-like back-tracking without modifying the virtual machine. The exception system is implemented using this facility. One of the more interesting uses of this is in the [[Seaside (software)|Seaside]] web framework which relieves the programmer of dealing with the complexity of a Web Browser's back button by storing continuations for each edited page and switching between them as the user navigates a web site. Programming the web server using Seaside can then be done using a more conventional programming style.<ref>{{cite web|last1=Ducasse|first1=Stéphane|last2=Lienhard|first2=Adrian|last3=Renggli|first3=Lukas|title=Seaside – A Multiple Control Flow Web Application Framework|url=http://scg.unibe.ch/archive/papers/Duca04eSeaside.pdf|work=scg.unibe.ch|publisher=Software Composition Group Institut fur Informatik und angewandte Mathematik Universitaat Bern, Switzerland|access-date=16 December 2013}}</ref> As with message sending Smalltalk-80 virtual machines optimize away the expensive use of contexts internally, providing the illusion and flexibility of a spaghetti stack without most its costs. Essentially context objects are created lazily as required, for example when a message is sent to the thisContext variable. An example of how Smalltalk can use reflection is the mechanism for handling errors. When an object is sent a message that it does not implement, the virtual machine sends the object the <code>doesNotUnderstand:</code> message with a [[reification (computer science)|reification]] of the message as an argument. The message (another object, an instance of <code>Message</code>) contains the selector of the message and an <code>Array</code> of its arguments. In an interactive Smalltalk system the default implementation of <code>doesNotUnderstand:</code> is one that opens an error window (a Notifier) reporting the error to the user. Through this and the reflective facilities the user can examine the context in which the error occurred, redefine the offending code, and continue, all within the system, using Smalltalk-80's reflective facilities.<ref>{{cite book|last1=Foote|first1=Brian|last2=Johnson|first2=Ralph |title=Conference proceedings on Object-oriented programming systems, languages and applications |chapter=Reflective facilities in Smalltalk-80 |pages=327–335|date=1–6 October 1989|chapter-url=http://www.laputan.org/ref89/ref89.html|access-date=16 December 2013|doi=10.1145/74877.74911|isbn=0-89791-333-7|s2cid=14207536|doi-access=free}}</ref><ref>{{cite journal|last=Smith|first=Brian C|title=Procedural Reflection in Programming Languages|journal=MIT Technical Report|date=1982-01-01|issue=MIT-LCS-TR-272|url=http://publications.csail.mit.edu/lcs/specpub.php?id=840|access-date=16 December 2013}}</ref> By creating a class that understands (implements) only doesNotUnderstand:, one can create an instance that can intercept any message sent to it via its doesNotUnderstand: method. Such instances are called transparent proxies.<ref name="Peck Bouraqadi Denker Ducasse 2011 pp. 1–16">{{cite conference | last1=Peck | first1=Mariano Martinez | last2=Bouraqadi | first2=Noury | last3=Denker | first3=Marcus | last4=Ducasse | first4=Stéphane | last5=Fabresse | first5=Luc | title=Proceedings of the International Workshop on Smalltalk Technologies | chapter=Efficient proxies in Smalltalk | publisher=ACM | date=2011-08-23 | isbn=978-1-4503-1050-5 | doi=10.1145/2166929.2166937 | page=1–16| hdl=20.500.12210/28011 | hdl-access=free }}</ref> Such proxies can then be used to implement a number of facilities such as distributed Smalltalk where messages are exchanged between multiple Smalltalk systems, database interfaces where objects are transparently faulted out of a database, [[Futures and promises|promises]], etc. The design of distributed Smalltalk influenced such systems as [[CORBA]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)