Monday, January 25, 2016

What is a null value?

A while ago, my kids were asking me about my work as a software programmer.  They were trying to understand what I was doing exactly all day long, "playing" on a computer with multiple displays.

They were understanding the concept of creating a software by writing coded instructions  but were actually baffled about the concept of variables.  It took a lot of explanations and examples to describe what was a variable but I finally was able to translate my mumbo-jumbo into bags of candies.  

The example was that at any moment, I wanted to keep count of how many laps a racing car had completed around the race track.  Each time the car does a lap, we add another candy into the bag.  The variable is the bag and the value is the amount of candies in the bag.  Technically, we have an Integer, meaning that this bag can only represents whole numbers.  

As we were discussing variable types (integer, strings, double,...), I mentioned that any variable must be initialized before using it or else, we would have a "null" value...  At that moment, I had lost them completely.  One of them replied that a null value is zero (0) so why have a name for a zero value?

The problem here is that I was explaining the concept of variables using quantities.  Saying that the bag had no candies in it or that the bag had zero candies in it, was the same thing.  They were right. I then used a pen and a piece of paper to explain the null value.

I wrote down the number 23 and asked them of many laps was represented.  They all answered twenty-three.  Then I erased the value and wrote 0 (zero).  Again I asked them how many laps and some answered zero, others said none.

Then I erased the number zero and left the piece of paper blank. 
- How many laps now?
- We don't know, you haven't written anything...
- That is a NULL value...

Then they started arguing that "zero" and "blank" was the same thing.  

- Wrong!  Writing "0" means that I had check how many laps were completed and counted no laps so the number of laps completed was "0".  This is an identifiable value.  When nothing was written, it meant that I did not count in any way the number of laps.  No value was available thus leaving the piece of paper blank.

I would have continued explaining the memory allocation or the joy of arrays but that was already too much information for them and they considered that my job must be very dull and complex.

At last, now, they do not think that I am gaming all day long...

Have a great week!

No comments:

Post a Comment