473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Yet another decorator proposal


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
Jul 18 '05 #1
7 1342
Marco Aschwanden <PP**********@spammotel.com> writes:
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.
Jul 18 '05 #2
Marco Aschwanden wrote:
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

--
Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
"kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
-- David Kastrup in de.comp.os.unix.linux.misc
Jul 18 '05 #3
On Wed, 11 Aug 2004, Reinhold Birkenfeld wrote:
- 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.

Jul 18 '05 #4
On Wed, 11 Aug 2004 10:55:40 -0400, Christopher T King <sq******@WPI.EDU>
wrote:
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
Jul 18 '05 #5
On Wed, 11 Aug 2004, Marco Aschwanden wrote:
On Wed, 11 Aug 2004 10:55:40 -0400, Christopher T King <sq******@WPI.EDU>
wrote:
Also, don't forget docstrings get thrown away when using python -OO.
Great voodoo would be needed to prevent this from happening.


<magic>


Like I said, great voodoo ;)

Jul 18 '05 #6
Marco Aschwanden wrote:
On Wed, 11 Aug 2004 10:55:40 -0400, Christopher T King <sq******@WPI.EDU>
wrote:
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.


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

Reinhold

--
Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
"kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
-- David Kastrup in de.comp.os.unix.linux.misc
Jul 18 '05 #7
On Thu, 12 Aug 2004 16:41:36 +0200, Reinhold Birkenfeld
<re************************@wolke7.net> wrote:
It doesn't really need to be triple-quoted, does it?


def test(): .... "A little test."
.... print "hi"
.... test.__doc__ 'A little test.'


It seems not, but I am not aware what language reference says to that...

Marco

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: C. Barnes | last post by:
I vote for def f(): (body of function) This is backwards compatible (Python <= 2.3 raise SyntaxError), and looks much nicer than @. The only problem is that you can't one-line a...
17
by: Istvan Albert | last post by:
Paul McGuire wrote: > Please reconsider the "def f() :" construct. Instead of > invoking a special punctuation character, it uses context and placement, > with familiar old 's, to infuse the...
24
by: Steven Bethard | last post by:
I think one of the biggest reasons we're having such problems coming to any agreement on decorator syntax is that each proposal makes a number of syntax decisions, not just one. For decorators, I...
37
by: Bengt Richter | last post by:
ISTM that @limited_expression_producing_function @another def func(): pass is syntactic sugar for creating a hidden list of functions. (Using '|' in place of '@' doesn't change the picture...
17
by: Doug Holton | last post by:
George W Bush, as certified by Florida's election commission. Which decorator syntax do you like the most? See http://wiki.wxpython.org/index.cgi/PythonDecoratorsPoll A. @classmethod def...
12
by: Steven Bethard | last post by:
The poll, as stated, asked voters to vote for the syntax suggestion they liked the /most/. Some of the conclusions people are trying to draw from it are what syntaxes people liked the /least/. ...
99
by: Paul McGuire | last post by:
There are a number of messages on the python-dev mail list that indicate that Guido is looking for some concensus to come from this list as to what *one* alternative syntax for decorators we would...
17
by: Jim Jewett | last post by:
Guido has said that he is open to considering *one* alternative decorator syntax. At the moment, (Phillip Eby's suggestion) J4 <URL: http://www.python.org/moin/PythonDecorators > (section 5.21...
16
by: Peter Otten | last post by:
I took the freedom to forward GvR's mail concerning decorator cosmetics. I think you should know about it. Peter ---------- Forwarded Message ---------- Subject: Strawman decision:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.