The perfect Python

Dan Bishop danb_83 at yahoo.com
Wed Aug 28 17:35:43 EDT 2002


Jean-François Ménard wrote:
...
> I would like to share my impressions and my comments on Python.  At the end,
> I will propose what would be for me the *perfect* Python interpreter.
...
> I tried to write an example of what Perfect Python(c) could look like.  It's
> not valid code (duh!),  and it does'nt try to do anything unless give a
> sample syntax:
...
> public interface MyInterface implements (OtherInterface1, OtherInterface2):

There already is a language that has a syntax almost exactly like that. 
  You can download it at http://java.sun.com/j2se/1.4/download.html .

But if you want to add this to Python, it ought to be made less verbose 
so it's consistent with the rest of the language.  How could we do this?

We could start by eliminating the "implements" keyword.  C# gets along 
fine without it.  And even Java doesn't use it for anonymous classes. 
Just use the old inheritance syntax:

public interface MyInterface(OtherInterface1, OtherInterface2):

Also, to ensure compatibility with old code, everything must be public 
by default.  That means the "public" keyword isn't essential, which 
leaves us with

interface MyInterface(OtherInterface1, OtherInterface2):

And furthermore, in a language with multiple inheritance, there's no 
need to make a distinction between interfaces and classes.  So let's 
replace "interface" with "class".

class MyInterface(OtherInterface1, OtherInterface2):

This last syntax has the further advantage of requiring less effort to 
implement, because it's already supported :-)

>     /*
>         Block comment
> 
>         function Foo():
>             pass
>     */

What's wrong with #?

I suppose one-line comments make it more difficult to comment out code, 
but why not just use "if 0:"?

>     public property MyProperty:
>         """ Comments """
>         get():
>             """ Comments """
>             return self.MyProperty
>         set(newValue):
>             """ Comments """
>             self.MyProperty = newValue

How are we supposed to distinguish the property MyProperty from the 
variable MyProperty?

>     private testInheritence(otherObject):
>         """ Inheritence checking """
>         # Check for class inheritance
>         if otherObject implements MyInterface:
>             return true

What's wrong with isinstance(otherObject, MyInterface) ?

>     public functionWithAssertion(Param1):
>         """ Design by Contract """
>         require:
>             """ Precondition """
>             Param1 < 1000000
>         do:
>             """ Function body """
>             pass
>         ensure:
>             """ Poscondition """
>             Param1 < 1000000

What's wrong with the assert statement?




More information about the Python-list mailing list