two-tier class thoughts (part 2)
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <002601c4593f$6ec73fe0$da01a8c0@walker> |
I've given more thought to how classes should be implemented in Prothon. This time I'd like to propose some ground rules.
I want to use the class keyword for familiarity and have everything related to that class grouped under that keyword. No matter how many objects and how much syntax it takes to implement a class I'd like it to be grouped in one construct in one place. I don't want the class definition spread across multiple places in the code.
The following is only meant to show the grouping, not be a syntax proposal:
class Klass:
object KlassFactory:
blah blah blah
object KLassProto:
blah blah blah
or maybe something like:
class Klass(ancestor):
instance:
blah blah blah
class:
blah blah blah
I also want the class object itself to be one self-contained object. In other words if you have a class object, a factory object, and an adaptor, then you'd end up with Klass, Klass.factory_, and Klass.adaptor_.
Note that if you accept this proposal, the differences between Paul's, Serge's, and my proposals start to dissapear. As a matter of fact, it seems to me that Paul's factory object could always be auto-generated and would not need to be part of the syntax. Plese correct me if I'm wrong.
I have a third guideline. I want this example to work by graceful degeneration of whatever syntax we come up with:
class Square(Rectangle):
def init_(wid):
self.wid = wid
def str_():
print '<Square:'+self.wid+'>'
I don't see where this should be a big challenge. For example, in the second syntax above you just make the default section of class be "instance". This makes sense since a class is supposed to be a blueprint for the instance, not the class.
Comments? Votes?