Hacker News new | ask | show | jobs
by magicalhippo 1740 days ago
In Delphi I try to use sets over boolean parameters. Then I can easily add new possible set members instead of introducing more parameters.

    type FuncParam = (fpDoThis, fpDoThat);
    type FuncParams = set of FuncParam;

    function MyFunc(arg1, arg2: integer; params: FuncParams): integer;
    begin
      result := 0;
      if (fpDoThis in params) then
         result := DoThis(arg1);
      ...
    end;

    // supply directly
    MyFunc(123, 42, [doThis, doThat]);

    // or indirectly
    params := [];
    if (condition) then
      Include(params, doThat);

    MyFunc(111, 222, params);
    

Delphi ain't the most elegant language out there, but the set functionality is pretty nice.
2 comments

Delphi has overload and default parameters. The problem in article is non existent for a good Delphi programmer.
> Delphi ain't the most elegant language out there

Citation, as they say, needed. :-)

Any anonymous function will do :P

Not knocking it, after all it's my daily driver. You can do quite a lot with it these days and it can be quite productive.