480 likes | 594 Views
Eiffel. "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide. Eiffel. Naeem Esfahani University of Tehran. I prefer to have as little as possible to do with Bertrand Meyer. -- Bjarne Stroustrup, 1989. Overview. Introduction & History
E N D
Eiffel "Man cannot discover new oceans unless he has the courage to lose sight of the shore." -- Andre Gide Eiffel Naeem Esfahani University of Tehran
I prefer to have as little as possible to do with Bertrand Meyer -- Bjarne Stroustrup, 1989
Overview • Introduction & History • Design By Contract™ • Elements • Concepts • Syntax and Semantics
Bertrand Meyer • BS from Ecole polythecnique • MS from Stanford University • PhD from Univesite du Nancy • Professor of Software Engineering at ETH in Zurich 2001
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
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
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
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
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
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
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?
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
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
Pre and postconditions • Preconditions and postconditions are associated with routines of a class
Pre and postconditions • The preconditions must be true when the routine is called • Postconditions must have been established when the routine terminates
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
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
Libraries • Classes that frequently appear • Reuse • EiffelBase: • INTEGER, REAL, STRING, LISTs, ARRAYs • Libraries are not defined as part of the Eiffel language
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
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
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 renameclause • Redefinition • Inheritance is one of the fundamental mechanisms for reuse • Polymorphism
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
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
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
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
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
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
Some constructs • Comments are introduced by -- • Grouped entities are terminated by the keyword end, no begin keyword • No semicolons, optionally be placed between instructions
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 ‘_’
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.
Basic Types • BOOLEAN not, or, and, implies, or else, and then • INTEGER +, -, *, //, \\, ˆ, <, >, <=, >= • REAL +, -, *, /, ˆ, <, >, <=, >=
Iterations • There is only one form of iteration in Eiffel
Functions • The value to be returned result := expression
Counter class 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
If Time! • Native C and C++ • Simplicity • First release instead prototype • Melting ice