Re: two-tier class thoughts (part 2)
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
> 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? Do you mean for "Class" to be an alias for "Object"? If not what are the differences? Also it seems that this proposal meshes with the idea of protocols/adaptors suggested in another thread. I.E. cls = x.class() returns a reference to object x that has had its interface changed to the class interface. This seems to me to be a general solution that can be used to allow the programmer to do a lot more than simulate classes.
reply
(text/html, 4.6 KB)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1400" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>I've given more thought to how classes should be implemented in Prothon. This time I'd like to propose some ground rules.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>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.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>The following is only meant to show the grouping, not be a syntax proposal:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> class Klass:</FONT></DIV> <DIV><FONT face=Arial size=2> object KlassFactory:</FONT></DIV> <DIV><FONT face=Arial size=2> blah blah blah</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> object KLassProto:</FONT></DIV> <DIV><FONT face=Arial size=2> blah blah blah</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>or maybe something like:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> class Klass(ancestor):</FONT></DIV> <DIV><FONT face=Arial size=2> instance:</FONT></DIV> <DIV><FONT face=Arial size=2> blah blah blah</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> class:</FONT></DIV> <DIV><FONT face=Arial size=2> blah blah blah</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>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_.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>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.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>I have a third guideline. I want this example to work by graceful degeneration of whatever syntax we come up with:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> class Square(Rectangle):</FONT></DIV> <DIV><FONT face=Arial size=2> def init_(wid):</FONT></DIV> <DIV><FONT face=Arial size=2> self.wid = wid</FONT></DIV> <DIV><FONT face=Arial size=2> def str_():</FONT></DIV> <DIV><FONT face=Arial size=2> print '<Square:'+self.wid+'>'</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>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.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Comments? Votes?</FONT></DIV></BODY></HTML>