3 ms·
Duplication is for when future changes are independent. "This client wants their reports customized" maybe. Flags are for when future changes affect both optio
by tbrownaw 4y ago
Duplication is for when future changes are independent. "This client wants their reports customized" maybe.
Flags are for when future changes affect both options. "On top of the usual functionality, we can also optionally handle this other related thing" or so. Or --dry-run handling.
- jef_leppard 4y agoEh maybe. Theres no hard and fast rules in this business for sure but when I'm dealing with pure business logic, if I am passing flags in that make the function behave in more than one way, I'll try my damndest to refactor until there is one and only one thing that that function does. If I _had_ to pass in a flag, then I'd make a top level function that mostly did flow control and called into functions that had straight line logic paths. Something like this (using enums instead of booleans): function doTheThing({typeOfThing, ...rest}) { if (typeOfThing === Thing.FOO) { doThingWithFoo(rest) } if (typeOfThing === Thing.BAR) { doThingWithBar(rest) } }