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

Re: dynamic vs. static typing

Ken Shan wrote:
> On 2003-11-24T23:02:07+0100, Pascal Costanza wrote:
>>>As Anton van Straaten explained beautifully, all the objects in this
>>>case respond to some message like "turn off if you can", or "can you
>>>turn off?".
>>...but that's a pretty bad idea in general. When you say this...
>>if (object.turnOffSupported()) {
>>  object.turnOff();
>>...there is a chance that the object is replaced in another thread 
>>between the check and the actual call.
> That wasn't what I had in mind.  A more reasonable design of
> turnOffSupported(), within a relatively impoverished type system like
> Java's, would return a (possibly null) reference to an interface that
> supports turnOff().
>     if (TurnOffable object2 = object.turnOffable()) {
> 	object2.turnOff();
> 	// object.turnOff() should be a type error
>     }
> After all, turnOffable should return a witness for its claim that the
> object can be turned off, and that witness is an interface that supports
> turnOff.

...but you still have a two-step protocol. Even worse, you can't change 
the object into one that cannot be turned off anymore as long as you 
have the object2 reference.

>>BTW, this is what a DT language gives you for free. ;)
> What are you saying here that a dynamically typed language gives me for
> free?  If by "give you for free" you simply mean "allow you to program
> without additional restrictions", then that is a rather vacuous claim,
> since the Turing machine gives you quite a bit for free according to
> that definition.

a) Note the smiley.

b) The dynamic language gives you a "one-step protocol" for free that 
simultaneously checks the presence of a feature and invokes it. In a 
static language, it takes more effort to ensure that your code behaves 
reasonably in between.

c) Turing equivalence is boring. Only the stuff that goes beyond Turing 
equivalence is really interesting in language design.


Pascal Costanza               University of Bonn
mailto:costanza@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  Römerstr. 164, D-53117 Bonn (Germany)