Eiffel Programming Language
By
David Riley and Jason Thorpe
December 3, 2002
Eiffel Overview
Object-oriented
Motivation – designed to avoid some of the pitfalls of older
OOP languages
Introduced in 1985
Created by Bertrand Meyer
Developed by his company Interactive Software
Engineering
Named after Gustav Eiffel (designer of Eiffel Tower)
“The Eiffel Tower was completed on time and within
budget, which should happen if you use Eiffel for your
software projects ”
http://www.engin.umd.umich.edu/CIS/course.des/cis400/eiffel/eiffel.html#history
Eiffel Milestones
1985: Bertrand Meyer and Jean Marc Nerson begin development of Eiffel
1986: 1st Eiffel compiler presented (April), 1 st Customer Deliveries
(December)
1987: Eiffel achieves commercial success
1991: Non-profit International Consortium for Eiffel (NICE) is founded;
NICE controls the standardization of the Eiffel language
1991: Publication of "Eiffel the language" by Bertrand Meyer (Prentice
Hall)
1995: NICE presents Eiffel Library Kernel Standard (ELKS), which sets
standards for basic Eiffel classes.
1997: NICE and the Eiffel Consortium organize Eiffel Struggle `97. Prizes
awarded for Eiffel applications and Eiffel libraries.
http://www.halstenbach.de/eiffel/eiffel8.htm
Supporting Platforms
Eiffel Software's EiffelStudio environment is
available for the major industry platforms:
Windows, Linux, Unix, and VMS.
These implementations are all source-code
compatible.
Eiffel Compilers
ISE Eiffel v5.2
free time-limited evaluation version; Windows and Unix
www.eiffel.com
SmartEiffel the GNU Eiffel compiler
Free; All ANSI C machines
http://smarteiffel.loria.fr/
Iss-base
Commercial – free 90-day trial version; Windows and Unix
NonCommercial – free; Windows and Linux
http://www.halstenbach.com/
Visual Eiffel
Commercial – free evaluation (limited features); Windows and Linux
http://www.object-tools.com/
Distinctive Features
Portable – runs on many platforms
Open System – has a C/C++ interface for code reusability
Melting Ice Technology – combines compilation with byte
code interpretation for faster turnaround times after a change
has occurred.
Design by Contract – enforced with assertions through
invariance, preconditions and postconditions.
Automatic Documentation – documentation produced
quickly by single click.
Distinctive Features (cont.)
Multiple Inheritance - a class can inherit from multiple
parents
Repeated Inheritance - a class inherits from another
through two or more parents
Statically Typed – catch errors at compile time; not run
time
Dynamically Bound – guarantee of right operation being
applied depending on target object
Areas of Application
Eiffel is not intended for any specific area but is used
in:
Teaching
not stuck within the confines of a single environment
Eiffel allows students to focus on the concepts, not notational details
Educators have remarked that it is easier to teach C++, Smalltalk, or Java
once Eiffel techniques are mastered.
Rapid Prototyping
covers analysis, design, and implementation in a single framework
Financial Applications
I/O in Eiffel
Attributes (Data) Input routines
last_character:CHARACTER read_character
last_integer:INTEGER read_integer
last_real:REAL read_real
last_string:STRING read_line -- result stored in
last_string
last_boolean :BOOLEAN
read_word -- result stored in
Output routines last_string
put_character(c:CHARACTER) read_boolean
put_integer(i:INTEGER)
put_real(r:REAL)
put_string(s:STRING)
put_boolean(b:BOOLEAN)
put_new_line
Basics in Eiffel
I/O example:
io.put_string(“Enter an Integer “);
io.read_integer;
int1 := io.last_integer;
Basic Data Types
INTEGER, CHARACTER, REAL, STRING,
BOOLEAN
Comments (--)
Control Structures
Looping Example
from from
--initialization i := 1
until until
done -- BOOLEAN condition i = 10
loop loop
-- executable statements io.put_int (i);
end io.new_line;
i := i + 1;
end
Control Structures
Conditional Example
... ..
if x > 10 then if x > 0 then
... statements ... io.put_string(“x is positive”);
elseif x > 5 then elseif x < 0 then
... elseif statements ... io.put_string(“x is negative”);
elseif x > 0 then else
... more elseif statements ... io.put_string(“x is 0”);
else end
... else statements ...
end
Control Structures
Multi-Branch Example
...
inspect input_character; State : INTEGER;
State_1, State_2, State_3 : INTEGER is unique;
when 'y' then
... statements ...
inspect State
when 'n' then
... statements when State_1 then
some_action;
else when State_2 then
... if no match is found some_other_action
end when State_3 then
another_action;
else
no_action;
end;
Arrays in Eiffel
Declaration
scores :ARRAY[INTEGER];
Creation
!!scores.make(1,100)
Functions
count, lower, upper.
Insertion
scores.put(<value>, <index>);
Access
scores.item(<index>);
Design by Contract
class COUNTER
feature
count: INTEGER
increment_by (inc: INTEGER) is
require
inc > 0
do
-- Implementation goes here
ensure
count = old count + inc
end
end
Hello World
class HELLO_WORLD
creation
make
feature
make is
do
print("Hello World!!!! %N")
end --make
end -- class HELLO_WORLD
Hello World (cont.)
Class name - end (required)
Creation Clause – specifies the routines that
may be called.
Feature Clauses – describes class features.
Type System
Strongly typed
Two categories: reference type, expanded
type
Five basic types (expanded): INTEGER,
REAL, DOUBLE, CHARACTER and
BOOLEAN
Sorting Example
class ARRAY_EXAMPLE
creation
start
feature
store:ARRAY[INTEGER];
-- function fill_array fills array with integers entered from keyboard
fill_array is
local
index:INTEGER;
do
from index = store.lower -1
until index = store.upper
loop
index := index + 1;
io.readint;
store.put(io.lastint,index);
end -- loop
end -- fill_array
Sorting Example (cont.)
-- function print array will print contents of array
print_array is
local
index:INTEGER;
do
from index := store.lower-1
until index = store.upper
loop
index := index + 1;
io.putint(store.item(index));
end -- loop
end -- print_array
Sorting Example (cont.)
-- function sort array will sort the elements of the array
sort_array is
local
sorted:BOOLEAN;
temp_item: INTEGER
index, last :INTEGER;
do
from
last := store.upper;
sorted := false;
until sorted or else last = store.lower
loop
from sorted := true
index := store.lower -1
last := last-1
until
index = last
Sorting Example (cont.)
loop
index := index + 1;
if store.item(index) > store.item(index+1)
then
-- swap element with successor element
temp_item := store.item(index+1);
store.put(store.item(index),index+1);
store.put(temp_item,index);
sorted := false;
end -- if
end – loop
end -- loop
end -- sort_array
Sorting Example (cont.)
start is
do
!!store.make(1,7);
fill_array;
sort_array;
print_array;
end -- start
end -- ARRAY-EXAMPLE
References
http://www.engin.umd.umich.edu/CIS/course.des/cis400/eiffel/
eiffel.html#history
http://www.halstenbach.de/eiffel/eiffel8.htm
http://www.faqs.org/faqs/eiffel-faq/
http://www.pi.informatik.tu-darmstadt.de/inf1/eiff-ref/