Re:Ask HN: Concepts that clicked only years after you first ...
by sanderjd on Sunday January 01, 2023 @03:39PM
(#34210607)
Yes, static analysis of types can eliminate a big class of unit tests (basically just checking pre- and post- conditions on types), which is a big part of why it's great. But most unit tests should be for logic. But that's why they aren't very useful for "glue" methods which just thread things through different dependencies - they shouldn't have much interesting logic.
Re:Ask HN: Concepts that clicked only years after you first ...
by codethief on Sunday January 01, 2023 @09:26PM
(#34213530)
> Of course it's not necessarily a full replacement
I'd actually say: Not in the slightest. A type system just rules out illegal input values[0] but it won't ensure that your business logic is correct.
And even that[0] is not entirely correct because, most of the time, a type system just rules out some illegal values but not all of them, because it cannot represent all possible constraints. Gary Bernhardt discussed this whole type checking vs. tests debate at length here: https://www.destroyallsoftware.com/talks/ideology
Of course it's not necessarily a full replacement, but it's definitely better and more time efficient than bad tests.