Hacker News new | ask | show | jobs
by mamcx 2437 days ago
Contracts are interesting but I think to make it usefull 1) are ON on release! and 2) Become part of the docs.

One example:

     fun date(y:i32, m:i32, d:i32)
     {... code ...}
This scream for more context (and better param names!). With contracts:

     fun date(y:i32, m:i32, d:i32)
     assert
         y in 0..9999
         m in 1..12
         d in 1..31
     {... code ...}
But I need to see it in the docs, in the tooltips, etc. Now are useful!
2 comments

Good old February 31.
Nothing like a bug behind a safety feature :)
That’s … not a bug.

A buggy assertion would be one that fires when the input is correct.

Assertions aren’t formal verifiers or replacements for a test suite.

And year 0.
I think that is why making the contract visible in the docs/intellisense or similar is valuable: You will understand more about the expectations of the code. Even if are incomplete or partial...
> (and better param names!)

And/or better param (sub-)types.