websolete
08/23/2022, 8:26 PMbdw429s
08/23/2022, 8:30 PMbdw429s
08/23/2022, 8:30 PMbdw429s
08/23/2022, 8:31 PMwebsolete
08/23/2022, 8:31 PMbdw429s
08/23/2022, 8:31 PMBIF( value ) // Doesn't error
value.bif() // also shouldn't error
websolete
08/23/2022, 8:31 PMbdw429s
08/23/2022, 8:32 PMbdw429s
08/23/2022, 8:34 PMif( isSimpleValue( foo ) ) {
foo.len()
}
There is no isString()
in CFML so to have some "simple value" member functions that don't work leaves us stranded by designbdw429s
08/23/2022, 8:35 PMbdw429s
08/23/2022, 8:35 PMbdw429s
08/23/2022, 8:36 PMAdam Cameron
someFunction(canTakeManyTypesAndDealWithThem)
and aSpecificType.aMethodOfThatType()
.
In this example although there's two things called len
, it's just dumb to think they're the same. One is a function that is implemented to take a SimpleType
, the other is trying to use a method len
on a Numeric
object.
This is not complicated.
@bdw429s I'm kinda with you with the "make a sort of SimpleTypeInterface
that all simple types in CFML implement". But it still seems like a bit of a hack when just "devs conceding they're having a brain fart" would be a better solution I think.
Does it make any sense, for argument's sake, that someDate.len()
returns 26? What's the length of a date? Is that a even sensible behaviour to ask about? I mean it does make sense that len(someDate)
returns 26 cos intrinsically it's clear that the len
implementation needs to convert the date to a string before before checking the length of that string. But does it really make sense that the operation of someDate.len()
- and method of the DateTime type, remember - should "convert" someDate
to a string before calling len()
on it? I don't really think it does.
All this justification of
BIF( value ) // Doesn't error
value.bif() // also shouldn't error
isn't really that sensible to me. It's just pandering to devs not engaging their brain. Or... understanding basic programming concepts. I know we set the bar very low for CFML devs, but does it need to be that low?Adam Cameron
Adam Cameron
len(String)
, len(Numeric)
, len(DateTime)
etc are actually all variants of SimpleObject::len
, and SimpleObject
is automagically imported behind the scenes.
But I guess it'd take longer to explain that thinking to a CFML dev than trying to explain function(obj)
is not the same as obj.function()
.
Sigh.websolete
08/24/2022, 1:13 PMbdw429s
08/24/2022, 2:11 PMbdw429s
08/24/2022, 2:16 PMbdw429s
08/24/2022, 2:17 PMbdw429s
08/24/2022, 2:17 PMs='5'
if( isNumeric( s ) ) {
dump( s.max(3) )
}
bdw429s
08/24/2022, 2:17 PMn=5;
if( isSimpleValue( n ) ) {
dump( n.trim() )
}
bdw429s
08/24/2022, 2:17 PMc = new Query();
if( isStruct( c ) ) {
dump( c.keyList() )
}
bdw429s
08/24/2022, 2:18 PMbdw429s
08/24/2022, 2:19 PMthingThatCanBeUsedAsNumeric.numericMember()
should be a safe line of code to write given the current design of the language.bdw429s
08/24/2022, 2:25 PMthingThatCanBeUsedAsNumeric.castNumeric().numericMember()
or
castNumeric( thingThatCanBeUsedAsNumeric ).numericMember()
though at this point, you've typed more than this! 😕
numericBIF( thingThatCanBeUsedAsNumeric )
Adam Cameron
c = new Query();
if( isStruct( c ) ) {
dump( c.keyList() )
}
Well. It really doesn't I guess. I just rolled my eyes and went "well of course CFML does that [f***in stupid language]".bdw429s
08/24/2022, 2:48 PMbdw429s
08/24/2022, 2:51 PMDoes it make any sense, for argument's sake, thatYes, I believe it does. In fact, I literally wrote that code last week when formatting console output in CommandBox I needed to know the exact number of chars in a date to output to the screen to calculate the width. I mean, that's not even a stretch! If it can be output as a string, it has a length. I even did the same thing where I needed to know the length of a number (again for formatting/width purposes) and I had to usereturns 26?someDate.len()
len( YAxisMax )
instead of YAxisMax.len()
because I wouldn't know if the user of my code would be passing their value as a string or a numeric.Adam Cameron
thingThatCanBeUsedAsNumeric.numericMember()
I 95% get where you are coming from. Well I 100% get where yer coming from. Just not 100% convinced yer right. That's the 95%
It comes back to whether one should consider function(object)
should intrinsically be considered analogous to object.function()
. I don't think it needs to be. And your - entirely reasonable point - about thingThatCanBeUsedAsNumeric.numericMember()
presupposes it is analogous.
However CFML is already a clusterfuck of a language, so I guess I don't see why CF and Lucee shouldn't implement thingThatCanBeUsedAsNumeric.numericMember()
and anySimpleValue.analogToFunctionThatTakesASimpleValueWhetherItMakesSenseOrNotOnTheObjectItsBeingCalledOn()
don't exactly make things worse.
I s'pose.
And I also take yer point that it's all well and good teaching the CFMLers to know their objects from their elbows, but this does not help framework code that needs to use generic code. Other than the fact why don't you just stick with function(object)
as that is the already-existing generic CFML handling of such things. Nothing's forcing this generic code to use woolly-type-specific methods when there's a generic function already?bdw429s
08/24/2022, 2:59 PMAdam Cameron
Adam Cameron
itIsABloodyNumericFfs.len()
(for whatever reason, it could be valid), and get back the length of the numeric value if it had .toString()
called on it? I guess not.
myDate.uCase()
..? Well if that's what you decided to do... knock yerself out.
I guess.