473,836 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why brackets & commas in func calls can't be ommited? (maybe it could be PEP?)

Hi all,
I looked to the PEPs & didn't find a proposition to remove brackets &
commas for to make Python func call syntax caml- or tcl- like: instead
of
result = myfun(param1, myfun2(param5, param8), param3)
just make possible using
result = myfun param1 (myfun2 param5 param8) param3

it would reduce length of code lines and make them more readable, + no
needs to write annoing charecters.
Maybe it will require more work than I suppose, for example handling
of things like
result = myfun(param1, myfun2(param5, param8), param3=15, param4=200)
to
result = myfun param1 (myfun2 param5 param8) param3=15 param4=200 #so
it needs some more efforts to decode by compiler

but anyway I think it worth.
+ it will not yield incompabilities with previous Python versions.

WBR, D.

Mar 21 '07
24 2296
dmitrey wrote:
1st still is shorter by 1 char; considering majority of people use
space after comma & number of parameters can be big it yileds
foo bar baz bar2 bar3 bar4
vs
foo(bar, baz, bar2, bar3, bar4)
I think most readers already agree on the ambiguities part. Now, for the
length of the code...
I agree that in you example the first syntax yields a full /five/ spaces
less than the second syntax. However, it ignores the fact that if you
are creating functions with that many arguments, you are probably doing
something wrong. Can't those arguments be provided as a list?
Let's see what is shorter:

foo bar baz bar2 bar3 bar4
or
foo *bars

Not to mention that it might (or might not) be a good idea to wrap the
function in some kind of class where you can specify a whole bunch of
attributes, so that you do not have to call a function with that many
arguments to start with.

Regards,
Bart
Mar 22 '07 #21
Bart Willems wrote:
dmitrey wrote:
>1st still is shorter by 1 char; considering majority of people use
space after comma & number of parameters can be big it yileds
foo bar baz bar2 bar3 bar4
vs
foo(bar, baz, bar2, bar3, bar4)

I think most readers already agree on the ambiguities part. Now, for the
length of the code...
I agree that in you example the first syntax yields a full /five/ spaces
less than the second syntax. However, it ignores the fact that if you
are creating functions with that many arguments, you are probably doing
something wrong. Can't those arguments be provided as a list?
I'm in danger of getting short-tempered on c.l.py for the first time in
a long time. If you think that five arguments is an excessive number for
a function then you live in a world of toy programs.
Let's see what is shorter:

foo bar baz bar2 bar3 bar4
or
foo *bars

Not to mention that it might (or might not) be a good idea to wrap the
function in some kind of class where you can specify a whole bunch of
attributes, so that you do not have to call a function with that many
arguments to start with.
Right, I think I have to assume that you're taking the piss.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 22 '07 #22
Steve Holden <st***@holdenwe b.comwrites:
I agree that in you example the first syntax yields a full /five/
spaces less than the second syntax. However, it ignores the fact
that if you are creating functions with that many arguments, you are
probably doing something wrong. Can't those arguments be provided as
a list?

I'm in danger of getting short-tempered on c.l.py for the first time
in a long time. If you think that five arguments is an excessive
number for a function then you live in a world of toy programs.
There's no need for functions of more than one argument. Even in
existing Python syntax, instead of

def f(a,b,c,d,e): ...

you could say

def f((a,b,c,d,e)): ...

and receive a,b,c,d,e in a single tuple.
Mar 22 '07 #23
<be************ @lycos.comwrote :
But I think in some situations Ruby allows to omit them, solving some
of the "impossibil e" problems shown in this thread. This makes Ruby a
bit better than Python to create application-specific mini languages,
that are quite useful in some situations.
Yes. However, Ruby parser has to resort to heuristic in many cases:

<http://www.rubycentral .com/book/language.html>

"When Ruby sees a name such as ``a'' in an expression, it needs to
determine if it is a local variable reference or a call to a method with
no parameters. To decide which is the case, Ruby uses a heuristic."

In fact it is something I don't really like about Ruby (even though I
find it useful in some cases).

This is a 'pathological example'

