3 ms·
I hadn't heard of the Rule of Three, but it parallels my own heuristic. The first time, I write the code to do the thing I need. The second time I encounter a s
by jfengel 7y ago
I hadn't heard of the Rule of Three, but it parallels my own heuristic. The first time, I write the code to do the thing I need. The second time I encounter a similar thing, if I can't find the right abstraction to unify them, I go ahead and repeat myself, writing a second, similar round of code that does what it needs.
If I encounter it a third time, then I've got enough data points to make a good guess about what the right abstraction will be. If I've done a good job so far, it shouldn't be too difficult to refactor it. (Strong, static typing helps.)
This is, of course, just a heuristic, and it's not all-or-nothing. I'll take my best guess about what the right abstraction is going to be, and I'll try to get it right the first time. The second round also presents opportunities to take two points and extrapolate a line.
It all comes down to experience: not just with the system, but with the domain that the system is about, and with the way systems change and grow. No one rule of thumb ever encapsulates all that.
- AnimalMuppet 7y agoI use the same approach to automate processes. The first time, I do it manually. The second time, I still do it manually, but I think "Hey, I did this once before. This is looking like something I maybe ought to automate." The third time I automate it. By then, I understand it well enough to have good odds on being able to do the automation successfully.
- amelius 7y agoHow often did you automate something yet? If it's more than three times, you ought to automate the automation!
- keithnoizu 7y agoskynet.gif
- AnimalMuppet 7y agoYou're kidding (I think), but I missed a piece. Part of the point of doing it the second time is to make sure that I really understand what I'm doing and how I'm doing it. Without that, I can't write the automation on the third time. Well, if the task is "automating things" (for very general values of "things"), I don't understand how I'm doing well enough to automate that.
- dasil003 7y agoWhy? It's already automated, the question about whether to automate a class of things could be answered by adding a dimension to this: https://xkcd.com/1205/ https://xkcd.com/1205/