260 likes | 434 Views
ISSEP 2006 Nov 7-11 Vilnius Lithuania. Natural Object-Oriented Programming: The Evolution Metaphor In Elica. Pavel Boytchev Dept. of Information Technologies Faculty of Mathematics & Informatics University of Sofia elica@fmi.uni-sofia.bg. Topics. What is Elica? What is Natural OOP?
E N D
ISSEP 2006 Nov 7-11 Vilnius Lithuania Natural Object-Oriented Programming:The Evolution Metaphor In Elica
Pavel Boytchev Dept. of Information Technologies Faculty of Mathematics & Informatics University of Sofia elica@fmi.uni-sofia.bg
Topics • What is Elica?What is Natural OOP? • Evolution Metaphors in Elica • Examples of Natural OOP applications
What is Elica?What is Natural OOP? Concepts and features of NOOP Comparison with traditional OOP
Elica • One of the 160+ Logo dialects • Flexibility to the extreme • Composing names and code at run-time • Dynamic modification of objects • Experimenting with different programming styles • 3D graphics, animation, modeling • Natural OOP
OOP and Natural OOP • OOP • collection of concepts, tools and styles • requires changes in language syntax (C, Pascal, Logo) • complex terminology (class, instance, inherit, method…) • Natural OOP • extended collection of concepts, tools and styles • no changes in language syntax • no special data structures for OOP elements • no special procedures and functions to manage OOP • no new terminology
type TPoint = class fx : integer; fy : integer; public constructor Create(x,y:integer); function Distance:real; end; constructor TPoint.Create(x,y:integer); begin fx:=x; fy:=y; end; function TPoint.Distance:real; begin Result:=Sqrt(fx*fx+fy*fy); end; OOP vs NOOP Example Problem: Make class POINT with fields X and Y and method Distance. • using Delphi OOP • using Elica NOOP to point :x :yto distanceoutput sqrt :x*:x+:y*:y end end
Evolution Metaphors in Elica Emergent evolutions
NOOP • NOOP itself is like an evolution: Classes species Instances individual creatures Fields characteristics Methods behaviour Inheritance genealogical relations
Object Creation • Creating an object is like giving birth to a creature • This is a common metaphor in all OOPs • An creature in Nature can be born in many ways – agamic reproduction, sexual reproduction, cloning, etc • Most OOP support only one way of creation
Creating by Assignment • The most primitive creatures on Earth reproduce themselves by fission (agamic reproduction). Technically, this means creating a creature as an exact copy of another one. MAKE "PETER :TOM
Creating Field by Field • Explicit creating of an object field by field is like playing God. The user has a total control over her Elica-based microworld and can create creatures by enumerating their properties and behaviours. MAKE "JERRY.AGE 55 MAKE "JERRY.HEIGHT 180
Creating by Modification • This creation corresponds to mutation. Mutations could change the appearance and the behaviour of a creature to the extend that it looks as a different specie. Some mutations are fatal or even lethal. MAKE "JANE :TOM MAKE "JANE.EYES "BLUE
Creating from Classes • Using classes is like giving a birth to a new creature. Its specie determines its features. TO HUMAN :AGE :HEIGHT defining human properties END MAKE "PAUL HUMAN 15 160MAKE "MARIA HUMAN 21 175
Interpretations • In an atheistic context:Mammal’s pregnancy – embryos are being developed inside the parent, and delivery is when the new body is taken out. • In a religious context:Creating is close to incarnation. The result of executing a class is the spirit incarnated into a variable-receptionist. • In a Hollywood context:Dead procedures are brought back to life. An appropriate name for these beings is procedure-zombies.
Identification of Objects Two methods for identification of objects: (lack of instanceOf( ), className( ), etc…) • A local variable containing the name of the class corresponds to creatures that know what they are, like dolphins and maybe … humans. • Recognition by properties is related to more primitive creatures that recognize themselves by the smell and other senses.
Inheritance • Supported are single inheritance (for partheno-genesis species), and inheritance from two parents. There is also multiple inheritance (adoption) and conditional inheritance (guardianship). TO MAN :AGE :HEIGHT TO WOMAN :AGE :HEIGHT RUN :HUMAN RUN :HUMAN LOCAL "SEX LOCAL "SEX MAKE "SEX "MALE MAKE "SEX "FEMALE END END
Five Flying Turtles Start
Pythagorean Theorem Start
Initial condition Proof Pythagorean Theorem
Pythagorean Theorem Initial condition & Proof Initial condition & Proof
The Day Before Yesterday • I woke up at 3 am… • willing to go to a special place • but it was too early to go by car • and it was too far to go by foot, • so I went there by … Logo. • Could you guess the name of this place? Start