4 ms·
Yeah, it's either flags or duplicating code. Both are smelly, so pick your poison.
by amelius 5y ago
Yeah, it's either flags or duplicating code. Both are smelly, so pick your poison.
- jackblemming 5y agoNo? Both separate functions can call a 3rd shared function if they want. You can also restructure the code with dependency injection. There's plenty of options that don't require duplication
- jef_leppard 5y agoYep. You said it better than I could. There are a lot better ways to do control flow than passing in a flag. Inversion of control being another great example.
- amelius 5y agoAlas, in reality the code controlled by the flag is often mixed with other code and separating the two is often difficult to do right, e.g. requiring to pass a lot of data hence and forth.
- gentleman11 5y agoThat indirection can end up a bit fractal. Sometimes the duplication is less bad than the readability reduction. You have to trust your intuition at those times