Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

If i create this method

public void foo()

And then i create an overloaded version like this

public void foo( string bar )

Do we say that the second functions overloads the first, or are both methods equally "overloaded".

This would imply ( i think ) , that there is a base type function, that is being overloaded, by another function. ( somewhat like inheritance, but not really )

Assuming that one method can "overload an other", would also imply terms like "overloader" and "overloadie", if that is a word at all. But that doesn't feel right at all, especially since you can have several overloads.

I got to this question when i wanted to write down the process of creating an overloaded method and i wanted the most correct way of writing it down.

Examples:

  • I am overloading foo
  • I am overloading foo with foo( string bar )
  • I am creating an overloaded method
  • I am making foo overloaded

So yeah, this kind of got my thinking, i am not sure what to make of it. There are hundreds, if not thousand, descriptions of function overloading online, but at a first glance i couldn't find any addressing this.

share|improve this question

3 Answers 3

up vote 21 down vote accepted

When talking about overloads, the name of the function is overloaded, not the function itself. The functions overloading the name are "overloads" and overload the name, but not each other. In your example, "public void foo()" and "public void foo( string bar )" both overload the name "foo". Therefore, you cannot speak in terms of overloader and overloadee of one of the functions, because they have no direct relationship.

In your examples, you can say that you are overloading "foo" (the name) with "foo( string bar )" (the function), but you cannot say that you create an overloaded method, because methods are never overloaded. You can say that you create an overloading method. To formulate "making foo overloaded" is just a worse way of saying "overload foo".

share|improve this answer
    
But would then not every function overload its name, even if no other function has the same one? –  leftaroundabout Apr 19 '12 at 19:17
    
I agree with this as the answer to the general question above. But if one called one of the functions from the other, then I perceive a sense in which one overloaded the other. –  Joshua Drake Apr 19 '12 at 21:00
1  
@leftaroundabout: "Overloading" implies that you're doing more "loading" than usual, so the term is only used when you have more than one function with the same name. –  kindall Apr 19 '12 at 21:36
    
Agreed with @kindall; the word "overload" in a software development context means "to assign more than one meaning to"; overloading columns in a DB (meaning depends on other fields), overloading parameters (meaning depends on other parameters), etc. One method doesn't overload any other, but if there is more than one method with one name, the name is "overloaded". –  Michael Edenfield Apr 20 '12 at 0:22

I would simply say foo is overloaded. There is certainly no master/slave or parent/child relationship going on here.

share|improve this answer
1  
Agree -- it's the name of the method or operator that's overloaded, not the method itself. Not to be confused with overriding, where the implementation of a given method in a subclass supplants the implementation in the parent class. –  Caleb Apr 19 '12 at 16:52
1  
I agree with this too, but i think thiton does a better job at explaining it. Thank you for your answer ! –  Willem D'haeseleer Apr 19 '12 at 16:56

I think that a good way to express this is to focus on the final result, not on changes made to the class over time. Thus, instead of saying "I overloaded 'foo' with 'foo(other parameters)'," you say "foo is an overloaded function, with 'foo()' and 'foo(other parameters).'"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.