Ben Finney schrieb:
Joe Strout <[EMAIL PROTECTED]> writes:
"x quacks like a basestring if it implements all the public methods
of basestring, and can be used in pretty much any context that a
basestring can."

That is not duck typing. Rather than checking what foo does in
response to prodding that, by your admission, is only designed to find
out what type it is, duck typing instead advocates that you should use
foo *as though it is known to be* the type of object you want. If it
is not suitable, then appropriate exceptions will be raised and either
caught by some code that knows how to handle them, or crash the
program.

Warning, rant ;)

This whole theory breaks down quickly if you're writing library code. How do your unittests help the user of your library to use it correctly? How do you communicate incorrect usage of your interfaces to the user?

If you are able to specify the type of the arguments as part of the interface the compiler/interpreter will help you. Types are used to describe behaviour (if thats a good thing, I don't know). While python has strong types, there could be used better (instead it gets worse, see the suddently-not-sortable-list-type diskussion and the endless repetition of the greatest of all after-the-fact theories ever "duck typing".

cheers
 Paul

BTW: Back to Java? No, not really.


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to