Recently as I was conversing with my young friend, he looked at some of my code and wondered why I was using a zero or null or empty string (“” or ‘ ‘ ) instead of using one wherever I wanted.
Programming is an interesting though weird or confusing discipline, especially to the novice things don’t mean a lot because most novices concentrate on the output than the efficiency and effectiveness of the output. For the mature programmers optimization is key, after all at the end of the day a user wants something working but requires less attention than something erroneous and slow.
So let’s get to it. How does null, empty string and zero differ?
First of all the similarity is of the three is that they are all values to variables and mostly used as the initial value of a variable.
Second the empty string and null will usually output nothing if printed on the screen.
Differences might be defined differently per programming language.
For example in Python there is no null but there is None which means the same as null in other programming languages.
PHP 4+ we use gettype( ) function to find out the datatype of the value stored in the variable. For example gettype( null ) will return for NULL.
So be careful initializing variables with ” especially if they will be used in mathematical expressions.
Though 0 or 1 might represent false/true they are not treated boolean data types.
It’s always good to code what a programmer and fellow programmers understand to avoid spending time in refactoring than improving functionality and optimization.
It’s also important to ship a software which will give more predictable results than not to avoid the users plucking hair out of their heads, assuming they’re wrong yet it’s the programmer is the calprit.
DataTypes determine how big your program will be and how it nay handle memory, avoid confusing by planing to code rightfully from the beginning.
This tutorial assumes you have some programming knowledge and some level of practice with the one or more of the programming languages cited in the tutorial.
The tutorial is dedicated to Were Calvin a Ugandan African motion graphics designer and emerging front-end developer practicing at Gagawala Graphics limited.