2 ms·
e.g. say you're writing some code that does something like this: account = queryDatabase(email) updatedUser = update(account) ping(account) queryDatabase re
by ArchieMaclean 6y ago
e.g. say you're writing some code that does something like this:
account = queryDatabase(email)
updatedUser = update(account)
ping(account)
queryDatabase returns a dictionary.
Later on, someone decides that a single username can have multiple accounts, so someone changes queryDatabase to return a list of dictionaries instead of a single dictionary. Now the above code is broken, since update expects a single dictionary.
Of course, you could grep through the whole codebase to try and find all the problems, but it would be easier and less prone to human error to rely on the type system to fail, especially if the change was something less contrived, and if changes like this were happening all the time.
The effect of this could be limited by other means (e.g. naming the function better) but type systems are just another way of adding robustness to a program.