3 ms·
You model every state that your program is expected to handle. How else will the computer know what to do? If the state is modeled in numeric terms then you ca
by 0xFACEFEED 7y ago
You model every state that your program is expected to handle. How else will the computer know what to do?
If the state is modeled in numeric terms then you can represent the intermediate state as a range of integers. You need to do this whether or not your program is typed.
Without types you're allowing the program to fall into a state that it doesn't know how to handle. This works because the program doesn't try to handle these intermediate invalid states. What happens when it eventually does try to handle that state? That's when bugs happen.
Static type systems are a brute force way to eliminate a certain class of bug. A dynamic language appears simpler because it doesn't even attempt to capture those errors. It's like saying your payment validation is "simpler" because it doesn't do CCV checks.