def a
print "Function 'a' called\n"
99
end
for i in 1..2
if i == 2
print "a=", a, "\n"
else
a = 1
print "a=", a, "\n"
end
end
But I have to say that omitting brackets in a language such as Python or
Ruby can make the code very hardly readable. The interpreter isn't the
only one who has to resort to heuristic: everytime you read a name with
no parenthesis you may have to go back and see whether it is a bound
variable, a method (so you may have to check documentation for various
modules) or an 'invalid' variable you forgot to initialize.

In fact, when I'm reading code from a project I'm not familiar with, it
can be quite hard in the first place.

In fact most Rubyists advice to use parentheses (unless you want to
achieve a DSL like effect, or in very simple cases like

puts s

)

The third problem I found out is related to blocks ({} and do have
different precedence order). They are only syntax errors, but I find
them annoying.

--
blog: http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site: http://www.akropolix.net/rik0/ | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
Mar 22 '07 #24
On Thu, 22 Mar 2007 14:20:42 -0400, Steve Holden <st***@holdenwe b.comwrote:
....
I'm in danger of getting short-tempered on c.l.py for the first time in
a long time. If you think that five arguments is an excessive number for
a function then you live in a world of toy programs.
Or at least in a world where people have good taste and time to Do It
Right(tm).

I personally believe many five-argument methods would be better off
refactored. I killed one today which had fourteen (most of which were
unused). But I don't pretend that it's always worth the effort of
doing that, in the real world.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyn dns.org R'lyeh wgah'nagl fhtagn!
Mar 23 '07 #25

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

Similar topics

0
2218
by: dohnut | last post by:
Here's one for some bored problem solver :) I ran across this earlier today and fixed it, but don't exactly know why. (that usually only happens in C :) I'm using Perl version 5.8.0 btw. Ok, let's start here: I end up with an array that comes from a fetchrow_array() call to MySQL. I return the array to a function.
5
1631
by: modemer | last post by:
I saw someone use the following code: void func(MyClass *& myCls) { myCls->test(); } // call func(): func(new MyClass);
6
15382
by: p|OtrEk | last post by:
What is practic difference between this two declarations? If i want call my func with func("blah") i could write: 1) func(std::string const& arg1) 2) func(const std::string& arg1) Whats better to use if i dont want to change content of arg1 it in func body? -- << pozdrawiam -lysek- @ irc.freenode.net#linux.com.pl << prompt$ :(){ :|:& };: << echo mail | sed 's/__NOSPAM//g'
27
2066
by: Peter Ammon | last post by:
My code obfuscator gave me this: char buff; to which gcc retorted: "ISO C90 forbids variable-size array 'buff'" and checking the standard, it appears that commas are indeed forbidden from being in a constant expression.
5
14066
by: Stef Mientki | last post by:
If I call a parameterless function without brackets at the end, the function is not performed, but ... I don't get an error message ??? Is this normal behavior ? thanks, Stef Mientki
9
4790
by: hufaunder | last post by:
I have a class "TestSuper" that implements the interface "TestBase". The interface has a property of type "ReturnType". The class "TestSuper" does not return "ReturnType" but a derivation "ReturnSuper". This gives the following compile error due to a bad return type: TestSuper does not implement interface member TestBase.Func. TestSuper.Func is either static, not public, or has the wrong return type.
2
2220
by: ek | last post by:
This first example does not work (cannot be overloaded): int& operator()(int a) { // (1) return a; } int const& operator()(int a) { // (2) return a; }
5
4781
by: Robert Dodier | last post by:
Hello, I'd like to split a string by commas, but only at the "top level" so to speak. An element can be a comma-less substring, or a quoted string, or a substring which looks like a function call. If some element contains commas, I don't want to split it. Examples: 'foo, bar, baz' ='foo' 'bar' 'baz'
45
2021
by: mdh | last post by:
Hi All, The section is titled Variable-length Argument lists. May I ask a question about the use of "macros". To quote K&R. "The standard header <stdarg.hcontains a set of macro definitions that define how to step through an argument list...... The type va_list is used to declare a variable...in minprintf..ap .......The macro va_start initializes ap to point to the first unnamed argument."
0
9814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9666
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10544
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7788
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6977
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5821
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4447
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
2
4010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.