3 ms·
Eh 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
by jef_leppard 4y ago
Eh 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)
}
}