|
The Essence of Smalltalk
S m a l l t a l k a n d i t s u s a g e i n M i c r o s o f t s . N e t Written by Aditya Dutt, aditya_db at yahoo dot com Smalltalk was one of the first systems to pioneer the WIMP (Windows, Icons, Menus and Pointers) interface. Compared to conventional programming languages such as C or Pascal, Smalltalk has an unusual syntax. Objects are employed to represent everything in Smalltalk, including all the conventional data types that may be found in any programming language: such as integers, Booleans, floating-point numbers, characters, strings, arrays. In addition to this, objects are used to represent display items such as menus, windows and even the compiler itself. Smalltalk is therefore described as a uniformly object-oriented language. Smalltalk language was developed at the Xerox Palo Alto Research Center in 1970s, the programming environment greatly influenced the development of Apple Macintosh and Microsoft Windows. Cincom has an extended version of Smalltalk-80 called VisualWorks (derived from the original ParcPlace version), which provides window-building facility and database connectivity. IBM's VisualAge is a development environment designed to support the easy creation of software applications on multiple platforms. IBM Smalltalk provides a platform-independent application program interface (API) based on industry standards. VisualAge Smalltalk Enterprise V6.0.1 allows for incremental and rapid development of new Smalltalk applications. Developers can build and deploy enterprise Web service solutions for dynamic e-business using VisualAge Smalltalk. Communication transactions can be protected with Secure Socket Layer (SSL) support. Comprising nine subsystems, it encompasses the functionality required by most Smalltalk applications. Applications programmed entirely in accordance with the Smalltalk interface specification run without modification on all supported platforms, yet adopt the native look and feel of the particular platform. This enables applications to be produced from a single code base across multiple platforms, while still providing a high degree of platform integration. The nine subsystems are of VisualAge Smalltalk are: 1) Common Language Data Types: The Common Language Data Types (CLDT) subsystem contains the classes and associated methods for working with standard Smalltalk objects such as Collection, Magnitude, Boolean, and Stream. The Common Language Data Types subsystem (CLDT) provides a platform-independent interface and implementation for the basic data types that form the building blocks of the Smalltalk programming environment. The CLDT classes have been grouped into seven categories: Boolean, collection, magnitude, graphical, stream, support, and exception handling. 2) Common Language Implementation: The Common Language Implementation (CLIM) subsystem contains the classes and associated methods which, together with the virtual machine, implement the Smalltalk class and message mechanisms. The Common Language Implementation (CLIM) subsystem provides a platform-independent interface that is primarily intended to describe the shared behaviour of IBM Smalltalk classes. A class in Smalltalk is an abstraction that describes a kind of object. One of the fundamental symmetries of the Smalltalk environment is that every object is an instance of a class. That includes classes themselves, which are instances of special classes called metaclasses. 3) Common Process Model: The Common Process Model (CPM) subsystem contains the classes and associated methods that facilitate the execution and arbitration of multiple execution contexts, or Smalltalk processes. The Common Process Model (CPM) subsystem provides a process model (shared memory threads) for IBM Smalltalk. Standard operations include process creation and destruction, as well as process scheduling operations including suspend, resume, and change priority. Simple synchronization mechanisms are provided by semaphores. 4) Common File System: The Common File System (CFS) subsystem contains the classes and associated methods for performing file and directory operations. 5) Common Graphics: The Common Graphics (CG) subsystem contains the classes and associated methods for performing low-level graphics operations, such as drawing lines, circles, and rectangles and for manipulating device independent images, fonts, and colors. 6) Common Widgets: The Common Widgets (CW) subsystem contains the classes and associated methods for constructing application user interfaces through the composition of user interface components called widgets. The Common Widgets (CW) classes and methods subsystem enables developers to design and build graphical user interfaces using an application programming interface (API) based on OSF/Motif. Using the Common Widgets subsystem, developers can do the following:
7) Extended Widgets: The Extended Widgets (EW) subsystem contains the classes and associated methods for expanding on graphical user interfaces built using the Common Widgets subsystem. The Extended Widgets classes and methods enable application developers to expand upon the graphical user interfaces built using the Common Widgets (CW) subsystem. 8) Drag and Drop: Through the Drag and Drop (DD) subsystem, pluggable drag and drop support is provided for the widgets in both Common Widgets and Extended Widgets subsystems without requiring modifications to the widgets. The Drag and Drop subsystem uses the portable CG and CW subsystems. 9) Common Printing: The Common Printing (CP) subsystem contains the classes and associated methods for performing printer job and page control, setup, and graphical and text output. IBM Smalltalk directly utilizes the native functionality provided by each platform. IBM Smalltalk emulates API functionality not directly supported by a particular platform in order to support a complete and consistent interface across all supported platforms. As part of the implementation of IBM Smalltalk, access to platform-specific functionality is also provided. Object oriented Programming languages use message sending as performing operations. If the receiving object understands the message it has been sent, then one of its internal operations will be performed. This in turn, cause some computations and a result is always returned. For instance, we are sending a message +3 to an object integer 9. Here '+' is a selector and 3 is an argument. The result of sending this message +3 to the object integer 9 is 12. A message expression comprises a receiver, a selector and some arguments. Keyword messages are complex type of message. ( 3 r a i s e d T o : 3 ) r a i s e d T o : 3 i s a k e y w o r d m e s s a g e . r a i s e d T o : a n d r a i s e d T o : a r e k e y w o r d s a n d n u m b e r s 3 s a r e a r g u m e n t s . K e y w o r d e n d s w i t h a c o l o n . We have different types of variables are provided in Smalltalk language: Temporary variables, Class variables, Instance variables, Global variables, Pool variables. By convention, private variables(instance variables, temporary variables) start with an initial lower-case letter, where as shared variables (class variables, global variables, pool variables) start with an initial upper-case letter. In most conventional languages, array is the only sort of collection, in Smalltalk we have two types of collections: unordered collection and sequential collection. The concept of block closure is a great feature that gives Smalltalk a great advantage. It's missing in languages like C# and many other languages. I n S m a l l t a l k w e h a v e h u n d r e d s o f c l a s s e s a n d t h o u s a n d s o f m e t h o d s . T h e S m a l l t a l k i s w r i t t e n a l m o s t e n t i r e l y i n S m a l l t a l k a s m a l l k e r n e l i s w r i t t e n i n m a c h i n e c o d e . I want to introduce a few concepts of the Smalltalk syntax to help the non-smalltalker to understand the issues: Messages A Smalltalk programmer can also invoke methods in an object like a C# programmer. The mechanism of doing so is by sending a message. Compare this with an example: Say, the 'Printer' is a variable and is called the 'receiver' in Smalltalk.
The word 'on' is called the message - it causes the Smalltalk system to locate the method with this name and to execute it. If the receiver does not have such a method, the #doesNotUnderstand: method is activated. Every Smalltalk object has this method. U s i n g a n a r g u m e n t : - s a y , w e w a n t t o s e t t h e h e i g h t t o t h e O b j e c t B o x .
The message used here is #height:. The colon at the end of the message is called a keyword message and it indicates that it takes an argument. U s i n g m u l t i p l e a r g u m e n t s s a y , w e w a n t t o s e t t h e h e i g h t a n d w i d t h t o t h e O b j e c t B o x .
This is of only one keyword. It is #height:width:. Unlike other languages the parameters are written right after the two colons. This may seem wierd but it actually makes code that is well readable. Control StructuresSmalltalk doesn't have control structures. Take a glance this by an example:
We have here the receiver (a > b). T h e r e c e i v e r i s a n e x p r e s s i o n . I t w i l l b e e v a l u a t e d a t e x e c u t i o n a n d w i l l r e t u r n e i t h e r t h e c l a s s T r u e ) o r t h e c l a s s F a l s e . T h i s o b j e c t w i l l t h e n b e s e n d t h e m e s s a g e ifTrue:ifFalse: with the trueblock and falseblock as arguments. Both the True class and the False Class are subclasses of the class Boolean. They both implement the method for ifTrue:ifFalse:. In the True class the first block is evaluated, in the false class the second block is evaluated. Thus the semantics of the if-then-else concept are implemented, without the language having if then or else as keywords and therefore no formal control structure exists. While and for loops are implemented in the same manner. BlocksA block represented by a sequence of expressions, enclosed by square brackets. Blocks are anonymous methods. For instance: aBlock := [a := 0]. aBlock value a B l o c k r e c e i v e s t h e m e s s a g e v a l u e , i t s m e s s a g e e x p r e s s i o n s a r e e v a l u a t e d , h e r e c a u s i n g t h e v a r i a b l e a t o r e f e r t o t h e i n t e g e r 0 . A Block represents a deferred sequence of message expressions. Eg: [answer := Float pi/16] Blocks are used as arguments in the conditional selection and control structure. ifTrue: aBlock ifTrue: trueBlock ifFalse: falseBlock Sample Example for using Blocks
A block can be activated with the value message. There are a number of them that are needed to supply the arguments for the block's parameters. So a block without parameters is activated by: [<statements>] value. A block with 2 parameters is: [:arg1 :arg2| <statements>] value: <arg1> value:<arg2>. and so on/ Smalltalk with .net: Development of S#: We got S# from Smallscript which is a redesign of Smalltalk Language. The S# language implementation (pronounced s-sharp) is a complete modular redesign of the Smalltalk language, offering transparent cross-language integration and component based deployment. Capable of supporting both repository and industry standard file-based source code management, it offers a rich array of streamlined features which enhance the Smalltalk language. In contrast with a variety of other programming languages, its unique modular composition technology with multi-threaded C-like-performance of dynamic and scripting languages addresses many of today's most difficult fragility and versioning challenges that developers face when working on just-in-time integration within client and server applications. Design work and implementation of the Smallscript System began in 1999. Today, it offers modular deployment as a small-footprint, hi-performance, pre-emptive multi-threaded jit-based execution engine for dynamic and scripting languages. It is designed to meet today's challenging requirements for building and deploying software engineering solutions as mixed language components. It enables delivery of programs and components as small as 2KB, supports namespace partitioned access to multiple co-resident versions of the same methods for a given class, and provides key features such as optional strong typing and file-based development. It breaks new ground for developers on leading Web and Internet technology platforms such as Microsoft .NET, where it offers unique capabilities that include enabling extension of final/base classes and new patterns of reuse through concrete interface implementations. Its state-of-the-art design removes the constraints of classic Smalltalk while offering lightweight scripting and module facilities that scale up into the traditional space occupied by classic Smalltalk. It's execution and object model facilities are designed around a unified architecture of state-of-the-art dynamic language techniques including selector namespaces, optional dynamic typing, multi-methods, concrete interfaces/mixins, and self-marshalling transparent foreign functions with typical FFI calling rates in the many 10's of millions calls/sec. Working in direct collaboration with Microsoft since 1999, the S# compiler architecture was extended to support the generation of native Microsoft.NET Framework IL modules and assemblies. Key features of the Agents Object System's [AOS] dynamic language platform facilities were also extracted and ported to Microsoft's .NET Framework to add an extended range of dynamic and scripting language services to Microsoft's .NET Framework Runtime. Smallscript provides a valuable development environment on the .NET Framework and offer developers of Smalltalk a productive, reliable, easy-to-use platform for building and deploying cross-language applications and Web services." The S# language derives its rich object model from the AOS Platform Architecture on which it is designed to execute. That architecture was designed from its inception to support multiple languages and distributed system agent services.
While it is simplest to view S# as a single language, it is in fact
only one language layer designed to integrate symbiotically within
the multi-language architecture of Smallscript. The primary script
structuring and object model language (AML) is the declarative
meta-language of the Agents Object System [AOS CDLR]. Its declarative
form is transparently mapped onto the dynamic MOP services of the
execution engine to support specifying code structure and object
model entities. It offers a flexible set of syntax ranging from pure
XML to various more human friendly forms.
The
Object Oriented Programming Feature Comparisons Table
features
Smalltalk-80
S#
C#
Typing
dynamic
dynamic
static
Dynamic
binding
Implicit
Implicit
yes
Root
class
Object
Object
Object
Receiver
name
self
self
this
Private
Data
yes
yes
yes
Private
methods
yes
yes
yes
Runtime
access to method names
yes
yes
yes
Runtime
access to class names
yes
yes
yes
Runtime
access to instance variable names
yes
yes
yes
Metaclasses
yes
yes
no
(classes and methods are not objects)
Inheritance
single
multiple
single
Instantiation
Explicit
Explicit
Explicit
Binding
(late/dynamic)
yes
yes
no
Multi-methods
(overloading)
no
yes
yes
Forwarding
(Delegation, Distributed Objects and Proxies)
yes
yes
yes
Access
to super method
super
super
,
Superclass:super, thisContext, CallNextMethod,...
yes
Class
Variables
yes
(classes are objects, shared/pool variables also exist)
yes
(classes are objects, shared/pool variables also exist)
yes
(static only, classes are not objects)
Interfaces
no
yes
(supports COM model, .NET model, interfaces can define methods
with code, and have concrete fields)
yes
(but not instantiatable, cannot contain implementation)
Templates
no
no
no
Garbage
Collection
yes
yes
yes
Pre-emptively
Multi-threadable (native threads?)
no
yes
yes
Intrinsic
Exception Model (native exception integration)
no
yes
yes
Foreign
Function Interface
no
yes
(replaces need for primitives; language also supports inline
C/C++/Assembly)
yes
(intrinsic COM and Distributed Object Services)
Macro
System
no
no
no
Lexical
Scopes
yes
yes
yes
Annotation
System and Metadata Declarations
no
yes
yes
Security
Validation
no
yes
yes
Graphics
and GUI Services
yes
yes
yes
Integrated
Source Level Debugging Facilities
yes
no
(only available on the.NET platform version)
yes
Designed
for Multi-paradigm support of component oriented programming
no
yes
(intrinsic COM; .NET facilities available)
yes
(intrinsic COM and .NET Facilities)
Copyright 1 9 9 9 - 2 0 1 0 b y S m a l l t a l k . o r g "! , A l l R i g h t s R e s e r v e d . |
|