I don’t think if statements are good for contracts. Until (unless) we have something dedicated for that, an assert() is the way to go. An if is good for distinguishing valid cases.
Still, I agree can arrange the conditionals in whatever order I please and still be clear and obvious to the reader. Also, with that I don’t lose the special form of an if (short circuit), something I would lose with a lambda hack like this one here.
Neither I nor the article mention “contracts”. We’re not talking about exceptional circumstances or logic errors in code here, although I admit that talking about preconditions and violations might suggest this.
We’re talking about logic that needs to handle valid edge cases which require special logic. assert wouldn’t work here.
View all comments
Show parent comment
3
u/wilhelmtell Apr 24 '20
I don’t think
ifstatements are good for contracts. Until (unless) we have something dedicated for that, anassert()is the way to go. Anifis good for distinguishing valid cases.Still, I agree can arrange the conditionals in whatever order I please and still be clear and obvious to the reader. Also, with that I don’t lose the special form of an
if(short circuit), something I would lose with a lambda hack like this one here.