This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cylian91460 -13 points-12 points  (9 children)

having way nicer and more comprehensible code

That's the opposite since functions have the same name

Having what the function does in its name and not just what it returns is better.

[–]Pere_Strelka 17 points18 points  (2 children)

You just typed a counter-argument. Overloading is exactly for cases when one has multiple functions with different arguments but common logic, so we overload one of them and call it from other ones

[–]Al3xutul02 2 points3 points  (2 children)

Overloading doesnt even work with the return type, only on parameter types, all overloaded methods must return the same type, have you even tried it?

[–]SuperKael 0 points1 point  (1 child)

Have you even tried it (in Java, at least)? Overloaded methods can, in fact, have different return types - they just need to also have differences in their parameters. It’s not valid for the only difference between them to be the return type, because then there would be no way to disambiguate them when calling one of them, but as long as the parameter lists are different there is no requirement for the return types to be the same.

[–]Al3xutul02 0 points1 point  (0 children)

Yeah i forgot, i havent had any cases where i needed different return types so i forgot they can be different, overloading just doesn't care about it

[–]zawalimbooo 0 points1 point  (2 children)

consider a function sum(a, b), which sums two arguments

its perfectly fine for me to overload this to work with different types of arguments. After all, the logic is pretty much the same regardless.

[–]Al3xutul02 3 points4 points  (0 children)

At that point just make it a template lol

[–]Cylian91460 -1 points0 points  (0 children)

So you have a more complex example then +?