3 ms·
Programming languages range in their formality. At the low end you have things like Python or Ruby, where you can write a loop over a type that can't be iterat
by danpalmer 10y ago
Programming languages range in their formality.
At the low end you have things like Python or Ruby, where you can write a loop over a type that can't be iterated, and it will crash at that line of code.
In the middle you have languages like Java, C#, at the mid-high end, even Haskell and F#. In these languages they enforce type safety at varying levels throughout the code, by first inferring the types at each point throughout the code, and then seeing whether they are consistent. You would not be able to loop over a non-iterable object here.
At the really high end you get into the realm of languages like Idris, Agda, and Ivory, and "formal verification" techniques. At this level you can not just write a loop, but you can write a loop that it is possible to prove terminates regardless of the input to the loop. This is done by setting constraints, and proving those constraints all the way through the code - the compiler will infer a lot of this, but it is still more work.
This is a very simplified view of it, but essentially the more formal you get in the specification, the less chance that the program can do something unintentional, crash, or be hacked. The vast majority of the code written today is not that formally specified.