Difference between revisions of "Void"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
(Somewhat fixed the translation. Should be checked by a native speaker though.)
 
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Book]]
 
 
 
==A definition of <TT>Void</TT>==
 
==A definition of <TT>Void</TT>==
   
The <TT>Void</TT> notation corresponds to an expression having no particular type. It is used to indicate the lack of an object.
+
The <TT>Void</TT> notation corresponds to an expression having no particular type. It is used to indicate the <b>lack of an object</b>.
 
<TT>Void</TT> is an elementary predefined and unmodifiable notation.
 
<TT>Void</TT> is an elementary predefined and unmodifiable notation.
 
<TT>Void</TT> can be used like this:
 
<TT>Void</TT> can be used like this:
Line 42: Line 40:
   
 
==<TT>Current</TT> is never <TT>Void</TT>!==
 
==<TT>Current</TT> is never <TT>Void</TT>!==
From the principle of object-oriented programming itself, <TT>Current</TT> always
+
From the principle of object-oriented programming itself,
points to an objet.
+
[[Current|<TT>Current</TT>]] always points to an object.
 
Comparing <TT>Current</TT> with <TT>Void</TT> has no meaning and such a
 
Comparing <TT>Current</TT> with <TT>Void</TT> has no meaning and such a
 
comparison is also forbidden.
 
comparison is also forbidden.

Latest revision as of 21:55, 30 August 2018

A definition of Void

The Void notation corresponds to an expression having no particular type. It is used to indicate the lack of an object. Void is an elementary predefined and unmodifiable notation. Void can be used like this:

if my_variable = Void then
   io.put_string("There's no object :-(")
else
   io.put_string("There's an object !")
end

Of course, to call a method, there must be an object. Thus, it is more frequent to see the opposite test in many programs:

if my_variable /= Void then
   my_variable.a_method
end

Graphically, the lack of an object in a variable or an attribute simply corresponds to:

Graphical representation of Void

Void can also be used on the right side of the assignment sign to voluntarily lose the reference to an object:

my_variable := Void

Of course, after the execution of the previous line, my_variable does not reference any object anymore.

In case of a variable which is an expanded type, the use of Void has no meaning because such a variable always contains an object. Actually, remember that in the case of an expanded variable, the object is directly stored in the variable without an intermediary pointer. It is impossible not to have an object when using an expanded variable. For example, the comparison between a variable of type INTEGER and Void has no meaning because the variable necessarily points out an INTEGER and thus can never correspond to the lack of object. For this reason, it is forbidden to compare Void with a variable of an expanded type.

For the same reasons, the use of Void on the right side of the assignment sign when the left side is of an expanded type is not allowed.

Current is never Void!

From the principle of object-oriented programming itself, Current always points to an object. Comparing Current with Void has no meaning and such a comparison is also forbidden.