4 ms·
Just because you do it frequently doesn’t necessarily make it good. Your approach increases the function’s cyclomatic complexity. The struct requires the caller
by tacotacotaco 4y ago
Just because you do it frequently doesn’t necessarily make it good. Your approach increases the function’s cyclomatic complexity. The struct requires the caller to dictate the function’s inner logic instead of the function logic being driven by application data. Maybe your solution is a good fit in your production code. I can’t say. Maybe there is a different approach to solve your boilerplate concerns. There will be exceptions but generally I don’t agree with the example as provided.
- klyrs 4y ago> Just because you do it frequently doesn’t necessarily make it good. Fair point, but in my ~20 years of experience, I've learned what does and doesn't make for more work down the road. To wit: if something is always bad, I don't keep doing it. But I didn't just say I do it frequently, I said that I do it frequently for big-ish functions when it's only toggling a line or so. That context is important: I am not arguing that this is always a good thing. I'm saying that there's a time & place for it, and with a language like C++, it's a zero-cost abstraction. > ...I don’t agree with the example as provided. Yeah, neither do I. As I pointed out elsewhere, its a contrived example which can be more simply factored out into two function calls. So unless it's being used tens to hundreds of times, nothing is gained there.