Beginner

Hello World in Eiffel

Your first Eiffel program - the classic Hello World example with Docker setup using EiffelStudio

Every programming journey starts with Hello World. Let’s write our first Eiffel program using EiffelStudio, the primary Eiffel development environment.

The Code

Create a file named hello.e:

class
    HELLO

create
    make

feature

    make
        do
            print ("Hello, World!%N")
        end

end

Understanding the Code

Eiffel is a pure object-oriented language - everything is a class. Let’s break down each part:

  • class HELLO - Declares a class named HELLO (class names are uppercase by convention)
  • create make - Specifies that make is a creation procedure (constructor)
  • feature - Introduces a section of class features (methods and attributes)
  • make - The entry point procedure called when the program runs
  • do ... end - Marks the executable body of the procedure
  • print ("Hello, World!%N") - Outputs text to the console
  • %N - Eiffel’s newline character (similar to \n in C-like languages)

The Class Structure

Every Eiffel program is built from classes. The minimal structure is:

class
    CLASS_NAME

create
    creation_procedure_name

feature

    creation_procedure_name
        do
            -- code here
        end

end

Eiffel enforces that every object is properly initialized through creation procedures (constructors).

The Feature Section

feature introduces class members. You can have multiple feature clauses with different export statuses:

feature          -- Available to all clients
feature {NONE}   -- Private to this class
feature {FRIEND} -- Available only to FRIEND class

The Print Procedure

print is inherited from class ANY, which all Eiffel classes implicitly inherit from. It accepts any object and converts it to a string representation for output.

Running with Docker

Eiffel requires a configuration file (.ecf) and compilation before running. Here’s how to do it with Docker:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Create the source file
cat > hello.e << 'EOF'
class
    HELLO

create
    make

feature

    make
        do
            print ("Hello, World!%N")
        end

end
EOF

# Compile and run with EiffelStudio
docker run --rm -v $(pwd):/app -w /app eiffel/eiffel:latest sh -c 'echo PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iSVNPLTg4NTktMSI/Pgo8c3lzdGVtIHhtbG5zPSJodHRwOi8vd3d3LmVpZmZlbC5jb20vZGV2ZWxvcGVycy94bWwvY29uZmlndXJhdGlvbi0xLTIyLTAiIG5hbWU9ImhlbGxvIiB1dWlkPSIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEiPgo8dGFyZ2V0IG5hbWU9ImhlbGxvIj48cm9vdCBjbGFzcz0iSEVMTE8iIGZlYXR1cmU9Im1ha2UiLz48c2V0dGluZyBuYW1lPSJjb25zb2xlX2FwcGxpY2F0aW9uIiB2YWx1ZT0idHJ1ZSIvPgo8bGlicmFyeSBuYW1lPSJiYXNlIiBsb2NhdGlvbj0iJElTRV9MSUJSQVJZL2xpYnJhcnkvYmFzZS9iYXNlLmVjZiIvPjxjbHVzdGVyIG5hbWU9InJvb3RfY2x1c3RlciIgbG9jYXRpb249Ii4iLz48L3RhcmdldD48L3N5c3RlbT4K | base64 -d > hello.ecf && ec -batch -config hello.ecf -c_compile && ./EIFGENs/hello/W_code/hello'

Understanding the Docker Command

  • ec - The Eiffel compiler command
  • -batch - Run without user interaction
  • -config hello.ecf - Use the specified configuration file
  • -c_compile - Automatically compile the generated C code
  • ./EIFGENs/hello/W_code/hello - Run the compiled executable

The Eiffel compiler:

  1. Parses and analyzes your Eiffel code
  2. Generates optimized C code
  3. Compiles the C code to a native executable
  4. Places the result in EIFGENs/<system>/W_code/

The ECF Configuration File

Eiffel projects require an ECF (Eiffel Configuration File) that specifies:

  • system name - The project name
  • target - Build configuration settings
  • root class and feature - The entry point
  • libraries - Which Eiffel libraries to use
  • clusters - Where to find your source files

The base library provides fundamental classes like STRING, INTEGER, and the print procedure through class ANY.

Expected Output

Hello, World!

Alternative Approaches

Eiffel offers several ways to output text:

Using io.put_string

The more “proper” Eiffel style uses io:

class
    HELLO

create
    make

feature

    make
        do
            io.put_string ("Hello, World!")
            io.put_new_line
        end

end
  • io - An inherited feature from ANY providing console I/O
  • put_string - Outputs a string without newline
  • put_new_line - Outputs a newline

