Status/Resolution/Reason: To Fix//
Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)
Created: 08/22/2013
Components: Language
Versions: 10.0
Failure Type: Enhancement Request
Found In Build/Fixed In Build: Final /
Priority/Frequency: Trivial / Unknown
Locale/System: English / Platforms All
Vote Count: 4
Ref: http://cfmlblog.adamcameron.me/2013/08/brad-wood-makes-interesting-feature.html
Consider adopting some behaviors from languages such as JavaScript or Groovy which allow for more clever conditional statements to be constructed. Consider this ticket a discussion on whether this is even possible and what implications it would have. I assume this might also require an on/off flag such as the null support feature.
This table outlines a suggestion of how the following values would behave when cast to booleans:
Value Truthiness
null false
Number false if 0, otherwise true
String false if "", "false", or "no"; otherwise true.
Array false if empty, otherwise true
Struct false if empty, otherwise true
Object true
This would allow for the full ternary version of the Elvis operator (Assuming full null support):
foo = null;
bar = foo ? foo : "default";
It would also simplify checking for the contents of structs and arrays:
myArray = [1,2.3];
if( myArray ) writeOut("Array has stuff");
myStruct = [];
if( !myStruct ) writeOut("Struct is empty");
I think these changes might be somewhat straightforward and mostly affect the Caster class, but most importantly:
Do we want this in CFML?
Would this have serious implications in backwards compatibility?
Other things to consider that are similar to Groovy would be Java Map, List and Iterator classes. True if not empty, or hasNext() is true.
References:
http://docs.codehaus.org/display/GROOVY/Groovy+Truth
http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3616205
External Customer Info:
External Company:
External Customer Name: Adam Cameron.
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: