(no title)
plainOldText | 4 months ago
type
Age = range[0..200]
let ageWorks = 200.Age
let ageFails = 201.Age
Then at compile time: $ nim c main.nim
Error: 201 can't be converted to Age
[1] https://nim-lang.org/docs/tut1.html#advanced-types-subranges
wucke13|4 months ago
Weirdly, when going through the higher assurance levels in aviation, defensive programming becomes more costly, because it complicates the satisfaction of assurance objectives. SQLite (whiches test suite reaches MC/DC coverage which is the most rigorous coverage criterion asked in aviation) has a nice paragraph on the friction between MC/DC and defensive programming:
https://www.sqlite.org/testing.html#tension_between_fuzz_tes...
nine_k|4 months ago
jordanb|4 months ago
Ada's compile time verification is very good. With SPARK it's even better.
Runtime constraints are removable via Pragma so there's no tradeoff at all with having it in the language. One Pragma turns them into static analysis annotations that have no runtime consequences.
vlovich123|4 months ago
naasking|4 months ago
Modifying a compiler to emit a message at every point that a runtime check is auto-inserted should be pretty simple. If this was really that much of an issue it would have been addressed by now.
zeroq|4 months ago
dwattttt|4 months ago
If it fails at run time, it could be the reason you get paged at 1am because everything's broken.
lock1|4 months ago
It's a good example for the "Parse, don't validate" article (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...). Instead of creating a function that accepts `int` and returns `int` or throws an exception, create a new type that enforces "`int` less than equal 200"
Something like this is possible to simulate with Java's classes, but it's certainly not ergonomic and very much unconventional. This is beneficial if you're trying to create a lot of compile-time guarantees, reducing the risk of doing something like `hmmm = works + 1;`.These kind of compile-time type voodoo requires a different mindset compared to cargo-cult Java OOP. Whether something like this is ergonomic or performance-friendly depends on the language's support itself.
baq|4 months ago
jb1991|4 months ago
arzig|4 months ago
plainOldText|4 months ago
mr_00ff00|4 months ago
I assume it’s a runtime error or does the compiler force you to handle this?
ajdude|4 months ago
wombatpm|4 months ago
Jtsummers|4 months ago
https://learn.adacore.com/courses/intro-to-ada/chapters/cont...