Nothingness & Null (sample training material)

cf-objective cfwheels ColdFusion

Here is a sample of training material for "Introducting ColdFusion on Wheels" on May 10 through May 11 before CF.Objective() in Minneapolis. One of the begining iterations we will cover is "CFML In 100 minutes". Hopefully getting the class on the same level to learning CFWheels. There are only 3 seats left for the class so please sign up.

10. Nothingness & Null

What is nothingness? Is there nothingness only in outer space? Really, when we think of nothing isn’t it just the absence of something? Ok, that’s too much philosophy ColdFusion did not have a way of referring to nothingness until version 9. ColdFusion can recieve a

COLDFUSION
NULL
value from an external source and maintain the
COLDFUSION
NULL
value until you try to use it. ColdFusion will convert the
COLDFUSION
NULL
into an empty string (in the case of queries) or potentially destroy the variable altogether. However now with greater support for
COLDFUSION
NULL
values, ColdFusion allows you to pass in and return a
COLDFUSION
NULL
value from a method.
COLDFUSION
IsNull()
instruction will test for
COLDFUSION
NULL
values and return
COLDFUSION
true
or
COLDFUSION
false
. If you have three eggs, eat three eggs, then you might think you have nothing , but in terms of eggs you have
COLDFUSION
0
. Zero is something, its a number, and its not nothing. A large percentage of the errors you encounter while writing CFML code will involve a variable not existing. You thought something was there, you tried to do something to it, and you can’t do something to nothing so CFML creates an error. Lets rewrite our
COLDFUSION
makeeggs
method to illustrate
COLDFUSION
NULL
:

Tag
<cffunction name="makeeggs" returnType="component"> <cfargument name="quantity" type="numeric"> <cfif (IsNull(arguments.quantity)) /> <cfset this.makeEggs = "How am I supposed to make nothingness number of eggs?" /> <cfelse> <cfset this.makeEggs = "Making your #arguments.quantity# eggs!" /> <cfset this.yourEggs = ArrayNew(1) /> <cfloop condition="#ArrayLen(this.yourEggs)# LT #arguments.quantity#" /> <cfset ArrayAppend(this.yourEggs, "Making an Egg.") /> </cfloop> </cfif> <cfreturn this /> </cffunction>
Script
public component function makeeggs(numeric quantity){ if(IsNull(arguments.quantity)) { this.makeEggs = "How am I supposed to make nothingness number of eggs?"; } else { this.makeEggs = "Making your #arguments.quantity# eggs!"; this.yourEggs = ArrayNew(1); while (ArrayLen(this.yourEggs) < arguments.quantity) ArrayAppend(this.yourEggs, "Making an Egg."); } return this; }

Reload the file, call

COLDFUSION
frank.makeeggs(3)
then try
COLDFUSION
frank.makeeggs()
.