ryan
03/11/2022, 5:29 PMisValid
to be allowed as a member function?bdw429s
03/11/2022, 5:30 PMbdw429s
03/11/2022, 5:30 PMryan
03/11/2022, 5:33 PMbdw429s
03/11/2022, 5:34 PMbdw429s
03/11/2022, 5:34 PMbdw429s
03/11/2022, 5:35 PMryan
03/11/2022, 5:35 PMryan
03/11/2022, 5:39 PMryan
03/11/2022, 6:00 PMisvalid
, as a member function, does not work in CF 2021, either.ryan
03/11/2022, 6:06 PMbdw429s
03/11/2022, 6:09 PMbdw429s
03/11/2022, 6:09 PMryan
03/11/2022, 6:11 PMbdw429s
03/11/2022, 6:12 PMbdw429s
03/11/2022, 6:12 PMryan
03/11/2022, 6:12 PMryan
03/11/2022, 6:13 PMryan
03/11/2022, 6:14 PMryan
03/11/2022, 6:14 PMryan
03/11/2022, 6:15 PMbdw429s
03/11/2022, 6:16 PMbdw429s
03/11/2022, 6:16 PMryan
03/11/2022, 6:17 PMryan
03/11/2022, 6:17 PMryan
03/11/2022, 6:25 PMryan
03/11/2022, 6:26 PMbdw429s
03/11/2022, 6:27 PMbdw429s
03/11/2022, 6:27 PMbdw429s
03/11/2022, 6:27 PMisvalid( anyRandomVariable, 'number' )
you CAN'T do
anyRandomVariable.isvalid( 'number' )
ryan
03/11/2022, 6:28 PMbdw429s
03/11/2022, 6:28 PManyRandomVariable
must first be a type that the CF engine has defined to have that member function. Which makes them fairly useless in any sort of libraries or frameworks which need to dynamically handle diverse inputsbdw429s
03/11/2022, 6:29 PMsimpleValue.len()
because it works fine until the simple value is a boolean eye rollbdw429s
03/11/2022, 6:30 PMfunction myFunc( required STRING foo ) {
return foo.len();
}
That will still blow up with
myFunc( true )
bdw429s
03/11/2022, 6:30 PMryan
03/11/2022, 6:32 PMryan
03/11/2022, 6:33 PMbdw429s
03/11/2022, 6:33 PMbdw429s
03/11/2022, 6:33 PMbdw429s
03/11/2022, 6:33 PMbdw429s
03/11/2022, 6:33 PMbdw429s
03/11/2022, 6:34 PMbdw429s
03/11/2022, 6:35 PMmyFunc( 45 )
bdw429s
03/11/2022, 6:35 PM4
return an actual len in the later versions of CFbdw429s
03/11/2022, 6:36 PMryan
03/11/2022, 6:36 PMbdw429s
03/11/2022, 6:37 PMlen()
"behaves" different. it's that it doesn't exist on those data types.bdw429s
03/11/2022, 6:38 PMbdw429s
03/11/2022, 6:39 PMisArray()
, isStruct()
, or isSimpleValue()
as well as UDF arg types all ask the question, "Can this variable be cast INTO this type if we wanted".bdw429s
03/11/2022, 6:39 PMryan
03/11/2022, 6:39 PMbdw429s
03/11/2022, 6:42 PMmyMap = createObject( 'java', 'java.util.HashMap' );
structInsert( myMap, 'foo', 'bar' );
writeDump( myMap.keyArray() )
bdw429s
03/11/2022, 6:43 PMryan
03/11/2022, 6:43 PMbdw429s
03/11/2022, 6:44 PMbdw429s
03/11/2022, 6:44 PMryan
03/11/2022, 6:45 PMbdw429s
03/11/2022, 6:46 PMbdw429s
03/11/2022, 6:46 PMzackster
03/11/2022, 6:49 PMzackster
03/11/2022, 6:56 PMzackster
03/11/2022, 6:57 PMstructKeyList()
is great candidate, st.keyList()
is nicezackster
03/11/2022, 6:57 PMzackster
03/11/2022, 6:59 PMx.isValid("email")
vs isValid("Email",x)
just saves one characterzackster
03/11/2022, 6:59 PMzackster
03/11/2022, 7:00 PMryan
03/11/2022, 7:04 PMzackster
03/11/2022, 7:05 PMryan
03/11/2022, 7:16 PMryan
03/11/2022, 7:19 PMAdam Cameron
isValid
that can be a method of at least some of CFML's data types. eg: myString.isValid("date")
has sensible meaning. myArray.isValid("uuid")
... not so much 😉
However, as @bdw429s points out, that's not as useful as it could be, in generic situations; and also not as flexible as the top level functions can be given the "flexibility" CFML shows in its type handling.
There's also something to be said that type checking (or "type interpretability", which is all isValid
is doing) is perhaps better left to a level outside the type system itself.
---
I think this discussion comes back my frequent observation here: it's just a misunderstanding of "how things work" in OOP that leads to the expectation that someFunction(somethingUsableHere)
should have a direct mapping as someConcreteThing.function()
.
It's easy to confuse one's self when there are identical words in play: ArrayMap()
and Array.map()
, but one needs to understand the usage of array
in the first one does not mean the same thing as in the second one: same word, two different (and legitimate) usages. ArrayMap
does not take an array as a first argument in the same sense that there is an Array
type in the second one. The function signature of ArrayMap
would be something like: Array ArrayMap(SomeVagueArrayInterface a, function f)
, whereas when we talk about Array.map
it is a specific method on that specific Array class. That's just how OOP works. There is no confusion in the reasoning for the implementation, there is just confusion on the part of CFML devs migrating from procedural to OOP CFML.