On 5/4/07, Aaron DC <[EMAIL PROTECTED]> wrote:
The difference between my suggestion and the way C++ (for example, I
won't speak to Java although it may be the same) implements method
overloading is C++ does it at compile time and we're doing it at runtime.

Correct (correct for Java too).

To the best of my knowledge, C++ uses name mangling to implement method
overloading. So at compile time, the declarations:

Again, correct. The static type signature is compiled into the name of
the method.

This allows the runtime to be very efficient - there is no name lookup
(the compiler did it), there is no type lookup (the compiler did it).
It's just a function call.

This *cannot* be done in a dynamic language without horrible efficiency issues.

Consider this:

<cfunction name="foo">
<cfargument name="a" type="string">
<cfargument name="b" type="numeric">
...
</cffunction>

<cfunction name="foo">
<cfargument name="a" type="numeric">
<cfargument name="b" type="string">
...
</cffunction>

What does this do:

foo(1,2)
foo("1","2")
foo(1e2,"2e3")
foo("1e-3","1e-")

At runtime, ColdFusion would have to examine all possible type
conversions across all arguments and decide on the "best match" (or
that the call was ambiguous). Can you imagine how slow that would be?

The rules in C++ are extremely complex - but they are compile-time
rules. The rules in CF would have to be pretty much as complex because
of all the possible implicit conversions (42 is both numeric and a
string depending on context, "42" is also both numeric and a string,
an object can be passed as a struct or as that object type or any base
type of it, the arguments scope can be passed as both an array and a
struct etc etc). But those rules would have to be applied, dynamically
at runtime, on every call.

Also consider that overriding rules become a lot more complex with
overloading. If your base CFC defines the first foo() above and an
extended CFC defines the second foo() - is it an override (it is
today) or does it create an overloading set or what?
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org

Reply via email to