Questions about app design - OOP with python classes

Paul Rubin http
Sat Mar 3 18:32:18 EST 2007


Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> writes:
> Unless there is a type system that can automatically deal with the
> semantic difference between (say) screen coordinates and window
> coordinates, or between height and width, or safe and unsafe strings, the
> coder still has to deal with it themselves.
> 
> And even if there is such a type system, Python isn't it.

Python uses runtime typing, so you'd define classes for screen and
window coordinates, and have them do appropriate conversions or raise
exceptions when you do mixed operations.  The compiler wouldn't notice
this happening at compile time, but that's just like the rest of
Python.

> The point I'm trying to get across isn't that Apps Hungarian is the best
> imaginable solution to the problem of dealing with semantically different
> kinds of data. But it is an easy solution that works quite well (not
> perfectly) and (unlike relying on Haskell's type system) it can be
> applied to Python quite easily.

I think the notion above fits ok into Python's dynamic typing scheme.
Yeah, you may get runtime exceptions at unexpected times due to type
conflicts that you overlooked in testing, but again, the Pythonic
prescription for these and other errors seems to be "write more tests".

Maybe we can concoct a cross between Python and Haskell, and call it
"Paskell" after the philosopher Blaise ;-).



More information about the Python-list mailing list