News for hackers. Stuff that matters.
Re:Flags Are a Code Smell (2014) by amelius on Saturday May 21, 2022 @08:15PM (#31463566)
Yeah, it's either flags or duplicating code. Both are smelly, so pick your poison.
Re:Flags Are a Code Smell (2014) by jackblemming on Sunday May 22, 2022 @01:26AM (#31465117)
No? 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

Re:Flags Are a Code Smell (2014) by amelius on Sunday May 22, 2022 @05:39AM (#31466415)
Alas, 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.
Re:Flags Are a Code Smell (2014) by gentleman11 on Sunday May 22, 2022 @12:57PM (#31470270)
That 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
Re:Flags Are a Code Smell (2014) by jef_leppard on Sunday May 22, 2022 @01:32AM (#31465149)
Yep. 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.