What is the command to determine an object's type?

Laura Creighton lac at strakt.com
Wed Feb 6 13:12:20 EST 2002


I think that everybody should read Design Patterns because it is the
single best way I know of to improve your code.  (And your life.
Life is more fun when your code is more maintainable.)  However,
for a Python programmer, there is one problem with the original
text:  Design Patterns.

It is written for C++.

This means that while a lot of the text is about the really good stuff,
the patterns, at least half of it could be entitled 'my struggles with
the C++ type system'.  And since you came to this discussion because
you wanted to test the type of something, which is something that
Mark McEahern and I both think that you probably ought not to be doing
at all, you may get the wrong lesson from reading that book now.  

There is another book, The Design Patterns Smalltalk Companion,
(Alpert Brown Woolf), which is meant to be read at the same time
as the Design Patterns.  Smalltalk does not have declared types
either.  As a result, patterns in Python end up looking a lot 
more like Patterns in Smalltalk.  I find the Design Patterns
Smalltalk Companion to be a lot easier to understand than its
parent, as well.  But when you get a look at the Smalltalk syntax,
you will see one of the reasons why Smalltalk has not taken over
the world by now, mores the pity.

What Mark McEahrn and I are plugging is called signature based
polymorphism.  (Well, I should only speak for myself.  I am.)

This has been discussed on the python list recently.

See:  (isinstance considered harmful)
http://groups.google.com/groups?q=group:comp.lang.python+insubject:isinstance+insubject:considered&hl=en&as_qdr=m3&selm=83n0z44t11.fsf%40panacea.canonical.org&rnum=1

which became (typetesting, adaptation, typeclasses, ... (was Re: isinstance() considered harmful) )

http://groups.google.com/groups?hl=en&threadm=a2ohsf%24mjj%241%40serv1.iunet.it&rnum=3&prev=/groups%3Fq%3Dsignature%2Bbased%2Bpolymorphism%2B-ruby%2Bgroup:comp.lang.python%26hl%3Den%26as_qdr%3Dm3%26selm%3Da2ohsf%2524mjj%25241%2540serv1.iunet.it%26rnum%3D3

Laura Creighton




More information about the Python-list mailing list