RE: Insight: Prothon is an Acquisition-orientedlanguage

"Mark Hahn" <[email protected]> Fri, 30 Jul 2004 10:04:03 -0700
Newsgroups gmane.comp.lang.prothon.user
Message-ID <000401c47657$37241380$0b01a8c0@mark>
Mark Hahn wrote:

>Paul Prescod wrote:
>
>> Here is a Python implementation of the style inheritance thing:
>> 
>> inherited_properties = ["a", "b", "c"]
>> 
>> class Node:
>>  vals = None
>> 
>>  def __init__(self, parent = None):
>>      # have to get around setattr below
>>      self.__dict__["vals"] = {}
>>      self.__dict__["parent"] = parent
>> 
>>  def __getattr__(self, name):
>>      if name in inherited_properties:
>>          if name in self.vals:
>>              return self.vals[name]
>>          else:
>>              return getattr(self.parent,name)
>>      else:
>>          return self.vals[name]
>> 
>> 
>>  def __setattr__(self, name, val):
>>      self.vals[name] = val
>
>Does this look significantly simpler to you?  It just switches 
>between using the built-in inheritance and a local store. To 
>use this you just mix-in this prototype with the data prototypes.
>
>object Node:
>   def init_():  
>       local_vals = {}
>   def get_(attr):
>       if attr in inherited_properties:
>           return getAttrNoProp(attr)
>       else
>           return local_vals[attr]
>   def set_(attr, value):
>       if attr in inherited_properties:
>           setAttrNoProp(attr, value)
>       else
>           local_vals[attr] = value
I noticed a couple of things after sending this.

1) I switched to Outlook recently and now both of our code samples are
unreadable in outlook express. :-)  You'd think different companies had
written the two products.  I fixed it in the code above for outlook express
readers.  

2) At first I thought I had forgotten the "self" in "return
getAttrNoProp(attr)".  Then I realized this code would work as written,
since Prothon defaults to the current self when it can't find any other rule
to use.
  
This made me realize that Prothon doesn't require the self prefix in all
situations.  Is this a good thing or a bad thing?  It is obviously
intuitive, at least to me, because I wrote the code expecting this behavior
last night.  I used to write Java code though.

Greg has said in the past that this situation should have no self at all and
should throw an exception.  He may have changed his mind though, I don't
remember.  A lot of water has passed under this bridge.