News for hackers. Stuff that matters.
Re:“What if it changes?” by konschubert on Monday May 23, 2022 @04:28AM (#31476544)
> If something is used once, ignore any abstractions. If it's used twice, just copy it, it's better. If it's used 3 or more times, look at writing an abstraction...

As others have said, this is a good rule of thumb in many cases because finding good abstractions is hard and so we often achieve code re-use through bad abstractions.

But really good abstractions add clarity to the code.

And thus, a good abstraction may be worth using when there is only two, or even just once instance of something.

If an abstraction causes a loss of clarity, developers should try to think if they can structure it better.

EDIT: This comment below talks about good example of how a good abstraction adds clarity, while a bad abstraction takes it away: https://news.ycombinator.com/item?id=31476408

There are no comments on this comment yet.