3 ms·
I think I went into the same trap as well quite often. And then I exactly ended up with the problems as they are described, i.e. adding further special cases be
by albertzeyer 3y ago
I think I went into the same trap as well quite often. And then I exactly ended up with the problems as they are described, i.e. adding further special cases becomes really complicated and convoluted in my abstraction.
But I really find this difficult. How to decide what abstraction is ok and which is not? Since I did this mistake a few times, I now sometimes tend to try to think a lot about this, which slows me down a lot, and in the end, I still not really sure whether I made the right decisions.
Any suggestions how to decide such things?
See also John Carmack about code duplication: http://number-none.com/blow/blog/programming/2014/09/26/carmack-on-inlined-code.html http://number-none.com/blow/blog/programming/2014/09/26/carm...
I have read much advice on this topic, but still, I think I often struggle to make the right abstractions.
- paweladamczuk 3y agoI think it's so specific to a given codebase that it's hard to give advice that generalizes well. I have the same feelings as you here, I often feel a little lost trying to decide how much duplication is appropriate in a given case. I try to not overthink it in the difficult cases. There are many other places in code where it's more obvious, because you can see the history of how people worked with the code, what was the frequency of changes and edge cases added to it etc. Often it's also just about the readability of the code, I tend to go by the "how confusing it will be for the next person if I defuplicate this code in a smart way" metric.