On Wed, Oct 17, 2012 at 10:45 AM, Joe Niederberger <email@example.com > wrote:
> What's all that got to do with the price of coffee Paul? > Coffee.price? > > Does coffee in fact have one price or maybe more than one? > It depends on the context. But we don't really need to talk > about bananas if we don't care to. > > Joe N >
One of the exercises I teach (daily) involves coconut instances, with different weights. South American, Middle Eastern, and American are our three coconut types. Some students use subclasses of Coconut and that's a good solution. Weight may be stored at the class level.
def add_coconut(self, incoming): if not isinstance(incoming, Coconut): raise AttributeError("can't add a not-coconut") etc.
That won't come across perfectly unless in plaintext view (a Math Forum option) but you get the idea: unless the caller of the add_coconut method is actually passing a coconut object, warning lights go on. It's like TSA at the airport. If you have a firearm, you really need to be noticed.
Even subclasses of Coconut, like SouthAmerican, make it through. Their weights are pre-set. But if someone tries to send a different type object to inventory, the whistle-blowers blow.
"Sensitivity to type" is not stupid. In STEM math, we want students to see the C > R > Q > Z > N hierarchy. If they don't, they're too illiterate for STEM. DC has lower standards. Our students tend to be smarter than the average American, but because of curriculum, not genes. We could assist the USA, but we aren't required by law to do so (It's "opt in" not "opt out").