Forked from mnem/MakeYourBooleanChecksBoolean.as
Created
March 19, 2010 17:58
Revisions
-
alecmce revised this gist
Mar 19, 2010 . 1 changed file with 8 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,30 @@ // meh... var iAmAStringInstance :String = ""; var iAmANullString :String = null; if(iAmAStringInstance) { trace("iAmAStringInstance is neither null nor empty"); } else { trace("iAmAStringInstance is either null or empty"); } if(iAmANullString) { trace("iAmANullString is neither null nor empty"); } else { trace("iAmANullString is either null or empty"); } // Trace outputs: // // iAmAStringInstance is either null or empty // iAmANullString is either null or empty // // Right. Not particularly good, but not particularly bad either. -
mnem created this gist
Mar 19, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ // This is just one of the reasons why // treating null as a boolean false // is Bad and Wrong var iAmAStringInstance :String = ""; var iAmANullString :String = null; if(iAmAStringInstance) { trace("iAmAStringInstance: That there is an instance!"); } else { trace("iAmAStringInstance: That there is a null object!"); } if(iAmANullString) { trace("iAmANullString: That there is an instance!"); } else { trace("iAmANullString: That there is a null object!"); } // Trace outputs: // // iAmAStringInstance: That there is a null object! // iAmANullString: That there is a null object! // // As I said, both Bad and Wrong ;)