The perfect Python

laotseu bdesth at nospam.free.fr
Thu Aug 29 06:00:02 CEST 2002


Jean-François Ménard wrote:
[snip]

> The Perfect Python (c):
> 
> What is missing ?  Well, I'm not a language designer, but I can say what *I*
> miss.
> 
>     - Interfaces.  Behavior checking is not enough.
They do exist... as a convention !
There has been recently a <long> thread about compile-time time checking.

>     - Private and Public scopes.  Explicitly.  No more __name_mangling
Well, as for interfaces, it's more a matter of self discipline (IMHO)

>     - Design by contract. Pre and Post conditions.  Could save hours of
> debugging.
Can't this be managed by code ? I think I saw some people using this in 
C++, where it's not a builtin of the language.


>     - Block comments.  """ """ should be for documentation.
>     - Class variables.
You've got them !

class myClass:
     my_class_var = "I'm a class variable"

     def __init__(self):
         my_instance_var = "I'm an instance variable"



>     - A cleaner Property declaration.  No separate _variable. Saw too many
> newbie posts about that.
>     - No more self in functions declarations.  In OOP, this *can* be
> implicit. (I know, this is controversial stuff)
It is ! In C++, I always use the 'this' pointer, and *hate* people not 
doing so cause this forces me to check wether it's a member function or 
a 'normal' function.

>     - Standard GUI library.  AnyGui seems to be the solution, but
> development seems to have stalled recently...
> 
> 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:
> ********************
> from package1.package2 import module1, module2
> 
> public interface MyInterface implements (OtherInterface1, OtherInterface2):
>     """ Comments """
>     private PrivateClassVariable
>     public property MyProperty
>     public MyFunction(param1, param2)
> 
> public class MyClass(Class1, Class2) implements MyInterface, Interface2:
>     """ Comments """
> 
>     # Instance Variable
>     private InstanceVariable = "Default"
> 
>     # Class Variable - Public by default
>     static PublicClassVariable = "Default"
> 
>     # Class Variable - Private
>     static private PrivateClassVariable = "Default"
> 
>     public initialize(param1, param2="", param3=None):
>         """ Comments """
>         # OtherInstanceVariable is Public by default
>         self.OtherInstanceVariable = "rien"
> 
>         # OtherInstanceVariable2 - Private
>         private self.OtherInstanceVariable = "rien"
> 
>     private MyFunction(MyParameter1, MyParameter1):
>         """ Comments """
>         return "Result"
> 
>     /*
>         Block comment
> 
>         function Foo():
>             pass
>     */
> 
>     public property MyProperty:
>         """ Comments """
>         get():
>             """ Comments """
>             return self.MyProperty
>         set(newValue):
>             """ Comments """
>             self.MyProperty = newValue
> 
>     private testInterface(otherObject):
>         """ Interface checking  """
>         # Check for interface implementation
>         if otherObject implements MyInterface:
>             return true
> 
>         # Check for multiple interface implementation
>         if otherObject implements (OtherInterface1 or OtherInterface2):
>             return true
> 
>         # Check for class inheritance
>         if otherObject implements MyInterface:
>             return true
> 
>         return false
> 
>     private testInheritence(otherObject):
>         """ Inheritence checking """
>         # Check for class inheritance
>         if otherObject implements MyInterface:
>             return true
> 
>     private propertyCall():
>         """ Uniform call """
>         return self.MyProperty
> 
>     private propertySet(newValue):
>         """ Uniform call """
>         self.MyProperty = "new value"
> 
>     public functionWithAssertion(Param1):
>         """ Design by Contract """
>         require:
>             """ Precondition """
>             Param1 < 1000000
>         do:
>             """ Function body """
>             pass
>         ensure:
>             """ Poscondition """
>             Param1 < 1000000
> 
> ********************

Except for the last part (pre and post), it looks like a weird mix of 
Java, Python, and VB. I'm not sure I really like it.

But I do agree on one thing : some 'compile' time checking *could* help 
for large
or complex projects, assuming this mechanism can be turned on & off.

my 2 cents...

laotseu




More information about the Python-list mailing list