The BETA programming language A language that doesnt
The BETA programming language «A language that doesn’t affect the way you think about programming, is not worth knowing. » ―Alan Perils, Epigrams in Programming
What is BETA? • BETA is a modern object-oriented language in the Simula school of object orientation. • BETA has powerful abstraction mechanisms for supporting identification of objects, classification and composition. • BETA is a strongly typed language like Simula, Eiffel and C++.
History • The BETA project was initiated in 1976 as part of what was then called The Joint Language Project by people from: – The Regional Computing Center – Aarhus University – Norwegian Computing Center, Oslo • The BETA language was developed by Bent Bruun Kristensen, Ole Lehrmann Madsen, Birger Møller-Pedersen, and Kristen Nygaard.
The Mjølner system • The Mjølner System is a programming environment supporting object-oriented programming in BETA. • The Mjølner System includes an implementation of BETA and a large number of libraries and application frameworks. • The Mjølner system is free of any licence fee and available for Windows, Linux, UNIX, Solaris and Macintosh platforms.
Abstraction in BETA The BETA pattern: towards the ultimate abstraction mechanism. – Concepts represented as patterns – Phenomena represented as objects • The world is not object-oriented, object orientation is a perspective on the world. – A perspective is the means used by people to organize knowledge within some domain
Phenomena and concepts • A phenomenon is a thing that has definite, individual existence in reality or in the mind; anything real in itself. • A concept is a generalized idea of a collection of phenomena, based on knowledge of common properties of instances in the collection.
The pattern • BETA replaces classes, procedures, functions and types by a single abstraction mechanism called the pattern. • Objects are instances of patterns. • As there is only one language mechanism for classes and procedures the notation of a subpattern applies equally well to classes and procedures (virtual classes and procedures).
Block-structured languages • BETA and Simula are block-structured languages in that classes and procedures can be arbitrary nested. I. e. in BETA and Simula an object may have class attributes in addition to references and procedures. • This enables part/whole composition where classes can be encapsulated by higher level class constructs.
Objects and Patterns An object representing a bank account may be described by following attributes: (# balance: . . . ; Deposit: . . . ; Withdraw: . . . ; #) The syntactic construct (#. . . #) is called an object descriptor, which describes the structure of an object.
Singularly defined objects my. Account: @ (# balance: . . . ; Deposit: . . . ; Withdraw: . . . ; #); The symbol @ shows that my. Account is the name of an object. The my. Account object is called a singular object, since the object descriptor (#. . . #) is only used for describing a single object.
Pattern: a named object descriptor The objects representing the actual bank accounts may then be described as instances of this pattern. The pattern representing the concept of a bank account may be described as follows: Account: (# balance: . . . ; Deposit: . . . ; Withdraw: . . . ; #); Account is the name of the pattern.
Object-descriptor The syntactic element for describing an object is called an object-descriptor, and has the form: (# Decl 1; Decl 2; . . . ; Decln enter In do Imp exit Out #) • Decl 1; Decl 2; . . . ; Decln is a list of attribute declarations that describes the attribute-part of the object. • The enter-, do- and exit-parts are together called the action-part of the object.
Pattern-defined objects The Account pattern may, for instance, be used to describe three bank accounts (objects): account 1: @Account; account 2: @Account; account 3: @Account; When making descriptions in BETA there is a large number of patterns available for describing objects. The integer pattern is one example: balance: @integer
Description of actions Account: (# balance: @integer; Deposit: (# amount: @integer enter amount do balance+amount->balance exit balance #); Withdraw: (# amount: @integer enter amount do balance-amount->balance exit balance #);
account 1, account 2, account 3: @Account; K 1, K 2, K 3: @integer; do {L 1} 100 ->&account 1. Deposit; 200 ->&account 2. Deposit; 300 ->&account 3. Deposit; {L 2} 150 ->&account 1. Deposit->K 1; 90 ->&account 3. Withdraw->K 3; 90 ->&account 2. Deposit->K 2; 80 ->&account 3. Withdraw->K 3; {L 3} #) The symbol & means new, and the expression account 1. Deposit means that a new instance of the pattern account 1. Deposit is created and executed. Text enclosed by the brackets {…} is a comment.
3 kinds of objects: system, component and item • A system object may me executed concurrently with other system objects • A component object (coroutine) may alternate execution with other components (quasi-parallel? ) • An item object is a dependent action sequence contained in a system, component or item
Static references A static reference constantly denotes the same object within the lifetime of the encapsulating object. Point: (# x, y: @integer #) P 1, P 2: @Point A singular static/part-object is declared in the following way: Y: @(#. . . #)
Dynamic items A 1 may refer to an Account-item, a sub-item of Account or NONE. A 1: ˆAccount A dynamic Account item may be generated by execution of a “new” imperative: &Account[]->A 1[] The difference between &P and &P[] is very important: the expression &P means ‘generate a new instance of P and execute it’; the expression &P[] means ‘generate a new instance of P without executing it and return a reference to the new object. ’
Classification hierarchies Subpatterns: Person: (# Name: @string, Age: @integer #); Student: Person (# Studentid: @string#) Phdstudent: Student (# Thesistitle: @string#)
Declaration of virtual patterns V: < A V is declared as a virtual pattern with qualifying pattern A V may be bound to any subpattern of A The virtual pattern attributes of a pattern P may be bound in subpatterns of P. A binding of a virtual pattern may have the form of a final binding: V: : A 1
Example: prefixed procedure Open. Record: (# ID: ˆText; R: ˆRecord enter ID[] do ID[] -> the. Data. Base. Open -> R[]; INNER R. Close #); Open. Writable. Record: Open. Record (# do R. Lock; INNER R. Free #); Foo: Open. Writable. Record (# do some. Data[] -> R. put #) Execution of Foo implies thus that the following sequence of actions is executed: ID[] -> the. Data. Base. Open -> R[]; R. lock; some. Data[] -> R. put; R. Free; R. Close
Example: classes with virtual procedures Record: (# Key: ˆKey. Type; Display: < {virtual procedure} (# do Key. Display; INNER #) #); Person: Record (# Name: ˆText; Sex: ˆSex. Type; Display: : < {extended procedure} (# do Name. Display; Sex. Display; INNER #) #); P: ˆPerson Execution of P. Display will imply execution of Key. Display, Name. Display, Sex. Display, and possibly more since P is known to denote at least Person-objects.
Example: Classes as attributes Grammar: (# Symbol: Object (# is. Terminal: proc (#. . . #); is. Non. Terminal: proc (#. . . #); Ada. Gram: @ Grammar; S 1, S 2: @ Ada. Gram. Symbol; Pascal. Gram: @ Grammar; X 1, X 2: @ Pascal. Gram. Symbol Each Grammar objects has an associated Symbol class as an attribute. Similarly it is possible to declare instances of class Pascal. Gram. Symbol, in the example X 1 and X 2. S 1, S 2 and X 1, X 2 are not instances of the same class. Also a Symbol class has no existence without a grammar object.
Summary • In BETA class and procedure are unified into one abstraction mechanism: the pattern. • In BETA a virtual procedure cannot be redefined in a subclass, but it may be further defined by an extended definition. The extended procedure is a “subprocedure” (in the same way as for subclass) of the procedure defined in the superclass. This implies that the actions of a virtual procedure definition are automatically combined with the actions of the extended procedure in a subclass.
Links? • The BETA Home Page: http: //www. daimi. au. dk/~beta/ • Mjølner Informatics A/S: http: //www. mjolner. dk/
- Slides: 25