DEV Community

Discussion on: Only three numbers matter: zero, one, and more-than-one.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Indeed, we even have specialized collections in our code that store 0, 1 or 2+ items. Optimized to avoid overhead in the common 0 and 1 case.

Of course, in testing it's been shown that 3 is a common number. If you test something twice in a loop it may not produce an error, only the 3rd time something different happens.

This has been my experience in coding interfaces and abstractions as well. The first two may not capture the situation fully, but by the third one the API is looking fairly stable. Somehow that third item always changes things.