Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is Method Overloading a good or bad thing?
Message
From
07/07/2004 10:53:31
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
07/07/2004 10:47:10
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00919869
Message ID:
00921411
Views:
15
>>>One more: the overloaded methods should be doing the same thing for different sets of parameters. Are we sure everyone is following that sameness thing? The code may be wildly different. We may have a method which says "hello world" when passed a string, and the same-name method which says "go to where you came from" when passed a number. All syntactically correct, and within the rules, except semantical. Or, nine out of ten same-name methods do it the same way, one does it a little different. Go catch the bug.
>>
>>It sure is possible to abuse this feature. But you can also write overloaded methods that do essentially the same thing.
>
>One can do nasty things in pretty much any language (spoken ones included :). I meant debugging - with the code in one place, it is much simpler to find.

For lack of experience, I really can't tell. But I imagine that you may have several versions of the code, for different parameters, but the compiler will substitute the correct version - and if you debug at runtime, that is the one you will see.

Assume, on the other hand, you use method overloading to provide the flexibility of providing either a logical or a numeric (1 or 0) parameter. Then, one of the method simply calls the other one, and the main work is done in a single method.

Sure, I also prefer a single method; but I think method overloading should not be a major nuisance.

Then, there is the case where you have functions that do identical work for different type of parameters. For example, abs(). You would need one version for integer, one for long, one for double, etc. ... And for efficiency, you want to keep essentially identical code, in separate methods.

It is my understanding that in .NET, and in the newest incarnation of Java, the concept of "code templates" is used precisely for this purpose. Internally, you would have one version of the method for each case; but the developer sees only a single version. I have no idea how the debugging would work in this case.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform