[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Lightness vs. Largeness
> Sure, it's good for the type declarations to be optional, particularly
> when you're writing a very small program. If I were in a team writing
> a large program in a declarations-optional language, though, I'd think
> carefully about team coding standards regarding where it's OK to omit
> type declarations.
Yes, this is why we added compiler directives to the Curl language that
allow you to force a compilation unit to declare all variables.
> (In another discussion, I learned an interesting thing about the Curl
> language. In Java, there is one type for every class, but in Curl
> there are two: a type that allows any object of that class or null,
> and a type that allows any object of that class but not null. That
> sounds useful. Of course there are important tradeoffs about how
> expressive you make your type system.)
Yes. We discovered that we were getting a significant number of null
dereferencing errors in our own code and decided to do something about it
while we still had the chance to change the language. It seems inherently
wrong that an object declared to be a 'Foo' could actually be a null, even
though null is not a valid 'Foo'. So we added support for #Foo, which is an
abstract type that can contain either a Foo or null. This only works for
class types, for other types the '#' is ignored (e.g. #int == int).
Although we are pleased with the result, I have to say that it was very
difficult to retrofit this to our code, so I doubt that it would be feasible
to make the same change to existing languages such as Java that suffer from
the same problem.
> Do you think it's true that, for any language, if you want type
> declarations to be optional, there must be some type that is the union
> of all types?
I think so. In Curl, this is the abstract 'any' type.
> (There is no such type in Java because of the
> "primitive" types; otherwise you could imagine omitted type
> declarations "defaulting" to "Object", although perhaps the grammar
> would need some adjusting...)
Well Curl has primitive types, just like Java, but still has such a type.
The compiler representation of 'any' is large enough to hold primitive and
other small values directly without boxing, and boxes larger value types.