Yet another decorator proposal

M

Marco Aschwanden

Here is yet another decorator proposal:

def sumSequencesLengths(var1, var2):
"""Computes something very important.

__decorators__:
staticmethod
__parameters__:
var1=Sequences
var2=Sequences
__returns__:
int
"""
result = len(var1) + len(var2)
return result

Reasoning:
Decorators are important to communicate to the programmer. So, if someone
wants to use decorators she better writes a documentation for it. So why
not let the documentation enforce the whole decoration system?

The main advantages:
- Keeps the documentation up-to-date! The first language to do so (-
doesn't it?)
- Enforces Python's readability further.
- Needs no new language constructs.


The main disadvantages:
- The values are frozen... the __decorators__ are set in a static string
- The definition follows after the def
- A "static" description has an impact on the "acting" program

There are really more pros and cons... it might be also only a
"Schnapsidee" - after all I am no language designer.

Have a nice day,
Marco
 
P

Paul Rubin

Marco Aschwanden said:
Here is yet another decorator proposal:

def sumSequencesLengths(var1, var2):
"""Computes something very important.

__decorators__:
staticmethod

I think you are onto something. The particular syntax you proposed
has shortcomings, but maybe improvements are possible.
 
R

Reinhold Birkenfeld

Marco said:
Here is yet another decorator proposal:

def sumSequencesLengths(var1, var2):
"""Computes something very important.

__decorators__:
staticmethod

I think this is not a great idea, for several reasons:

- Decorators are inside the function. I'm not generally against that,
but I agree that decorators are something important that, e.g., should
not be folded away.
- Decorators are "hidden" in a string. This is almost as ugly as the
meta-constructs some other languages have, hiding vital information in
comments.
- The indentation, if it is a crucial part of your proposal, is not
clear. Remember that docstrings are strings, and as such have no notion
of the current indentation of the function block.

Sorry, but if decorators should go into the body, I'm sure they will
take such a form:

def SomeFunction(param):
meta:
staticmethod
<code>

Reinhold
 
C

Christopher T King

- Decorators are "hidden" in a string. This is almost as ugly as the
meta-constructs some other languages have, hiding vital information in
comments.

Also, don't forget docstrings get thrown away when using python -OO.
Great voodoo would be needed to prevent this from happening.
 
M

Marco Aschwanden

Also, don't forget docstrings get thrown away when using python -OO.
Great voodoo would be needed to prevent this from happening.

<magic>
By now the compiler takes the first triple-quoted-string and sets it on
the object's __doc__-var. Even in -00 mode the compiler has to find the
triple-quoted-string... well on his way he can pick out the modifiers
before throwing the doc string away, and set the appropiate object vars
(__decorators__, __parameters__, ...).

Doesn't seem too complicated to me.
</magic>

Magic greetings,
Marco - The magician
 
R

Reinhold Birkenfeld

Marco said:
<magic>
By now the compiler takes the first triple-quoted-string and sets it on
the object's __doc__-var.

It doesn't really need to be triple-quoted, does it?

Reinhold
 
M

Marco Aschwanden

It doesn't really need to be triple-quoted, does it?
.... "A little test."
.... print "hi"
....
It seems not, but I am not aware what language reference says to that...

Marco
 

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

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top