Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Eiffel - a humble introduction
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Tue Feb 17, 2004 10:07 pm   Post subject: Eiffel - a humble introduction

The Eiffel programming language is commonly associated with the concept of Design by Contract, which more or less extends object-oriented design by strictly enforcing conditions by which routines may run.

Bertrand Meyer created the Eiffel programming language as an implementation of his ideas about Design by Contract and general good software construction practices.

Before showing syntax examples, it's important to understand a few things about the language itself, and the terminology associated with it. Eiffel is a purely object-oriented language. Moreso even than Java, everything, including basic integer types are objects. More along the lines of C++, Eiffel supports multiple inheritance and operator overloading. Eiffel does not, however, support overloaded method names.

I've been using the term "methods", but Eiffel does not use this term. Eiffel may have variables, and routines. Routines are further broken down into functions and procedures. A function returns a value, but a procedure does not. A procedure may effect the state of variables outside its own scope, but function may not. These differences are enforced. A function cannot be used and not have its return value assigned (or "bound") to something.

When variables or routines are part of a class, they are known as "features". Rather than being "public", "private", or "protected", features are available to objects of certain other classes. ANY and NONE stand in for public and private.

Eiffel is garbage-collected, so destructors are not necessary. Additionally, Eiffel does not have constructors, but rather "creation" routines. These are procedures which can be used with the "create" keyword, and serve to initialize instance variables. This is similar to C++'s "new" keyword, but any procedure whose name is in the "creation" clause of the class can be used.

Each class in Eiffel is stored in its own file, with a name matching that of the class, plus a ".e" extension. Though Eiffel class names are all capital letters, the file name should be lower case.

One class serves as a "main" for the program, with its "make" creation routine containing the code Java programmers might put in:

Quote:
public static void main(String[] args)


So, without further ado, I give you "Hello, world!"...

Quote:

class
HELLO_WORLD
creation -- creation clause
make
feature { ANY } -- public
make is
local
-- just for demonstration, some local vars
hello : STRING is "Hello" -- a constant string variable
world : STRING
do
world := "world"
std_output.put_string(hello + ", " + world + "!")
std_output.put_new_line
-- look Ma! No parentheses
-- when parens aren't needed.
end
end


Now, let's say this thrice.

code:

class
   HELLO_WORLD
creation
   make
feature { NONE }
   say_hello_world is
      do
         std_output.put_string("Hello, world!")
         std_output.put_new_line
      end
feature { ANY }
   make is
      local
         i : INTEGER
      do
         from
            i := 1
         until
            i > 3
         loop
            say_hello_world
            i := i + 1
         end
      end
end


Of course, this is all very basic. I welcome questions.

those code tags are too bugged... at random it seems... bah - Tony
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: