Null object: Difference between revisions

From Rosetta Code
Content added Content deleted
(Python)
Line 31: Line 31:
=={{header|MAXScript}}==
=={{header|MAXScript}}==
<pre>if obj == undefined then print "Obj is undefined"</pre>
<pre>if obj == undefined then print "Obj is undefined"</pre>

=={{header|Python}}==

if x == None:
print "x is None"


=={{header|Ruby}}==
=={{header|Ruby}}==

Revision as of 17:27, 2 August 2008

Task
Null object
You are encouraged to solve this task according to the task description, using any language you may know.

Null (or nil) is the computer science concept of an undefined or unbound object. Some languages have an explicit way to access the null object, and some don't.

Show how to access null in your language by checking to see if an object is equivalent to the null object.

Ada

<Ada>with Ada.Text_Io;

if Object = null then

  Ada.Text_Io.Put_line("object is null");

end if;</Ada>

C

C's access to null is by way of a macro which simply evaluates to 0. <c>if(object == NULL){

  printf("object is null");

}</c>

C++

C++'s access to null is (as in C) by way of a macro which simply evaluates to 0. <cpp>#include<stdio>

if(object == NULL){

  cout << "object is null";

}</cpp>

Java

<java>if(object == null){

  System.out.println("object is null");

}</java>

MAXScript

if obj == undefined then print "Obj is undefined"

Python

 if x == None:
   print "x is None"

Ruby

if object == nil

  puts "object is null"

end