PEP318

A

ajsiegel

But it *isn't* part of the core language. I think that's the whole
point. @decorator does something that no other statement in Python does,
so why should it *look* like a normal statement? Or are you suggesting
that a keyword should be used instead of a symbol?
I must not understand your argument.

I'm not making an argument. I'm speculating.

The design goals of PEP318 include:

"""
make it obvious what is happening; at the very least it should be obvious that new users can safely ignore it when writing their own code
"""

I'm supportive (I guess) of that design goal, but I guess I am speculating that
the actual decision as to the syntax might have been different had this not
have been among the design goals. And that a lot of the discussion regarding the syntax seems to not take consideration of this particular design goal and how it might have impacted Gudio's decision.

Art
 
J

Josef Dalcolmo

Hello,

I just would like to add my vote against using '@' in the Python language.

I use Leo (the intelligent folding editor written in Python), which makes heavy use of @ and using the same character in Python might create some incompatibilities.

I don't think @ looks good in ANY context and I don't want Python to start looking as ugly as some other languages. (Though I like how in Oberon - which is ugly otherwise because of its use of uppercase keywords - a variable is declared public by marking it with a '*', like in var*).

On many non-English keyboards it isn't exactly simple to type an '@', but since decorators aren't going to be used everywhere, I guess this is a weak point.

- Josef
 
P

Peter Otten

Josef said:
On many non-English keyboards it isn't exactly simple to type an '@', but
since decorators aren't going to be used everywhere, I guess this is a
weak point.

Let me add that temporarily switching to an American keyboard layout (*) for
programming helps with all of the following chars: @\[]{}|`.

Peter


(*) clearly an obsession of mine
 
V

Ville Vainio

Peter> Let me add that temporarily switching to an American
Peter> keyboard layout (*) for programming helps with all of the
Peter> following chars: @\[]{}|`.

US layout is indeed the only sensible way to program in languages
designed for US layouts, which pretty much includes most mainstream
languages.

If you are not man enough to learn Dvorak, that is ;-). I recently
switched over, and did some additional keymap tweaking like switching
'8'/'(' and ')'\'9' so that I won't need to press shift for
parens. Numbers like 8 and 9 are useless for coding - everything
beyond 0 and 1 implies a flawed design.
 
S

Sion Arrowsmith

Josef said:
On many non-English keyboards it isn't exactly simple to type an '@'
[ ... ]

As someone who's just started using a Mac for the first time(*),
I'd like to add that it's not always plain-sailing on an English
keyboard. (Yes, I know in terms of keystrokes it's no more
difficult than on a PC, but it's not *marked*. And I have a great
aversion to remapping keyboards so that they generate characters
other than those on the keycaps.)

(* ... for about fifteen years, when all I wanted it for was
word processing)
 
A

Arthur

Hello,

I just would like to add my vote against using '@' in the Python language.

I must say that after days of waffling, and I think an honest effort
to accept where things were going, I woke this morning hating
@decorator.

The existing syntax for this kind of transformation is, in fact,
exactly what one would expect:

foo=staticmathed(foo).

That is the universal langauge for transformations. And when we try
to explain to anybody what it is that @decorator means, we go back to
the pseudo code that is in fact the existing syntax.

I guess I am mystified what it is that is perceived to have been
gained ... by moving magic outside the function block to the top of a
function in lieu of expressive code outside the function block at the
bottom of the function. Something is created, and then transofrmed -
in the language of transformation that transcends the implementation
detail of what programming language is doing the work.

Art
 
R

Roy Smith

Sion Arrowsmith said:
As someone who's just started using a Mac for the first time(*),
I'd like to add that it's not always plain-sailing on an English
keyboard.

What's wrong with Mac keyboards? I've used a number of Mac keyboards
over the past 15 or so years, and have found the variety of layouts to
be no better or worse (or more or less standardized) than any other
keyboards in general. I'm currently using a 12" PowerBook and other
than finding the control key to be uncomfortably close to the space bar,
I find it perfectly reasonable for programming and emacs-ing.
And I have a great
aversion to remapping keyboards so that they generate characters
other than those on the keycaps.)

Yes, that's evil. I was just in the UK a couple of weeks ago and was
using a semi-UK keyboard. As far as I could tell, the keycaps were
labeled with the UK layout, but the codes they generated were US style.
I touch-type, so as long as I ignored what was printed on the keycaps
and just typed normally, everything was fine. But it's amazingly
difficult to ignore the printed keycaps.
 
