3 ms·
Pascal has it too. I always found it quite natural to specify the range I want with the data type and not as precondition in the function. Another big advantage
by weinzierl 7y ago
Pascal has it too. I always found it quite natural to specify the range I want with the data type and not as precondition in the function. Another big advantage is that you can avoid a good deal of potential off-by-one errors, if you define your data types appropriately. For example the following definition in Pascal would be much less error prone than the corresponding definition in C[1]:
var
weekday: 0 ... 6;
monthday: 1 ... 31;
For a quarter of a century I wonder why no one seems to miss that feature. I really hope we will get them in C one day. Even more so I hope that the proposals for refinement types in Rust[2] will one day be resolved and become implemented.
[1] https://www.cplusplus.com/reference/ctime/tm/ https://www.cplusplus.com/reference/ctime/tm/
[2] https://github.com/rust-lang/rfcs/issues/671 https://github.com/rust-lang/rfcs/issues/671