Eiffel to C++ terminology mapping

by Loryn Jenkins

Adapted from a comp.lang.eiffel

Introduction

Obviously, this is not complete (and some of it may be wrong), but it's a start. I've never programmed in C/C++ in my life, so no flames please if I get some stuff wrong.
Eiffel                  C++   (-- are comments)
---------------------   ---------------------------------------------

ancestor class          superclass [4]

class                   class

class                   type

class                   module
                           -- in C++ typically, class /= module

class                   struct
                           -- probably deprecated in C++

object                  object

interface               interface

parent class            base class

child class             derived class

child class             derived class [5]

deferred feature        pure virtual function

deferred class          abstract base class

generic class           template

generic parameter       generic parameter

feature                 function
                            -- function = method

feature                 data member

feature                 method
                            -- method = function

function                virtual function [1]
                            -- with non-void return type

fully deferred class    pure virtual base class

command                 virtual function
                            -- with void return type [1]

n/a                     variadic function
                            -- function with unspecified
                            -- number/types of arguments

once function           n/a
                            -- rough equivalent is using
                            -- a static

descendent class        subclass [5]

parent class            base class [4]

Precursor               super()
                            -- excepting that super() is regularly
                            -- used to call *any* feature of the
                            -- superclass so desired

n/a                     global
                            -- rough equivalent is using a once f(x)

attribute               data member

CQS                     n/a

side-effecting function function

creation feature        constructor

`dispose' feature       destructor
   from class MEMORY

garbage collection      #*$(#*%

short form              header
                           -- a separate module

short flat form         n/a

flat form               n/a

assertion               assertion

pre-condition           n/a
                           -- can use ASSERT, but is not
                           -- inheritable

post-condition          n/a
                           -- can use ASSERT, but is not
                           -- inheritable

class invariant         n/a
                           -- can use ASSERT?????

loop variant            n/a
                           -- can use ASSERT

loop invariant          n/a
                           -- can use ASSERT

check                   assert

reference               pointer OR reference OR 'smart' pointer

n/a                     de-reference
                           -- in C/C++ you need to turn a pointer
                           -- to some data into ??? in order
                           -- to access / use that data value

x is deferred end       virtual void x() = 0;

x is do end             virtual void x() { }

frozen x is do end      void x() { }

uniform access          n/a
                           -- access to functions, data members,
                           -- through pointers, or directly (not via
                           -- pointer is all differentiated within
                           -- client code

x.f (expanded object)   x.f()

x.f (reference object)  x->f()
                           -- here, x is a pointer to a class

x.f                     x.f()
                           -- function access

x.f                     x.f
                           -- data member access

n/a                     CLASSNAME :: f
                           -- infix namespace operator

n/a                     :: g
                           -- prefix namespace operator, meaning
                           -- the "global namespace

rename .. end           ::
                           -- scope resolution operator ... selects
                           -- between inherited base classes; must
                           -- be used throughout the code, whenever
                           -- clashing functions are called. In
                           -- practice, C++ers use :: basically any
                           -- time they have inheritance

a: LIST[LIST[INT]]      List <List <int> > a
                           -- Note that if you wrote this as:
                           --    List<List<int>> a
                           --    it would be an error, because the
                           --    >> after int is a shift operator.

a = b                   a == b
(ref equality [6])
                           -- reference semantics if a and b are
                           -- pointers, otherwise value semantics

equal (a,b)             a == b
(value equality)
                           -- reference semantics if a and b are
                           -- pointers, otherwise value semantics)

a /= b                  a != b
(ref equality [6])
                           -- reference semantics if a and b are
                           -- pointers, otherwise value semantics)

not equal (a,b)         a != b
(value equality)
                           -- reference semantics if a and b are
                           -- pointers, otherwise value semantics)

a := b                  a = b
                           -- usually, watch for the overloading
                           -- of this operator in the pure virtual
                           -- function declaration

i := r.to_integer       int i = real r
                           -- be careful of the truncation, if the
                           -- physical representation of these types
                           -- are different, then could cause memory
                           -- errors; officially, could cause an
                           -- "undefined error", which means,
                           -- an implementation dependent error

; ([7]sequence infix)   ;
                           -- mandatory terminator

!! x.make               y = new x
                           -- implicit constructor; multiple
                           -- constructors are differentiated
                           -- by ?????

Result                  return

static type checking    static type checking

once function           static
                           -- member of a class

n/a                     static allocation
                           -- on the heap

n/a                     static
                           -- local variable in a class; whenever
                           -- this function is called, the static
                           -- retains its value from the previous
                           -- invocation.

void: NONE              void

x: ANY                  void*
                           -- used to lose the type information of
                           -- the object being pointed at, meaning
                           -- 'set of all types'

a := a + 1              a = a + 1

a := a + 1              a += 1

a := a + 1              a++
                           -- increment before evaluation

a := a + 1 [8]         ++a
                           -- increment after evaluation

s.append ("string")   s += "string"

s,x:STRING;...equal(s,x) string s,x ... strcmp (s,x)
                           -- beware of the inconsistency
                           -- between different ways of doing
                           -- comparisons with different types

n/a                     cast
                           -- is deprecated, so you should only use
                           -- them "if you have to"

parameter where type    pass by value
is expanded [2]

parameter where type    pass by reference
is reference [2]

n/a                     blocks
                           -- beware the the scope rules!

n/a                     overloaded function
                           -- Eiffel uses dynamic binding
                           -- as sole form of "overloading"

assignment attempt      downcast [3]
                           -- only rough equivalent, using RTTI

multiple inheritance    "beware"

repeated inheritance    "the dreaded diamond inheritance issue"

---------------------   ---------------------------------------------
Eiffel                  C++   (-- are comments)

Notes

[1] I popped the virtual in here to indicate the difference between Eiffel's "dynamically bound by default" policy compared with C++'s "statically bound by default" policy.

[2] Eiffelists don't actually use these terms. Sometimes use "pass by value" or "pass by reference" when dealing with CASE notations; but generally don't 'worry' about this distinction, unless it is integral to the modelling issue at hand. (We don't 'worry' because it is obvious what we're doing, and we don't need to make an explicit choice like C++ers do.)

[3] I'm definitely unsure about this one.

[4] terminological equivalents

[5] terminological equivalents

[6] In Eiffel, = is reference equality for reference types (unless you explicitly set the object to use value semantics), value equality for expanded types.

[7] In Eiffel, ; is defined as a sequence infix operator. Because Eiffel disambiguates between statements without it, and because Eiffel can handle null instructions, it is effectively possible to program:

[8] In Eiffel, you express increment after evaluation by changing to position of the increment statement relative to the other constructs.