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() ``` .
Mike Henke

Written by Mike Henke

Mike Henke (pronounced "hang-kee") is a full-stack developer with 25+ years of experience, evolving from ColdFusion to modern frontend frameworks, AI, and cloud technologies. Based in Omaha, he enjoys time with his wife and three children when not coding.