04 June 2019

Neoxam: Null vs Empty Quotes

I want to start writing about my experiences with Neoxam development since there are not very many resources out there. I am by no means an expert, so please feel free to comment on any corrections. Hopefully someone will find these posts to be helpful.

Disclaimer: I do not work for Neoxam. My advice/knowledge in these posts do not represent my employer and are just general tips/knowledge. Use them at your own risk.

Null vs Empty Quotes 
Neoxam uses a propriety scripting language. While many languages include the null keyword, Neoxam does not.

If you were to declare a variable that ends up empty and compare it to null, that comparison may work, but maybe not for the reason you think. When your variable is not assigned anything, it is null/empty. When you compare it to null, what you are actually doing is comparing it to another undefined variable.

     sql := "SELECT * FROM  MyTable WHERE custID in ('1', '2')"; //Assume this does not return anything
     myVariable := sqlResult(sql);
     if(myVariable == null){
          //do something
     }
   
So in most cases this comparison will work because you are comparing your empty variable with an undefined variable.

This example is only one very specific scenario. You need to be cautious as null may not work as expected in all scenarios. You can also encounter issues if someone else assigns a value to the variable null. 

A better approach is to us the empty string - "". You could even define the variable null to contain it, although I prefer to use "" to avoid confusion.

    if(myVariable == ""){
          //do something
     }

Or

      null := "";
      if(myVariable == null){
          //do something
     }
 

No comments:

Post a Comment