ColdFusion has a long history of being able to seamlessly cast between String and non-String data types. Which is why the following all yield true:
isBoolean( "yes" )isBoolean( "true" )isBoolean( true )isBoolean( 1 )
I many cases, this is great functionality. However, when validating data pre-persistence layer, it would be nice to have access to more strict testing. I think this could either be available as an optional argument, like:
isBoolean( "yes", false )=>trueisBoolean( "yes", true )=>false
… where that second argument is a “strict mode” setting.
Or, a better option would be a series of new isStrict{type}() functions like:
isStrictBoolean()~=isInstanceOf( value, "java.lang.Boolean" )isStrictNumberic()~= “???”isStrictDate()~=isInstanceOf( value, "java.util.Date" )
ASIDE: We already have some prior art here in terms of
isNumericDate(), which is basically a lower-level validation on theisDate()BIF.
I’ve never really had to think about this before because I’ve always saved data to a Relational Database system where the DB schema basically enforces this for me. But, if i needed to store data in a Document store, or a flat-file, or something more loosey-goosey, then enforcing strict data types pushes “left” and it becomes my responsibility.
