[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: in defense of types
I admit that type declarations will help turn up bugs that
might not have been found till later, if at all.
However, type declarations are only one of many assertions
you might choose to make in the source of a program to
catch bugs. Why not let it be up to the programmer to
decide which such assertions to make, and when? What's
special about variables' types that makes it a good idea to
make assertions about them mandatory, at compile time?
I know why mandatory type declarations first appeared
in programming languages: because values were represented
directly as chunks of memory (i.e. unboxed) and it would,
with the wimpy hardware available at the time, have seemed
shockingly wasteful to represent all variables as pointers.
This tradition had a long time to harden, because pointers
were still considered a luxury till the 1980s.
Occam's razor suggests that *that's* what's special about
this particular kind of assertion. It is merely a
tradition. Static typing has some benefits (catching bugs),
and when something is both traditional and has some actual
benefits, it is hard to discard. But static typing has costs
too, of the very worst sort: it makes programs longer and
more rigid, and thus makes the language a bad tool for
exploratory programming.
It's like the way the military does things. Making everyone
fill out forms to do anything certainly prevents
mistakes. But it also inhibits innovation terribly.
I'm not saying the military is mistaken here. There are
places where restrictions are good-- particularly when you
don't trust individual people not to screw up. So requiring
type declarations or other assertions (e.g. all the
boilerplate that seems to be required in Java) could be
a good idea in some big company where the programmers
are guys who walked in off the street after Learning Java
in 21 Days. But at the other end of the continuum, there
is also a role for languages that put as few constraints
on the programmer as possible.
--pg