Jay Parlar wrote: > Well guess what: The *only* code you'll have to change is inside the > function returning the object, none of the callers would have to change. > That's completely different from C++, where you'll have to change not > only the return type and the function, but you'll also have to change > every single calling function to be aware of this new db object. And not > just how the callers store the returned object, but also how they use > that object. That's a LOT of work, for really no gain.
Part of the problem is that both standard Python and C++ lacks the concept of defining an interface. Whether we deal with C++ or Python, we need to understand what we can do with a return value, or what kind of interface a parameter we send to a function needs to provide. In Python, this is implicit. The compiler doesn't force us to do the right thing, and a programmer can make a mess by doing it wrong. In C++ it's the opposite. By demanding a particular type, we restrain ourself to using a set of values which is much smaller than the logic calls for, or we can throw away all type checks by e.g. casting to void pointers. I don't have enough experience with languages that provide interfaces, such as Java, to understand how useful they are, but it's my impression that they are too cumbersome to use fully. As far as I understand, most Java APIs use types more than interfaces for parameters and return values. (I browsed the Java API docs at java.sun.com, and as far as I see, it seems the APIs always require parameters of distinct classes or types, and return values of particular types or classes.) I know that there have been attempts to provide interfaces in Python, and it seems Zope Interfaces are getting a decent following, but I don't think anyting like that will ever take the place that type declarations of all function and class declarations have in e.g. C++. It's too difficult to make interfaces so convenient and flexible that they could be used generally in Python without taking away a lot of power. -- http://mail.python.org/mailman/listinfo/python-list