Re: Static/Dynamic typing, lessons from the field
- From: Pascal Costanza <pc@xxxxxxxxx>
- Date: Tue, 31 Jan 2006 09:50:38 +0100
André Thieme wrote:
Hmm, don't know what to think about this article. The author says: "They artifically limit your expressiveness."
And his justification is an example:
"In Java, for instance, the type system doesn't let you do operator overloading, multiple inheritance, mix-ins, reference parameters, or first-class functions. Any time the most natural design involves these things, you're stuck trying to mutate it into a design that fits Java's type system."
But what does static typing have to do with Javas non-existing support for the points he mentioned (operator overloading, mult. inh., etc.)? The Java designers did intentionally *not* putting them into the language. From Suns point of view that might be a good thing cause Java is now pretty much the most popular programming language. The author got that point plain wrong.
It's actually true that whenever you try to design new language features for Java, you always have to match them against Java's type system if you want a remote chance that it will ever get accepted. And this can lead to horrible situations. Consider the interactions between AspectJ 5 and generic types in JDK 5.
In Common Lisp, for example, it is actually relatively straightforward to create an incompatible new "world" in which your type system behaves very differently from the CL's original type system. Consider ACL2 and Qi as examples. Something like that wouldn't be acceptable in Java. (That's a social restriction, not a strict technical one.)
The relationship to expressivity is unclear here, but it is actually an acknowledged fact that static type systems have to limit the expressivity of the base language in the sense that they have to reject programs that wouldn't produce type errors at runtime. This is because there is always a grey area for which a static type checker cannot decide whether a program will produce a type error or not, and a static type system is only accepted (again socially by the people who are into static type systems) when such programs are effectively rejected.
As a comparison, CMUCL's and SBCL's compiler use a type inferencing, which means that they effectively have a static type system. But instead of rejecting programs for which they cannot prove type safety, they will just issue warnings. This is typically not considered "strong" enough.
Later he says: "Dynamic languages give you more expressive power and more design options;" but does not explain this point. It sounds like an opinion and therefor is not much more worth than the opinion "Static languages give you more expressive power and more design options;". And I personally would like to know what a static language or a dynamic language is. Probably he wanted to say "statically typed language". Making this kind of mistake tells me that he is probably not an expert on this issue, and so I should not take his conclusions too serious.
It's relatively straightforward to produce example that show how a dynamically typed language can be more expressive than a statically typed one. For example, in Common Lisp you can change class definitions at runtime. Especially when you remove slots from a class, this results in a program that a static type checker wouldn't have accepted in the general case. Yet, Common Lisp provides enough rope to ensure that such a program still works (ultimately by error handlers that can take advantage of useful restarts).
There are also cases where static type systems are more expressive than dynamically typed languages, but in that case the gained expressivity is not at the base language level, but rather at the type system level. I have only seen one example so far, though, in which code can be dispatched on the type of the expected return value - which is interesting because the dispatch can depend on some future event, something that is, as far as I can tell, impossible to do in a dynamically typed language.
Pascal
-- My website: http://p-cos.net Closer to MOP & ContextL: http://common-lisp.net/project/closer/ .
- References:
- Static/Dynamic typing, lessons from the field
- From: pp
- Re: Static/Dynamic typing, lessons from the field
- From: André Thieme
- Static/Dynamic typing, lessons from the field
- Prev by Date: Re: Interesting developments since "Beating the averages"?
- Next by Date: Re: Interesting developments since "Beating the averages"?
- Previous by thread: Re: Static/Dynamic typing, lessons from the field
- Next by thread: Re: Static/Dynamic typing, lessons from the field
- Index(es):
Relevant Pages
|