473,382 Members | 1,622 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,382 software developers and data experts.

PEP318 alternate syntax idea


It just occurred to me that if decorators really catch on, there could
be cases where they are applied repeatedly to many functions, and
possibly with many decorators. Combine that with many (and variable
numbers of) parameters per function and readability could be seriously
hit.

In C++, the 'private', 'public' and 'protected' modifiers for class
members are not applied individually to every single member. This
always struck me as being a good thing, and it irritates me that in C#
and java every single definition needs to specify it's visibility.
Yes, there's a default, but you still often get a lot of definitions
that don't match the default. Some classes present a lot of public
member functions as their interface, for instance.

If I were inventing a language, I would allow more modifiers to be
moved away from the definitions/declarations to some kind of preamble.
In C++, for instance, it bugs me if I have to individually declare
each of a group of members to be static, or mutable, or whatever.

With that in mind, how about...

def [staticmethod, ...] :
# could use alternate keyword such as 'decorate'

def a (a1, a2) :
"this function is decorated"
...

def b (b1, b2) :
"this function is also decorated"
...

def c (c1, c2) :
"this function is _not_ decorated"
...
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #1
5 1238
>>>>> "Stephen" == Stephen Horne <st***@ninereeds.fsnet.co.uk> writes:

Stephen> It just occurred to me that if decorators really catch
Stephen> on, there could be cases where they are applied
Stephen> repeatedly to many functions, and possibly with many
Stephen> decorators. Combine that with many (and variable numbers
Stephen> of) parameters per function and readability could be
Stephen> seriously hit.

d = publishdecorator

def f() [d]:
pass

def g() [d]:
pass

d = hidedecorator

def f2() [d]:
pass

def g2() [d]:
pass

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #2
On 23 Mar 2004 12:08:01 +0200, Ville Vainio <vi***@spammers.com>
wrote:
>> "Stephen" == Stephen Horne <st***@ninereeds.fsnet.co.uk> writes:


Stephen> It just occurred to me that if decorators really catch
Stephen> on, there could be cases where they are applied
Stephen> repeatedly to many functions, and possibly with many
Stephen> decorators. Combine that with many (and variable numbers
Stephen> of) parameters per function and readability could be
Stephen> seriously hit.

d = publishdecorator

def f() [d]:
pass


Do we really want people writing...

d = lambda x : staticmethod (someotherdecoration (whateverdeco (x))

def f() [d] :
pass
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #3
>>>>> "Stephen" == Stephen Horne <st***@ninereeds.fsnet.co.uk> writes:

Stephen> Do we really want people writing...

Stephen> d = lambda x : staticmethod (someotherdecoration (whateverdeco (x))

Probably not - but the 'as' syntax should accept any iterable, so it
could be

d = [d1, d2, d3]

or with currently proposed syntax

d = functional.compose([d1,d2,d3])

Which just needs the not-yet-implemented 'functional' module :-).

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #4
Python has the concept that names with a preceding underscores (__) will
be mangled in some way. I suppose the "compiler"/interpreter does this
name-mangling. Why not use the same concept:

def __static__theRealFunctionName(self, var1, var2):
pass

The compiler will do some name mangling. The function is called without
the __static__ part:

--> theRealFunctionName(3,4)
The advantages:

- Old code won't break (except if someone has functions starting with
__static__).
- It is an already used concept for "private" variables --> they might be
migrated to __private__
- well they even might be joined:
__static____privat__theRealFunctionName(...)
- don't use it if you don't need it (this probably defaults to a
__public__)
- The definition tells us what kind of method (class?) this is

The disadavantage:
- long names

Stupid idea? I guess so, but I am too stupid to see why?

Bye,

Marco
Jul 18 '05 #5
Ville Vainio wrote:
d = functional.compose([d1,d2,d3])

Which just needs the not-yet-implemented 'functional' module :-).


Well, PEP 309 has been submitted for review, so with any luck (since
it's not very controversial) we'll have somewhere to put compose().

But I only asked for partial(). Someone else can propose how to do The
Right Thing for function composition ;)

Peter Harris
Jul 18 '05 #6

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

Similar topics

10
by: Sean Ross | last post by:
Here's a breakdown of most of the syntax discussed re: PEP318 using an example from python-dev. There are probably several more (I've added ). The example applies both function decoration and...
30
by: ajsiegel | last post by:
Arthur wrote: >> And either intuitively, or consciously, he is doing something that >> offsets it from something truly intergrated into the core of the >> language. By breakling all of his own...
14
by: Arien Malec | last post by:
Apologies for feeding the fire, when we are rallying around a consensus, but I've been concerned about the clash between syntax and semantics, and I've finally reached a mini-epiphany: The...
21
by: Steel | last post by:
Hi at all, I have a very long html page with many photo. Therefore the best to print this page is to print the some page as PDF. Therefore I maked a PDF file like my page to print best. I'ld want...
2
by: Jason Ourscene | last post by:
I'm using the simplexml class to parse through some xml. when i use the standard foreach loop syntax, i get the expected results. <?php foreach ($xml->item as $artist) { echo $artist->title "<br...
20
by: Eric Wertman | last post by:
I was considering putting together a proposal for an alternate block syntax for python, and I figured I'd post it here and see what the general reactions are. I did some searching, and while I...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.