- DelphiTools - https://www.delphitools.info -

What do you think of function overloads?

In Delphi, you can overload functions, but doing so requires using the overload directive explicitly.

The following code declares two functions with the same name, one that will be invoked if you pass an integer, another that will be invoked you pass a string:

function MyFunc(a : Integer) : String; overload;
function MyFunc(s : String) : String; overload;

In many other languages, the overload directive is implicit, you don’t have to type it and you can always overload.

On the other hand, it means that as long as your parameters differ, you can end up overloading an existing function without noticing, which can lead to confusion.

What do you think of function overloads?

  • They're confusing, they shouldn't be allowed. (3%, 11 Votes)
  • They can be useful, but should be explicit via a directive. (72%, 246 Votes)
  • They're very useful, no directive should be required. (25%, 85 Votes)

Total Voters: 342

Loading ... Loading ...