Ian Bicking: the old part of his blog

Re: Why Python Unicode Sucks

Dynamic typing only works when you adhere to certain important principles -- one of those is that if objects are not interchangeable they should use differently-named methods.

If you really meant that, you'd have to abandon polymorphism for good and all. If (classes of) objects were truly interchangeable, the only possible difference would be in performance. So since sets and bags are not interchangeable, we'd have to use addToSet and addToBag methods instead of just add methods in each one.

You've got a hold of a serious point here, but you are holding the stick at the wrong end. To begin with, a better title (if less blogospherically trendy) would be "Why Python 'str' Sucks".4

Comment on Why Python Unicode Sucks
by John Cowan

Comments:

Abandoning polymorphism seems extreme. I read the originating comment as 'if objects are not interchangeable, they should use differently-named methods for places where that difference lies".

Both sets and bags support addition, existence testing, held object counts, and the like. 'add' is thus a perfectly fine method for both, and usage via duck typing makes sense - if an add method exists, then I can use it. Where you run into problems is when there is a behavioral difference - a set can return only a single item, thus the idea of a 'countOfItem' method in a Set is silly. In a bag, it is not. Thus, the key behavioral difference shows up in a way visible to duck typing, and it is visible for those clients that care.

The problem with strings is that there are two different classes that have virtually identical method signatures, so client code interacting with these classes has a hard time knowing wherther it will get something that behaves well with Unicode.

Scott

# Scott Ellsworth

The point was intended to include only dynamically typed languages (i.e. Ruby with its duck typing). In other words, the risk of naming incompatible methods with the same name only exists if the language will assume these similarly named methods denote polymorphic behavior. In contrast, with a statically typed language like Java, polymorphism will only be assumed if the classes are explicitly placed in a class hierarchy using inheritance. (Unless, of course that is bypassed using reflection, as with Java Beans).

# Keith Bennett

# body piercing