Barry SCHWARTZ (Barijo ŜVARC) (chemoelectric) wrote,
Barry SCHWARTZ (Barijo ŜVARC)
chemoelectric

Why mandatory variable declaration is stupid

Typically languages with static type checking require you to declare your variables with their types.

First, this is stupid because it is a throwback to early compilers, which depended on the programmer to tell it ‘I am going to need this chunk of memory, which I am naming such. I need this much space for it, arranged in such and such a way.’ Vestiges of assembly language.

Second, what is the compiler then going to do? It’s going to analyze the context in which the variable is used, and check that the declared type is compatible. The declaration is superfluous for this task; you can simply check that all the uses of that variable are compatible with some type; then the type checking has been passed, no declaration required.

Explicit type declaration still has uses, but they are at the fringes, or for instance to provide human-readable, limited-information interfaces for multiple compilation units. Such interfaces aren't really needed, however, because the compiler itself can generate type-safe interfaces.
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 3 comments