Difference between revisions of "Void"
(Somewhat fixed the translation. Should be checked by a native speaker though.) |
m (11 revisions: initial import from SamrtEiffel Wiki - The Grand SmartEiffel Book) |
||
(7 intermediate revisions by the same user not shown) | |||
Line 42: | Line 42: | ||
==<TT>Current</TT> is never <TT>Void</TT>!== |
==<TT>Current</TT> is never <TT>Void</TT>!== |
||
− | From the principle of object-oriented programming itself, |
+ | From the principle of object-oriented programming itself, |
− | points to an objet. |
+ | [[Current|<TT>Current</TT>]] always points to an objet. |
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. |
Revision as of 22:50, 3 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:
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.