Syntax modification idea: (classmethods, properties locking...)
andrew-pythonlist at puzzling.org
Fri Jan 17 03:37:31 CET 2003
On Thu, Jan 16, 2003 at 05:06:23PM -0800, Dennis Lee Bieber wrote:
> Arne Koewing fed this fish to the penguins on Thursday 16 January 2003
> 01:03 pm:
> > why not extending the def statement?
> > class bar(object):
> > def foo(class,arg1) is classmethod:
> > pass
> > def bar(arg1) is staticmethod:
> > pass
> I think I'd prefer just modifying the def keyword...
> defclass ...
> defstatic ...
> with plain def retaining the effect it has at present.
The problem is that classmethod and staticmethod are so special that they
require new keywords -- you can easily implement them in python (using
descriptors). More importantly, you could easily implement other wrappers,
which ideally you could use just as easily.
Thus I quite like the idea of "def foo(...) is classmethod" (or perhaps
"def foo(...) as classmethod"?). If I implement a "synchronised" wrapper for
an otherwise thread-unsafe method (which would be quite straightforward),
I'd quite like to be able to write "def foo(...) is synchronised".
> "is" already has meaning in the language when doing compares -- I'd
> rather not overload it as a noise verb "def ... [is] classmethod:"
> wouldn't change if one left out the "is".
Yeah, I appreciate your concern, but I don't think there's much risk of
confusing a function declaration with a comparison. And the advantage of it
reading so clearly is worth it "def foo(...) is classmethod" can be read
out-loud as "define foo (with parameters ...), which is a classmethod".
To my eyes it looks natural... my only concern is that it's *too* natural --
it's almost magical ;)
More information about the Python-list