Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage...

48
Eiffel Eif fel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide

Transcript of Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage...

Page 1: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Eiffel

Eiffel

Naeem EsfahaniUniversity of Tehran

"Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide

Page 2: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

I prefer to have as little as possible to do with Bertrand Meyer

-- Bjarne Stroustrup, 1989

Page 3: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Overview

• Introduction & History

• Design By Contract™

• Elements

• Concepts

• Syntax and Semantics

Page 4: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Introduction & History

Page 5: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Bertrand Meyer

• BS from Ecole polythecnique

• MS from Stanford University

• PhD from Univesite du Nancy

• Professor of Software Engineering at ETH in Zurich 2001

Page 6: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Bertrand Meyer

• Nine years in a large company

• Three years on the faculty at the University of California, Santa Barbara

• computer languages, object-oriented system design, architectural reviews, technology assessment

Page 7: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

History

• Designed at Eiffel Software in 1985 as an internal tool

• A modern, OO environment integrating the concepts of modern software engineering

• There was simply nothing available

Page 8: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

History

• First demonstrated in public at the first OOPSLA conference in October of 1986

• Release it as a commercial product at the end of 1986

• In 1988 in a book by Bertrand Meyer

• Version 2.3, released in the Summer of 1990

Page 9: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

History

• Eiffel 3, was written entirely in Eiffel– Melting Ice Technology for fast recompilation – Fully graphical environment– Considerable advances in libraries– Optimization of the generated code

• The latest milestones is:

Eiffel 5 and EiffelStudio

Page 10: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Application

• Leading to a set of successful industrial projects in the US, Canada, Europe and the Far East

• Adoption by numerous universities as the primary teaching language

Page 11: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Where the Name does come from?

• Homage to Gustave Eiffel, the man who built the eponymous Tower in Paris

• The Eiffel Tower was completed on time and within budget

• Small number of robust, elegant design patterns, combined and varied repeatedly to yield a powerful, efficient structure

Page 12: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Where the Name does come from?

• The Eiffel Tower was initially conceived as a temporary structure and it was able to endure far beyond its original goals

• What better symbol could there be of the engineering principles behind Eiffel?

Page 13: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Design By Contract™

Page 14: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Assertions

• A boolean expression that is evaluated when it is reached during execution

• If true, execution continues

• else, execution may halt or an exception

• Eiffel has support for writing assertion

Page 15: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Assertions

Preconditions:When a routine is called

Postconditions:When a routine returns

General assertions:When execution reaches them

Class invariants:Maintained by all instances of a class

Page 16: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Pre and postconditions

• Preconditions and postconditions are associated with routines of a class

Page 17: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Pre and postconditions

• The preconditions must be true when the routine is called

• Postconditions must have been established when the routine terminates

Page 18: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Class Invariant

• Conditions that must be true for all objects of the class at ‘stable’ times

• When method starts to execute:– Its preconditions are met and the class invariant is

satisfied

• After execution:– The postcondition must be met and the class

invariant must be satisfied

Page 19: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Class Invariant

Page 20: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Elements

Page 21: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Classes

• The basic and only construct in Eiffel

• The attributes of entities and the operations that entities can perform

• A class represents all objects of that type

Page 22: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Libraries

• Classes that frequently appear– Reuse

• EiffelBase: – INTEGER, REAL, STRING, LISTs, ARRAYs

• Libraries are not defined as part of the Eiffel language

Page 23: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Features

• Each class has a set of features which represent the attributes and routines of a class

• routines are either procedures or functions; attributes can be fields, constants or functions

Page 24: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Features

• Procedures (Commands) alter the state of the object

• Functions (Queries) are return an answer to a query about the state of an object

• This is by convention, rather than being enforced in Eiffel

Page 25: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Concepts

Page 26: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Inheritance

• Build new classes out of existing classes, and to reuse features already defined in those classes, you use inheritance

• Eiffel has multiple inheritance– solves clashing by having a rename clause– Redefinition

• Inheritance is one of the fundamental mechanisms for reuse

• Polymorphism

Page 27: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Class Syntax

Page 28: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Genericity

• You can reuse like inheritance

• Genericity is important in making programs type safe without resorting to type casts

• constrained genericity– allows generic parameters to be constrained

• allow you to write general algorithmic patterns

Page 29: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Objects

• A name in an Eiffel program is declared as having a type. The declaration

x : T

• Still does not refer to any objects: x is not bound to an object

• Expressed as the object void. We can see if an object is bound to void by writing x=void

• Name x can be bound to any object that type conforms to type T

Page 30: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Objects

• Three ways to achieve this binding:

Assignment instruction: The assignment x:=y binds x to the object to which y is currently bound

A creation instruction: The creation instruction !!x creates a new object of type T,and binds x to it. This is similar to new in C++.

Routine call

Page 31: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Objects

c: C!! c.make• An object of type C is created and attached to

the reference c

!D! c.make• An object of type D, where D conforms to C is

created and attached to c.

• If you have a creation routine declared for the class, the creation routine must be called like constructor

Page 32: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Objects

• Creation routines can be called as normal routines

• Note that the !! syntax is somewhat cryptic, and a recent change to the language has changed this for a create command keyword

• Eiffel has no delete operator. This is because, as with Java, Eiffel is garbage collected

Page 33: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Etc

• Class variables: variables which do not have one copy per class of objects. The Eiffel equivalent for doing this is once routines

• Eiffel does not have...– Gotos are not needed, as the Eiffel style is to write small

routines– Global variables are a sign of poor structuring use once

routines instead– Type casts to make up for a flawed type system– Pointers with their associated problems

• Code must be structured in classes

Page 34: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Syntax and Semantics

Page 35: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Some constructs

• Comments are introduced by --

• Grouped entities are terminated by the keyword end, no begin keyword

• No semicolons, optionally be placed between instructions

Page 36: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Style

• Keywords are shown in bold

• User named entities in italic

• Class names are given in uppercase

• Eiffel is not case sensitive, so it is up to the programmer to follow style conventions.

• More than one words separate the constituent words with underscore ‘_’

Page 37: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Access specifiers

• Any set of features introduced by the feature keyword can be exported to other specific classes

• ANY and NONE

• There is no strict equivalent to private, as Eiffel believes it is not sensible to restrict visibility in subclasses.

Page 38: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Access specifiers

Page 39: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Basic Types

• BOOLEAN not, or, and, implies, or else, and then

• INTEGER +, -, *, //, \\, ˆ, <, >, <=, >=

• REAL +, -, *, /, ˆ, <, >, <=, >=

Page 40: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Conditional

Page 41: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Iterations

• There is only one form of iteration in Eiffel

Page 42: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Procedures

Page 43: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Functions

• The value to be returnedresult := expression

Page 44: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Redefinition

Page 45: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Renaming

Page 46: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Counterclass

          COUNTER

feature -- Access item: INTEGER     -- Counter's value.

feature -- Element change increment is  -- Increase counter by one.

   do             item := item + 1   end

decrement is -- Decrease counter by one.   do             item := item - 1   end

reset is -- Reset counter to zero.   do             item := 0   end

end

Page 47: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

Questions

Page 48: Eiffel Naeem Esfahani University of Tehran "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide.

If Time!

• Native C and C++

• Simplicity

• First release instead prototype

• Melting ice