python-2.1 function attributes
chrisg at iacsolutions.com
chrisg at iacsolutions.com
Fri Jan 26 00:54:54 EST 2001
"Michael Hudson" <mwh21 at cam.ac.uk> wrote in message
news:<m33de7z7dn.fsf at atrus.jesus.cam.ac.uk>...
[ hack ]
>
> def f(a, b, c) with publish = 1; secure = 0:
> print "bobbins"
>
> Then you use backslashes when the attribute or argument list get long.
>
> def f(long_name, even_longer_name, still_longer_name) \
> with publish = 1; secure = 0
> grammar = f_grammar:
> print "bobbins"
>
> Thoughts?
This is the best idea I have seen yet. I would make the ; mandatory at
the end of lines, but that is the C in me, I'm sure. It might be
better, also, if line-continuation were required at the end of the
second line as well:
def f(long_name, even_longer_name, still_longer_name) \
with publish = 1; secure = 0 \
grammar = f_grammar:
print "bobbins"
(OT) One thing bothers me about this. It's the same thing that bothered
me about list comprehensions, and I like those. I'll quote from a
message on the Ruby vs. Python thread:
"Johann Hibschman" <johann at physics.berkeley.edu> wrote in message
news:<mthf2o6f2s.fsf at astron.berkeley.edu>...
[ hack ]
> I'm a bear of little brain, and I can fit most of Python into my head,
> but I had trouble getting all of Ruby in, because it had just that
> much more complexity. That's probably just practice, though.
[ hack ]
That's my problem with any new feature: anything that adds to the
complexity of the core of Python may make our beautiful language harder
to learn. I am likewise nervous about strong and/or explicit typing for
the same reason.
In fact (OT^2) I feel that explicit typing may be inherently bad in
Python as it adds complexity that may not be necessary. Why not?
Because when I write modules I (almost) always check types and classes
at the beginning of the function anyway. In many cases I allow a small
set of types (for instance, string or None) and I check for my own
conformance with an if ... : raise MyUglyError construct.
(OT^3) This also applies to the question in yet another thread about
knowing all the exceptions that a function can throw. This led to a
discussion of exceptions one should default to "ignoring"... another
thing I feel is a bad idea.
Remember that adding "beauty" or "elegance" to a language often has the
effect of making the learning curve steeper. This is a religion to
some, but when it comes to computer languages I am a pragmatist.
More information about the Python-list
mailing list