[Gambas-user] Method Overloading (reprise)

Rob Kendrick gambas-users at ...790...
Mon Jan 17 19:54:44 CET 2005


Brant Wells wrote:
> Thanks for the explanations, y'all.
> 
> I understand it... but couldn't that get confusing if you have two methods or 
> functions with the same name??

I've never found it so, in any of the languages I've used it in.  How 
could it be confusing?  You just think of the parameter type list as 
part of the function name.

> Why not just do
> 
> Sub mysub(myarg as variant)
>  if isnumeric(myarg) then
>   'do something to the number
>  else
>   'do something to the string
> end

This can't be optimised at compile or link time, unlike overloaded 
functions.  (ie, in C++, the linker knows exactly where the right 
function is, so the code that's generated is just a jump there, your way 
requires jumping to one function, and then code executed to do the same 
thing, so it's not as quick.)

-- 
Rob Kendrick
PGP signed or encrypted mail welcome (Key ID: 3651D17A)




More information about the User mailing list