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

Re: dynamic vs. static typing



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.

> 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.

	Ken

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Sexy types in action: http://www.eecs.harvard.edu/~ccshan/cs252/usage.pdf
new journal Physical Biology: http://sansom.biop.ox.ac.uk/images/physbio.gif
What if All Chemists Went on Strike? (science fiction):
http://www.iupac.org/publications/ci/2003/2506/iw3_letters.html

Attachment: signature.asc
Description: Digital signature