[lazarus] classesh.inc change required

Dmitry Osinovsky ode at prbank.ru
Tue Dec 21 11:33:43 EST 1999


21.12.99 11:27:36 michael wrote:
>Open Brackets: (
>
>Although there is a problem with overloading and default parameters
>in Delphi (see the 'known issues' text that comes with Delphi 5)
>
>Given the declaration:
>
>Procedure TMyObject.Proc(Param1 : longint; Param2 : Longint default
0);overload;
>Procedure TMyObject.Proc(Param1 : longint); overload;
>
>And the call:
>
>MyObj.Proc(2);
>
>Which one must be called ? Both are legal targets so to speak !

Compiler should report an error.

>The idea of default parameters is as stupid as Visual Basic itself!

No, no, no. At first, default parameters, as I know, came from C++, not
from VB (though implementation in Delphi is the best :).

And second, default parameters are VERY convenient. Suppose you need to
add one more parameter to function so that all existing calls to this
function remain compileable.
Compare this

1.
interface
procedure MyFunction(OneParameter: Integer; OneMoreParameter: Boolean =
False);
...
implementation
procedure MyFunction(OneParameter: Integer; OneMoreParameter: Boolean =
False);
begin
...
end;

and this:

2.
interface
procedure MyFunction(OneParameter: Integer); overload;
procedure MyFunction(OneParameter: Integer; OneMoreParameter: Boolean);
overload;
...
implementation
procedure MyFunction(OneParameter: Integer);
begin
  MyFunction(OneParameter, False);
end;
procedure MyFunction(OneParameter: Integer; OneMoreParameter: Boolean);
begin
  ...
end;

The first is quicker to write and easier to read - you can immediately
tell what is the default value for OneMoreParameter without looking
through implementation.

>
>So this would be a reason for me not implement either overloading
either
>default parameters. (the latter actually)

I see no problem supporting both this and that - as I mentioned,
compiler should report an error in conflict situations.

>
>) Close Brackets







More information about the Lazarus mailing list