SV: Python Productivity over C++

Huaiyu Zhu hzhu at knowledgetrack.com
Wed Jun 14 16:53:57 EDT 2000


On Wed, 14 Jun 2000 20:09:37 +0200, Thomas Thiele <thiele at muc.das-werk.de>
wrote: 
>Aahz Maruch wrote:
>
>> Suppose you needed a file object to connect to some chunk of memory.  In
>> other languages, you would need to inherit from the Python file object
>> in order to ensure that random functions that expect file objects would
>> still work.  In Python, that's completely unnecessary.  It's probably a
>> lot simpler to create your own class, complete with open(), close(),
>> read(), and write() methods -- and because you've maintained *interface*
>> consistency, you can use your new class *ANYWHERE* a file object would
>> go.
>> --
>
>But there is no mechanism to ensure that the behaviour of your memfileobjectsis
>like a fileobject. For instance if you don't note that you forgot to write the
>write()-function.
>In a worst case scenario it works for many months until a user calls a function
>in which
>the write() -function is needed.
>

Here's one example why not forcing complete interface compliance may be a
good thing:

In the matrix for python project I've just added a bunch of statistical
distribution classes, each of them supposedly provide cdf, pdf, rand and
other methods.  Each method is a simple wrapper around some library function
but to do them all takes time.  So I only added the easier ones and the ones
I may need shortly.  I can already use them now, and the project goes along.
If each one had to confirm to a final complete interface specification the
whole thing might have been put off for a long time. If a user wants
something more he can easily add the missing pieces or ask me to do so.  You
may say that when a project is finished everything should be there and
working, but my list of everything has an infinite length.

Now it could be nice if there were a tool that flags the not-implemented
parts and put them into a TODO list.  For example it could give todo=['B.b',
'B.c'] from the following example:

class A:
  def a(): raise NotImplementedError
  def b(): raise NotImplementedError
  def c(): raise NotImplementedError

class B(A):
  def a(): pass

I'm not sure if this is feasible in general, but even a half-hearted job
would still be helpful.

Huaiyu

PS. The stats classes are only in the latest CVS version as I added them
last night.

-- 
Huaiyu Zhu                       hzhu at users.sourceforge.net
Matrix for Python Project        http://MatPy.sourceforge.net 



More information about the Python-list mailing list