Hacker News new | ask | show | jobs
by the_af 400 days ago
It's a legacy problem in the sense your system is a badly designed mess of functions that only return boolean. You could encode additional semantics in the types. Of course if you don't, the type system will be unhelpful.

This is a modeling problem at this point. Types can make your model better by encoding more things. It's often not easy or feasible to refactor the mess, so sometimes you're stuck with it.

1 comments

Can you explain concretely how adding types would make a bunch of boolean-valued functions and some tests better? What types would you introduce to my example?
You need dependent types for this to fly. But the main argument is that there’s an infinite number of ways your Boolean functions can go wrong if they mistakenly taken a wrong input type or return a non Boolean. Types reduce this universe of runtime errors by 99 percent. It’s still infinite though but you have a lot less possible errors.
That's my point, the type errors being reduced isn't that interesting, I usually find and fix those extremely quickly. What I don't find but am most interested in is the actual logic. So I must write tests. And when I write tests, I get the type errors covered too. So why should I spend my precious time modeling inside a type system when the ROI is minuscule and the cost is I have to litter my codebase with types. Just write the tests.
You can write the test in the type system with dependent types. It's the same thing. But your language needs to support this. Typescript supports it. The static analyzer in your ide or during compilation will now run the test. You get a model and a test for free.