A

Antoon Pardon

Op 2004-08-12 said:
What's wrong with Mac keyboards? I've used a number of Mac keyboards
over the past 15 or so years, and have found the variety of layouts to
be no better or worse (or more or less standardized) than any other
keyboards in general. I'm currently using a 12" PowerBook and other
than finding the control key to be uncomfortably close to the space bar,
I find it perfectly reasonable for programming and emacs-ing.


Yes, that's evil. I was just in the UK a couple of weeks ago and was
using a semi-UK keyboard. As far as I could tell, the keycaps were
labeled with the UK layout, but the codes they generated were US style.
I touch-type, so as long as I ignored what was printed on the keycaps
and just typed normally, everything was fine. But it's amazingly
difficult to ignore the printed keycaps.

It's not that difficult if you gain some experience with it. Half
the keboards here are qwerty the other half is azerty. On all machines
I have to work on with an azerty I have configured my account to
treat the keyboard as if the keyboard is qwerty. After a little
getting used to that works easier and faster than always adjusting
to the keyboard of the specific computer.
 
S

Sion Arrowsmith

Roy Smith said:
What's wrong with Mac keyboards?

No @, hence tangential relevance to PEP318 (and a point against
pies, before or after the def). Unless you can remember it's on
option-3.
 
R

Roy Smith

Arthur said:
I must say that after days of waffling, and I think an honest effort
to accept where things were going, I woke this morning hating
@decorator.

The existing syntax for this kind of transformation is, in fact,
exactly what one would expect:

foo=staticmathed(foo).

That is the universal langauge for transformations. And when we try
to explain to anybody what it is that @decorator means, we go back to
the pseudo code that is in fact the existing syntax.

I'm with Arthur.

I think the core problem is that the def statement is kind of wierd. It
does two different things. First, it creates a function body, then it
binds the function to a name.

One of the objections to:

def foo ():
whatever
foo = decorator (foo)

is that you have to type the word "foo" three times. It's not so much
the effort of repeating the keystrokes, but the fact that it feels so
unfactored. The only reason you need to do this is because you have no
way of getting at the newly-generated function (what CS types would call
a "lambda form") before it's bound to the name.

A solution to that is to factor out the function definition from the
name binding, so you would do something like:

foo = def ():
whatever

although by the time you do that, you might as well have just gotten rid
of def and used lambda() directly. If you wanted it to be a
static/class method, you would do:

foo = staticmethod_def ():
whatever

The other big objection to the current syntax is that it puts the
wrapper way down at the bottom of the function body, away from the name.
The above syntax solves that too.

The big problem with the above is that it changes the semantics of the
def statement in a way which is incompatible with current usage, and
thus I would expect it's a complete non-starter. Not to mention
inventing new keywords.

On the other hand, doing:

def (staticmethod) foo ():
whatever

(you can pick whatever bits of punctuation turn you on) seems like it
should work just fine. I think it achieves all the goals:

1) It puts the decorator before the function body.

2) It keeps the decorator right next to the function name.

3) It doesn't re-define any currently valid syntax.

4) It looks enough like current Python syntax that most add-on tools
should handle it just fine.

5) If you've got lots of decorators (I'm still not sure if people really
think this will happen in real life), it's easy enough to break it up
into multiple lines:

def @decorator1 \
@decorator2 \
@decorator3 foo (a, b, c):
print a, b, c

but I'm assuming that will be the exception, just like really long
argument lists are the exception. Define the order of application of
multiple decorators in whichever way floats your boat; I'm guessing
outside-in (i.e. the last one gets done first) makes the most sense.

I suppose you could take this one step further and put the decorators
inside ()'s, so you'd have any of (as auto-indented by emacs):

def (decorator) foo (a, b, c):
pass

def (decorator1, decorator2, decorator3) foo (a, b, c):
pass

def (decorator1,
decorator2,
decorator3) foo (a, b, c):
pass

def (decorator1,
decorator2,
decorator3) foo (a,
b,
c):
pass

with the last example being a bit ugly, but at least it seems to follow
the expected indenting rules. In any case, you'd only have to resort to
something like that if you had lots of decorators and lots of arguments,
and in that case, I suspect you might want to be refactoring things to
simplify it all anyway.

I haven't done an exhaustive search of all the proposed syntaxen which
have come flying by here in the past week or so. My apologies if I've
accidentally duplicated somebody else's work here.

