3 ms·
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
by magicalhippo 5y 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.
- unnouinceput 5y agoDelphi has overload and default parameters. The problem in article is non existent for a good Delphi programmer.
- CRConrad 5y ago> Delphi ain't the most elegant language out there Citation, as they say, needed. :-)
- magicalhippo 5y agoAny 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.