Eiffel Programming Language: by David Riley and Jason Thorpe
Eiffel Programming Language: by David Riley and Jason Thorpe
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
I/O example:
io.put_string(“Enter an Integer “);
io.read_integer;
int1 := io.last_integer;
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.)
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];
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/