From: <bc...@wo...> - 2001-01-12 09:31:07
|
[Ben Hutchison] >This posting is about language design. I want to pose the question: Is >there a way to tweak Jython so that the "self" reference that refers the >containing instance can be implicitly, like the implicit "this" pointer >of java or C++? Regardless of whether there are a technical way to do this, I must establish that Jython will *not* innovate on the core python language design. On this I place all my trust on Guido. >Im a java developer who feels very comfortable with the OO paradigm, yet >am attracted to Jython because the it makes somethings that are too hard >in java much easier: map(), list slicing, keyword arguments. But the >need to explictly specify self.X and self.Y and pass it to instance >methods disturbs me. I clearly recall that it disturbed me too when I discovered JPython about three years ago. Coming from the normal java & C++ background, it just seems so unnecessary. It took me a full week <wink> to accept this as a natural part of the python language, and it haven't bothered me since. I think you will get to accept it too. >It makes Python's OO features look something of an >afterthought, grafted on to a imperative/functional language. Using this >frequent, default construct, seems like uneccesary hard work. Based on the history lectures Tim Peters have been teaching on c.l.py, I think that OO was a fundamental part of python from the very beginning. >eg: > class MyClass: > def __init__(self, name): > def doIt(self): >becomes: > class MyClass: > def __init__(name): > def doIt(): > >which seems far more natural (and easier) from a java point of view. > >Why cant "self" be prepended to all functions and vars by default, when >inside a class definition? If "self." was prepended to all vars, how could the python compiler tell the difference between a local vrbl and a instance vrbl class Foo: def bar(): v = 1 # is "v" a local or an instance vrbl? Today an instance vrbl is clearly visibly to both programmers and the compiler because of the explicit self.v syntax. >If this issue has already been thrashed out on a forum, please refer me >an archive link. I'm certain this issue have been discussed on c.l.py (I say that I'm certain, because every topic have already been discussed on c.l.py several times over the last 10 years). I don't have a link because, I don't track c.l.py closely. The Jython language spec will stay closely tied to the Python language. It is only on the integration of java classes and java objects that jython will invent new semantics. If Jython should change on the topic of explicit self, it will only be because CPython have changed. regards, finn |