Eiffel style guides recommend documenting classes and features:

note
    description: "Classic Hello World program"
    author: "Your Name"
    date: "$Date$"

class
    HELLO

create
    make

feature -- Initialization

    make
            -- Print greeting message.
        do
            print ("Hello, World!%N")
        end

end
  • note - Metadata section for documentation
  • -- Comment - Comments start with double dash
  • feature -- Initialization - Feature clause with a comment header

Eiffel Naming Conventions

ElementConventionExample
Class namesALL_CAPSHELLO, BANK_ACCOUNT
Feature nameslowercasemake, deposit
Local variableslowercasei, count
Constantslowercasemax_size
File namesclass_name.ehello.e, bank_account.e

Note: One class per file, filename matches class name (lowercase).

The Eiffel Compilation Process

Eiffel uses a unique compilation approach:

hello.e → ec compiler → C code → C compiler → executable

Compilation Modes

  1. Workbench (W_code) - Fast compilation for development
  2. Finalized (F_code) - Optimized for deployment

For Hello World, workbench mode is sufficient. For production, you’d use:

1
2
ec -batch -config hello.ecf -finalize -c_compile
./EIFGENs/hello/F_code/hello

Why Generate C?

Eiffel compiles to C for several reasons:

  • Portability across platforms
  • Leverages mature C compiler optimizations
  • Easy integration with C libraries
  • No runtime dependency (unlike JVM languages)

Common Beginner Mistakes

Missing Create Clause

class HELLO
feature
    make
        do
            print ("Hello, World!%N")
        end
end
-- Error: no creation procedure specified

Every class that will be instantiated needs a create clause.

Wrong String Escape

print ("Hello\nWorld")   -- ❌ Wrong: C-style escape
print ("Hello%NWorld")   -- ✅ Correct: Eiffel-style escape

Eiffel uses % for special characters:

  • %N - Newline
  • %T - Tab
  • %% - Percent sign
  • %" - Double quote

Class Name Mismatch

The class name must match the filename (case-insensitively):

  • hello.e should contain class HELLO
  • bank_account.e should contain class BANK_ACCOUNT

Installing EiffelStudio Locally

If you prefer to run Eiffel without Docker:

Ubuntu/Debian:

1
2
3
4
5
6
7
# Download from eiffel.com
wget https://ftp.eiffel.com/pub/download/24.05/eiffelstudio-24.05-linux-x86-64.tar.bz2
tar xjf eiffelstudio-24.05-linux-x86-64.tar.bz2
# Set environment variables (add to ~/.bashrc)
export ISE_EIFFEL=/path/to/Eiffel_24.05
export ISE_PLATFORM=linux-x86-64
export PATH=$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin:$PATH

macOS:

1
2
# Download the macOS version from eiffel.com
# GUI installer available

Windows:

1
2
# Download the Windows installer from eiffel.com
# Run the setup wizard

After installation, you can use the EiffelStudio IDE or the ec command-line compiler.

A Bit of History

Eiffel was created by Bertrand Meyer in 1986 at Interactive Software Engineering (now Eiffel Software). Meyer, who had worked with Ada and formal specification methods, designed Eiffel to bring mathematical rigor to software development.

The language introduced Design by Contract - the idea that software components should have explicit contracts (preconditions, postconditions, and invariants) just like business contracts. This revolutionary concept influenced virtually every object-oriented language that followed.

The name “Eiffel” comes from the Eiffel Tower, symbolizing the language’s goal of combining engineering precision with elegant design.

Why Eiffel for Hello World?

Even in this simple example, you see Eiffel’s philosophy:

  1. Pure Object-Orientation - Everything is a class, including the program
  2. Explicit Initialization - Creation procedures ensure proper setup
  3. Clear Structure - Keywords like class, create, feature, do, end make structure visible
  4. Configuration Separate from Code - ECF files separate build settings from source

These features become essential in large systems where Eiffel’s Design by Contract shines.

Next Steps

Continue to Design by Contract to learn about Eiffel’s most powerful feature - preconditions, postconditions, and invariants that make your code provably correct.

Key Takeaways

  1. Everything is a class in Eiffel - there’s no “main” function
  2. Creation procedures (constructors) must be explicitly declared with create
  3. print outputs to console, %N is the newline character
  4. ECF files configure the project, libraries, and build settings
  5. Eiffel compiles to C, producing native executables
  6. Class names are UPPERCASE, feature names are lowercase
  7. One class per file, filename matches class name

Running Today

All examples can be run using Docker:

docker pull eiffel/eiffel:latest
Last updated: