[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Small time coding [Was: Re: About Visual Basic [Was: Industry versus academia]]



Christopher Barber wrote:
> The Curl language has optional type annotations.  Variables with
> undeclared types are given the compile-time type of 'any', which
> is the supertype of all other types.  Type checking involving anys
> is deferred until runtime while that with other types is done at
> compile time.

That's excellent.  It's interesting how few languages do this.  Aside from
any intrinsic difficulty to doing it, a big reason, I'm sure, is that if
it's not designed in from the beginning, it would be much more difficult to
add later.

> > I think these optional type annotations are one example of a
> > sort of pragmatism that's often lacking in language designs.
> > It's a pretty low-cost feature to include in a language.
>
> Not if you want to get compile-time type checking or any
> performance benefit from your type annotations.

Sure.  I was talking about forgoing those benefits, in the interests of
expediently getting some type annotations into purely dynamic languages
which don't currently have them.  There are benefits other than performance
and compile-time checking - I think pre-.NET VB provides some evidence of
that.

As Michael Vanier noted, Perl has plans to do this.  The Ruby extension
mentioned by Robert Feldt implements parameter type checking as assertions,
which is close to what I was talking about, although it can't handle types
for ordinary variables, since there's no central point to implement the
checks.  BTW, the FAQ on that page,
http://www.nwlink.com/~rpav/StrongTyping.html, provides a nice motivation of
some reasons to want strong typing, even if not statically checked.

Having optional type annotations in a dynamic language, even without static
checking, would allow the language to evolve in a bazaar-style way towards
more sophisticated use of types, without sacrificing any dynamism that
developers don't choose to sacrifice.  Lint-like checkers would probably
arise that took advantage of type information, even before the compilers
did.  The same goes for other tools.

Anton