4 ms·
> As a mostly C++ programmer making sure that I get compiler errors as often as possible by encoding most preconditions in the type system .. When selecting a
by labawi 6y ago
> As a mostly C++ programmer making sure that I get compiler errors as often as possible by encoding most preconditions in the type system ..
When selecting a language for a recent project, that needed to run correctly, without extensive debugging that would be hard to simulate (too many states and interactions), I had a couple of important criteria:
0) checked static typing
1) ADTs (that are reasonably easy to use, read and write)
2) pattern matching (no way I'll get all the if/else right)
3) reasonably easy to write static const (pure functional) code
4) memory-safe
I've considered rust, but settled on haskell, as I needed it fast and I know haskell. While technically any Turing-complete language would work, I don't think C++ would be a fit for must-work code, even disregarding (4).
While I haven't used C++ in a while, it seems to me, encoding the constraints would be 3-10x as much code, or even more, with many checks/cracks left, and a lot of readability gone.
Clean and correct functional haskell code took a bit longer to write than say happy-path imperative python, but after fixing 2 or so bugs that manifested on pretty much the first (partial) use (like incorrect "<" vs. ">" and a bad constant), it has been running happily ever since. I didn't even bother simulating a full system configuration before a real-world customer acceptance test, because components worked on 1-2 inputs I tried, setting up a system would take a couple of hours and I couldn't think of reasonable failure scenarios. I haven't experienced similar correctness in other languages.