Hacker News new | ask | show | jobs
by lexi-lambda 2051 days ago
> What's a better alternative though?

I’m not really suggesting there needs to be an alternative. Using newtypes to achieve safety via encapsulation is fine, good even, and I say as such at several points in the article.[1] The point is twofold:

1. A lot of uses of newtypes in the wild are “safety theater” and provide zero actual safety benefit.

2. The uses of newtypes that do add safety provide it in a weaker sense than correct-by-construction data modeling.

The point is not that newtypes are always useless. In fact they are often by far the most practical tool for the job. The blog post just advocates being conscious and considerate of the limitations of the techniques.

[1]: https://news.ycombinator.com/item?id=24964494