473,569 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1249
>>>>> "Stephen" == Stephen Horne <st***@ninereed s.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 = publishdecorato r

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***@ninereed s.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 = publishdecorato r

def f() [d]:
pass


Do we really want people writing...

d = lambda x : staticmethod (someotherdecor ation (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***@ninereed s.fsnet.co.uk> writes:

Stephen> Do we really want people writing...

Stephen> d = lambda x : staticmethod (someotherdecor ation (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.comp ose([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__theRe alFunctionName( self, var1, var2):
pass

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

--> theRealFunction Name(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____pri vat__theRealFun ctionName(...)
- 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.comp ose([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
1418
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 annotation. # .. , competing ways to say the same thing # def foo(self) : "doc string"
30
2288
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 rules. >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,...
14
1656
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 problem with PEP318 is that it is too powerful, and tries to do too much. It is a sledgehammer for attacking three problems: 1) Metadata, a la Java and...
21
5705
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 that when the user press the print button in the browser , it print automatically the pdf file and not the html page. To do that I insert at the...
2
1568
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 />"; }?> Outputs: Kinky Matchbox Twenty
20
1385
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 found a lot of tab vs space debates, I didn't see anything like what I'm thinking of, so forgive me if this is a very dead horse. Generally...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.