News for hackers. Stuff that matters.
Re:My Thoughts on “Bad Code” by hk1337 on Friday March 17, 2023 @10:45AM (#35197787)
We have a tendency sometimes to prematurely abstract pieces of code.

I am okay with copy-pasting code but after the second or third copy-paste, you should probably at least consider asking, “Should I abstract this into its own function?”

Re:My Thoughts on “Bad Code” by WorldMaker on Friday March 17, 2023 @05:24PM (#35203111)
One way this is formulated is the "Rule of 3 for Abstractions":

One copy of something is YAGNI. You aren't going to need it (an abstraction).

Two copies of something are coincidence. It's fine to copy and paste and leave it that way.

Three copies of something are finally a pattern. At least three copies are when you start to really see what sort of abstraction that you need to handle the pattern.