Search code examples
language-agnosticprogramming-languagesstrong-typing

Doesn't the ability to cast defeat the purpose of typed variables?


So, I'm working under the assumption that we have typed languages because we make a lot of mistakes... so typing is one way to have the compiler do a lot of checks for us and help us out a bit (please let me know if it is my assumptions that's incorrect).

However, if we introduce casting to a typed language, don't we re-introduce most the problems we had when were not able to type variables?

I'm also aware that my assumption isn't the only reason why we type variables. Please share some of the other reasons why we have typed languages.


Solution

  • The bottom line is that strong typing lets the compiler check things for you and casting lets you override the strong typing when necessary.