When discovering any approach to software construction, however ambitious its goals, it is reassuring to see first a small example of the big picture -- a complete program to print the famous "Hello World" string. Here is how to perform this fascinating task in the Eiffel notation.
You write a class HELLO with a single procedure, say make , also serving as creation procedure. If you like short texts, here is a minimal version:
In practice, however, the Eiffel style rules suggest a better documented version:
The two versions perform identically; the following comments will cover the more complete second one.
Note the absence of semicolons and other syntactic clatter or clutter. You may in fact use semicolons to separate instructions and declarations. But the language's syntax is designed to make the semicolon optional (regardless of text layout) and it's best for readability to omit it, except in the special case of successive elements on a single line.
The indexing clause does not affect execution semantics; you may use it to associate documentation with the class, so that browsers and other indexing and retrieval tools can help users in search of reusable components satisfying certain properties. Here we see two indexing entries, labeled description and author .
The name of the class is HELLO . Any class may contain "features"; HELLO has just one, called make . The create clause indicates that make is a "creation procedure", that is to say an operation to be executed at class instantiation time. The class could have any number of creation procedures.
The definition of make appears in a feature clause. There may be any number of such clauses (to separate features into logical categories), and each may contain any number of feature declarations. Here we have only one.
The line starting with -- (two hyphen signs) is a comment; more precisely it is a "header comment", which style rules invite software developers to write for every such feature, just after the is . As will be seen in "The contract form of a class", page 44 , the tools of EiffelStudio know about this convention and use it to include the header comment in the automatically generated class documentation.
The body of the feature is introduced by the do keyword and terminated by end . It consists of two output instructions. They both use io , a generally available reference to an object that provides access to standard input and output mechanisms; the notation io . f , for some feature f of the corresponding library class ( STD_FILES ), means "apply f to io ". Here we use two such features:
Rather than using a call to put_new_line , the first version of the class simply includes a new-line character, denoted as %N , at the end of the string. Either technique is acceptable.
To build the system and execute it:
Execution starts and outputs Hello World on the appropriate medium: under Windows, a Console; under Unix or VMS, the windows from which you started EiffelStudio.
Copyright Interactive Software Engineering, 2001