Thursday 8 August 2013

It's getFunctionCalledName(), not getFunctionReferenceName() or getNameFunctionCalledAs(), or getFunctionNameCalledAs()

This is an unabashed "note to self", and will not be of any use to anyone else at all. But there's method in my madness.

The name of the function that returns the name that a function was called using is  getFunctionCalledName(). I never remember this, and I never remember a decent googling string to find it. It's a handy function: sometimes one does not call a function via its originally declared name, and it's handy to know what name was used when calling that function: it returns the name of the function reference used to call the function, not the name of the function.

(This is an attempt at doing some SEO-loading so that things I search for will find this article).

So why would one want to know the name a function was called via? Or even "huh, what do you mean 'the name the function is called as'?". Here's an example:

void function actualFunctionName(){
    writeOutput("actualFunctionName() was called as: #getFunctionCalledName()#<br>");

writeOutput("<hr><h4>Calling actualFunctionName()</h4>");

writeOutput("<hr><h4>Calling actualFunctionName() via reference</h4>");
referenceToFunction = actualFunctionName;

And this outputs:

Calling actualFunctionName()

actualFunctionName() was called as: actualFunctionName

Calling actualFunctionName() via reference

actualFunctionName() was called as: referenceToFunction

So you can see that the function returns the reference used to call the function, rather than the function's original name.

I think getFunctionCalledName() is a bit incomprehensibly named, I suspect because the person deciding on the name perhaps spoke... erm... well Indian English rather than a more western-european one. People will probably rail at that, but Indian English really does have some odd usage rules which results in unexpected word orders sometimes. This comes out in the CF docs sometimes, as well as in function-naming.

I would have thought (this is another SEO-loading exercise... stuff I am inclined to search for) getFunctionReferenceName() might make more sense, as that's actually what it does: it returns the name of the reference used to call the function. or getNameFunctionCalledAs() because that too describes what is going on, with a more normal word order. Because I know the function name doesn't have the word "reference" in it, getNameFunctionCalledAs() is what I usually google for. Or remembering it uses dodgy word order, sometimes I try getFunctionNameCalledAs(), both of which are more comprehensible to me compared to getFunctionCalledName().

To me, getFunctionCalledName() would be a function which takes a string and returns the function called that name as a reference, eg:

callback = getFunctionCalledName("listAppend");
result = appender(data, callback);

That would be jolly handy, but it's not what this function does.

Anyway, that's enough waffle. Hopefully when I try to find WTF the name of getFunctionCalledName() is now, Google will find this page.

If you got this far, bless you for simply reading whatever bullshit I type in.