Difference between revisions of "Void"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
m (11 revisions: initial import from SamrtEiffel Wiki - The Grand SmartEiffel Book)
 
Line 1: Line 1:
[[Category:Book]]
+
[[Category:Smarteiffel]]
   
 
==A definition of <TT>Void</TT>==
 
==A definition of <TT>Void</TT>==

Revision as of 22:16, 4 March 2013


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 objet. Comparing Current with Void has no meaning and such a comparison is also forbidden.