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!
== Object-oriented programming == {{main|Object-oriented programming}} [[File:Smalltalk80book.jpg|thumb|right|''Smalltalk-80: The Language and its Implementation'', a.k.a. the "Blue book", an original book on the language]] As in other object-oriented languages, the central concept in Smalltalk-80 (but not in Smalltalk-72) is that of an ''object''. An object is always an ''instance'' of a ''class''. Classes are "blueprints" that describe the properties and behavior of their instances. For example, a GUI's window class might declare that windows have properties such as the label, the position and whether the window is visible or not. The class might also declare that instances support operations such as opening, closing, moving and hiding. Each particular window object would have its own values of those properties, and each of them would be able to perform operations defined by its class. A Smalltalk object can do exactly three things: # Hold state (references to other objects). # [[Message passing|Receive a message]] from itself or another object. # In the course of processing a message, send messages to itself or another object. The state an object holds is always private to that object. Other objects can query or change that state only by sending requests (messages) to the object to do so. Any message can be sent to any object: when a message is received, the receiver determines whether that message is appropriate. If the message is not understood by the object then the virtual machine sends the doesNotUnderstand: message with the original message as an argument, and the default implementation of doesNotUnderstand: raises an exception that if not caught opens the system's debugger. Alan Kay has commented that despite the attention given to objects, messaging is the most important concept in Smalltalk: "The big idea is 'messaging'—that is what the kernel of Smalltalk/Squeak is all about (and it's something that was never quite completed in our Xerox PARC phase)."<ref>{{cite web |last=Kay |first=Alan |title=Prototypes vs Classes (e-mail on Squeak list) |url=http://lists.squeakfoundation.org/pipermail/squeak-dev/1998-October/017019.html |date=October 10, 1998}}</ref> Unlike most other languages, Smalltalk code can be modified while the system is running. [[Live coding]] and applying fixes 'on-the-fly' is a dominant programming methodology for Smalltalk and is one of the main reasons for its productivity. Smalltalk is a "pure" object-oriented programming language, meaning that, unlike [[C++]] and [[Java (programming language)|Java]], there are no primitive types. All values are represented as objects and computation on integers uses message sending just like any other object. In Smalltalk, types such as integers, Booleans and characters are also objects, in the sense that they are instances of corresponding classes, and operations on them are invoked by sending messages. For efficiency and generality integers are implemented by four classes, Integer, the abstract superclass of all integers, SmallInteger, whose instances fit in a machine word, for example having a 61-bit signed range in a 64-bit implementation, LargePositiveInteger and LargeNegativeInteger, the last two being vectors of bytes. Consequently Smalltalk can evaluate 52 factorial to produce 80658175170943878571660636856403766975289505440883277824000000000000. The transition from small to large integers is transparent to the programmer; variables do not require type declarations. This makes the system both concise and flexible. A programmer can change or extend (through [[Inheritance (object-oriented programming)|subclassing]]) the classes that implement what in other languages would be primitive values, so that new behavior can be defined for their instances—for example, to implement new control structures—or even so that their existing behavior will be changed. This fact is summarized in the commonly heard phrase "In Smalltalk everything is an object", which may be more accurately expressed as "all values are objects", as variables are not. Since all values are objects, [[Class (computer programming)|classes]] are also objects. Each class is an instance of the ''[[metaclass]]'' of that class. Metaclasses in turn are also objects, and are all instances of a class named Metaclass. Classes contain method dictionaries that map selectors (the equivalent of function procedure names in other languages) to method objects, objects that are executed to evaluate messages. Classes inherit from other classes, with either Object or ProtoObject at the root of the class hierarchy. Sending a message to an object at the most abstract involves fetching the class of the receiver (the object being sent the message) and looking up the message's selector in the class's method dictionary, followed by the superclass and so on until the method is found or doesNotUnderstand is sent. Smalltalk virtual machines use various techniques to speed up message lookup so the system provides both a simple consistent message binding mechanism and good efficiency. [[#Code blocks|Code block]]s—Smalltalk's way of expressing [[anonymous function]]s—are also objects.<ref>{{cite book|last1=Goldberg|first1=Adele|author-link1=Adele Goldberg (computer scientist)|last2=Robson|first2=David|title=Smalltalk-80 The Language|year=1989|publisher=Addison Wesley|isbn=0-201-13688-0|pages=31, 75–89}}</ref> They have a very lightweight syntax and are used throughout the system to implement control structures, especially for the Collection hierarchy.
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)