|
|
|
|
|
by disnet
5401 days ago
|
|
Well, CoffeeScript/JavaScript doesn't have a static type system. And to add one would be...hard. But we would still like to express and enforce some invariants about our code. And we'd like to do it in a more elegant way than constantly writing "if(argument === ...) then ... else ..." Contracts also allow us to check invariants that might not result in a run-time exception but could lead to the code just being subtly wrong. |
|
Indeed it would be. That said, CoffeeScript is a compiler of sorts.
> And we'd like to do it in a more elegant way than constantly writing "if(argument === ...) then ... else ..."
This doesn't really seem to solve that problem. It just throws consistent errors if the types don't match. Your code would likely throw its own error if you didn't check the type manually. In my experience, native js errors are as easy or easier to track down that throwing errors yourself.
> Contracts also allow us to check invariants that might not result in a run-time exception but could lead to the code just being subtly wrong.
Ah, ok. That makes more sense. They're like python decorators, only single purpose.