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

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.

  • My tweets

    Tue, 12:31: RT @ AngryBlackLady: Why is it the libertarian assholes ALWAY bring up the crack/cocaine sentence disparity w/ me? Like drugs are…

  • My tweets

    Mon, 20:01: @ Floridaline Sort of. I think tomorrow he’s going to meet his first Italian American who doesn’t support Mussolini. :) Mon,…

  • My tweets

    Sun, 15:39: My Kindle seems to like regular web-embedded fonts, though not the Google Web Fonts API. Mon, 08:54: reworked;…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded