class proposal 3
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
I figure that if I throw enough crap against the wall something will
eventually stick. So here is today's. :-)
I agree with Paul and others that prototypes aren't really broken and we
don't need classes as a language feature. Today's proposal will add classes
as a contract feature that can be imported as a module.
I am not going to try to solve the call_ and str_ problem in the class
module. These will be solved seperately in the language for both prototypes
and classes.
I want classes to be able to have these properties when one does "import
Class":
1) The class is a blueprint only. It cannot function as an instance. This
also allows normal method calls to be made which solves problem 1 in my
thread 'what is "class behavior"'.
2) The class is immutable. Once defined it cannot have class or instance
methods added, removed, or redefined. Class variables cannot be added or
removed but their values may change.
3) Instances may have only data attributes. No instance methods are
allowed.
4) Instances only inherit from their one class. All inheritance is from
their class which inherits only from other classes.
5) If possible, class and instances will have seperate namespaces.
Because the class feature is imported, it's syntax is limited. Here is my
current idea for the "class statement" (The Class.Factory idea is from
Michael Lucius):
object Klass(Class, Parent1, Parent2):
def init_(x):
self.x = x
class.count += 1
print 'Klass instance number {class.count}'.fmt()
def str_():
print '<kls:{self.x}>'.fmt()
class = Class.Factory(Klass) # this is mandatory
with class: # this is optional
count = 0
def str_():
print '<Klass:{count}>'.fmt{}
Of course the "with class" could be replaced by:
class.count = 0
def class.str_():
print '<Klass:{count}>'.fmt{}
Class.Factory(Klass) defines call_(), str_() and whatever else the class
object needs and returns the class object.
I will need to add some general language features. For example. I need to
add a feature to the object command that at the end of the object body a
method is called on the object called "endObject_". This will allow cleanup
code to run after the object body is finished. In the case of the Class
prototype this "endObject_" method would just set the immutable bit,
allowing the object to be modified only during construction before being
write-protected.
Another language feature needed is a very powerful equivalent to
getattribute from Python. This will allow the class object to provide the
limitations for the items in the list above.
You get the point. I will only add features that are general purpose
features that are approved by everyone for the overall good of Prothon, not
hooks just for classes.
Comments?