In retrospect (this has been written in dribs and drabs over the past
several hours, as I've been called away repeatedly to do real work), I
see I started out by agreeing with Arthur that the current (i.e. pre
PEP-318) way of doing things is good enough, then managed to head off
into a different direction and suggest YADS (Yet Another Decorator
Syntax). Oh, well.

I'm also not at all convinced that using decorators for things like doc
strings makes any sense at all. It's just the wrong tool. Docstrings
work just fine the way they are. If it ain't broke, don't fix it.
Which I guess brings me full-circle back to agreeing with Arthur :)
 
A

Arthur

I'm with Arthur.

Yes and no.

I am contendingt that that staus quo (pre 2.4 alpha2), all things
considered, is the best we are going to do, realistically.

Within the framwork of Python as it is, and without making changes to
Python as it is out of proportion to the need that is being addressed.

I certainly thing that @decorator is a chnage out of proportion to the
need being addressed.

But you are proposing a non-starter, which implicitly rejects the
status quo. And proposes other changes out of proportion to the need
being addressed.
One of the objections to:

def foo ():
whatever
foo = decorator (foo)

is that you have to type the word "foo" three times.

Big f**king deal - all things considered. ;)

Art
 
M

Mark Bottjer

Arthur said:
I guess I am mystified what it is that is perceived to have been
gained ... by moving magic outside the function block to the top of a
function in lieu of expressive code outside the function block at the
bottom of the function. Something is created, and then transofrmed -
in the language of transformation that transcends the implementation
detail of what programming language is doing the work.

I'm in the same boat. I wanted something (anything!) to get around the
ugliness that is f=foo(f) after the def. Now that we have it (in spades,
considering all the variants), I don't find it to be any more satisfying
than what we already had.

Sigh.

-- Mark
 
A

Arthur

Big f**king deal - all things considered. ;)

Mathematical notation looks to achieve conciseness, and precision of
expression. And on settled matters of notation, assumedly that attempt
has been optimized.

Why is that not good enough for Python?
 
M

Mark Bottjer

Roy said:
A solution to that is to factor out the function definition from the
name binding, so you would do something like:

foo = def ():
whatever

although by the time you do that, you might as well have just gotten rid
of def and used lambda() directly. If you wanted it to be a
static/class method, you would do:

foo = staticmethod_def ():
whatever

I agree that this seems to be the cleanest solution, but I also agree
with you that it is a non-starter. Maybe when we get subclassable
statements in Python 3.0. :)

-- Mark
 
D

David Eppstein

Arthur said:
foo=staticmathed(foo).

That is the universal langauge for transformations. And when we try
to explain to anybody what it is that @decorator means, we go back to
the pseudo code that is in fact the existing syntax.

I guess I am mystified what it is that is perceived to have been
gained ... by moving magic outside the function block to the top of a
function in lieu of expressive code outside the function block at the
bottom of the function.

Not having to write the function name three times? If it's just foo,
that would be one thing, but have you seen the PyObjC examples?

Also, it's not in the Zen of Python, but maybe declarative is better
than imperative?
 
R

Robin Becker

David said:
Not having to write the function name three times? If it's just foo,
that would be one thing, but have you seen the PyObjC examples?

Also, it's not in the Zen of Python, but maybe declarative is better
than imperative?

I think I'm with Arthur in that the current transformation notation is sufficient.

If people wish to avoid three names then we need proper anonymous functions as
others stated.

To avoid lots of extra parentheses we need a function call composition mechanism
or for people to define the functions they need rather than have arbitrary lists
of operators.
 
A

Arthur

Not having to write the function name three times? If it's just foo,
that would be one thing, but have you seen the PyObjC examples?

Does

def __f(something):
dosomething

the_name_I_really_ant_to_call=transform(__f)

work?
Also, it's not in the Zen of Python, but maybe declarative is better
than imperative?

Starting now, I guess. ;)

Art
 
D

David Eppstein

Also, it's not in the Zen of Python, but maybe declarative is better
than imperative?

Starting now, I guess. ;)[/QUOTE]

Well, I think starting with list comprehensions in place of imperative
append-loops.
 
P

paolo veronelli

Starting now, I guess. ;)

Well, I think starting with list comprehensions in place of imperative
append-loops.[/QUOTE]

I don't think there is a clear similarity,in fact I don't have any
declarative feeling when I use list comprehension,for me it's a shortcut.
With decorators before defs I have a new feeling,but not the good
declarative one I have with haskell (which would be nice to melt with).
I'm not erudite enough to explain it anyway.

Paolino
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top