Status/Resolution/Reason: Closed/Deferred/EnhancementRequired
Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)
Created: 10/15/2012
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: 1
G'day
Extract from blog article:
http://adamcameroncoldfusion.blogspot.co.uk/2012/09/callbacks-function-expressions.html
{quote}
This is something else not implemented in CF10 although perhaps should have been. This time it did not occur to me to request them (mostly because I was only superficially aware of the concept at the time). One shortfall of CFML's support for callbacks is that one can only be as precise as saying the calling-function needs to be a function. However it's seldom going to be the case that that is the full extent of the requirements of the callback function. Taking the earlier sorting function as an example, the comparator callback function needs to fulfil this function prototype:
Boolean function(required any, required any)
This ain't a great example because the two arguments can be anything, but the key thing is it takes two required arguments, and returns a boolean. If the function does not do that, then it cannot be used as this callback (because the function using it will break). The way callbacks are implemented in ColdFusion make it impossible to specify the callback's requirements.
This is where delegates come in. A delegate is to a function what an interface is to a CFC: it specifies a minimum requirement level.
So one might have this:
public Boolean delegate Comparator(any firstElement, any secondElement);
And in the function requiring the callback, have this:
public any sorter(any toSort, Comparator comparator);
This means that if we tried to call sorter() like this:
String function comparator(string first, string second){
// etc
}
sorted = sorter(myData, comparator);
It'll error with something along the lines of "invalid callback the callback passed to sorter() was not of type Comparator" or something similar (because a Comparator needs to return a boolean, and the function we're trying to use returns a string). Just the same as if one passes any other sort of invalid argument type to a function.
Not earthshattering, but would be useful to tightening up code, and report any errors closer to their source than their side-effect.
{quote}
--
Adam
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3346444
External Customer Info:
External Company:
External Customer Name: Adam Cameron.
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: