I think it’s ok to realise that some conditions are too complex, costly or cumbersome to move into types, and use assertions instead. If anything, it makes for very clear documentation for people who have to maintain the code.
-
-
-
Replying to @benkio89
So what do you do when your constraint is a pain - positive int, for example, which means that you need to write unsafe code whenever you add two positive ints because the compiler can't prove that the result will be positive? I prefer having the unsafe code in a single place.
3 replies 0 retweets 0 likes -
Replying to @NicolasRinaudo @benkio89
I approve of this general principle. A cast (e.g. Int#asInstanceOf[PosInt]) is you—the programmer—claiming you know better than the compiler. If you can minimize the number of times you do this without compromising the certainty of your reasoning, then it's (ahem) a net positive.
1 reply 0 retweets 1 like
A related idea is when you're safely handling failure cases, it makes sense to channel these into few places, rather than distributing the error-handling throughout your code. A larger part of your codebase will be total, and it will be easier to read.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
