News for hackers. Stuff that matters.
Re:Parse, Don't Validate (2019) by munificent on Tuesday February 10, 2026 @01:38PM (#46964693)
I wouldn't call it a good use of static typing, but I'd call it a good use of object-oriented programming.

This is one of the really key ideas behind OOP that tends to get overlooked. A constructor's job is to produce a semantically valid instance of a class. You do the validation during construction so that the rest of the codebase can safely assume that if it can get its hands on a Foo, it's a valid Foo.

There are no comments on this comment yet.