Consider you are a compiler. Now suppose you are a person who doesn't care about your fellow programmers who are writing code and using you to get them compiled. Like for example:
Someone is assigning an integer(4 bytes) into a char(1 byte) variable.
If you are not careful, that assignment will take away the adjacent 3 bytes away. Poof!.
This is type-unsafe. That is the compiler or YOU are not taking care of such validations before compiling them.
Again this can be at two levels:
- Static typing - one which is done at compilation time.
- Dynamic typing - one which is done at run-time. This is when you get all those run-time exceptions.
Be type-Safe!
Top comments (5)
I never said you would write 0 unit tests. You would write no tests for types.
Kotlin has nullability built into the language, so I don't have to write a test what happens when the variable I am passing is null.
I also don't have to do defensive programming and check if the variable is null.
Well, you could have the compiler verify the types for you or write unit tests instead..
How else do you make sure the function expecting a User doesn't get a Monkey instead?
What does dynamic typing have to do with "Divide by zero"? Zero is a value, not a type. Statically typed languages won't prevent division by zero.
True, unless you have refinement typing!
True ... that was a mistake. Thank you for pointing it out.