Eiffel Programming Language

advertisement
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), 1st 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




Rapid Prototyping


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.
covers analysis, design, and implementation in a single framework
Financial Applications
I/O in Eiffel
 Attributes (Data)
last_character:CHARACTER
last_integer:INTEGER
last_real:REAL
last_string:STRING
last_boolean :BOOLEAN
 Output routines
put_character(c:CHARACTER)
put_integer(i:INTEGER)
put_real(r:REAL)
put_string(s:STRING)
put_boolean(b:BOOLEAN)
put_new_line
 Input routines
read_character
read_integer
read_real
read_line -- result stored in
last_string
read_word -- result stored in
last_string
read_boolean
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
--initialization
until
done -- BOOLEAN condition
loop
-- executable statements
end
from
i := 1
until
i = 10
loop
io.put_int (i);
io.new_line;
i := i + 1;
end
Control Structures
 Conditional
 Example
...
if x > 10 then
... statements ...
elseif x > 5 then
... elseif statements ...
elseif x > 0 then
... more elseif statements ...
else
... else statements ...
end
..
if x > 0 then
io.put_string(“x is positive”);
elseif x < 0 then
io.put_string(“x is negative”);
else
io.put_string(“x is 0”);
end
Control Structures
 Multi-Branch
 Example
...
inspect input_character;
when 'y' then
... statements
when 'n' then
... statements
else
... if no match is found
end
State : INTEGER;
State_1, State_2, State_3 : INTEGER is unique;
...
inspect State
when State_1 then
some_action;
when State_2 then
some_other_action
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/
Download