
Why do function definitions require parens?
This seems to me to break a symmetry with class definitions. I assume this is just a hold off from C, perhaps there is a non-historical reason tho. I believe in the past we've forced parens in list comprehensions to create a symmetry between comprehensions/generator expressions. Why not for this?

Jason Keene wrote:
Just to be clear, I wasn't suggesting forcing parens for class definitions. Rather make them optional for functions!
That would introduce an asymmetry between function definitions and function calls -- parens would be required in the call but not the definition. And before you say that this asymmetry currently exists between class definitions and class instantiations, it's not the same situation. What goes between the parens in a class definition is the base classes, not the arguments to the constructor. -- Greg

On 2013-01-31 16:35, Jason Keene wrote:
The parentheses are always required when calling the function, so it makes sense to always require them when defining the function. The case with class definitions is different; they are used in the definition only when you want to specify the superclass. They are always required when creating an instance of the class and in method definitions.

On 1/31/2013 12:15 PM, MRAB wrote:
I think parens for super class are an unfortunate syntax, since it looks just like arguments to the class and is confusing for some beginners: def function(arg): ... function(10) # Similar syntax: 10 corresponds to arg class Thing(Something): ... thing = Thing(10) # How does 10 relate to Something? It doesn't. A better syntax (which I AM NOT PROPOSING) would be: class Thing from Something: --Ned.

On Fri, Feb 1, 2013 at 5:11 AM, Ned Batchelder <ned@nedbatchelder.com> wrote:
What about class Thing = Something: pass I am not proposing this either, but it would emphasize the difference between superclasses and __init__ args. But really, parens are used in many different ways. There doesn't need to be a logical parallel between generator expressions and function calls, for instance. ChrisA

Other strange thing is that the `raise` statement doesn't require to instantiate an Exception object, allowing to pass an Exception class to it. raise NotImplementedError raise NotImplementedError() Is there any difference between this two lines of code? And there is nothing about that fact in python docs. (or I just not found?..) -- Andrew 31.01.2013 20:35, Jason Keene ?????:

On 1/31/2013 4:06 PM, Barry Warsaw wrote:
Questions like this below on python-list, not here.
The main difference (I *think* this is still true) is that in the first example, if the exception is caught in C it can avoid instantiation.
The the second form allows addition of a message, which is usually a good idea. -- Terry Jan Reedy

In a way they do the same thing, they both create an object (function/class) from a suite and assign it to the name given after the keyword (def/class). Sure they do totally different things with the suite in creating the object, but in essence it's a name assignment. On Thursday, January 31, 2013, Steven D'Aprano wrote:

Jason Keene <jasonkeene@gmail.com> writes:
In a way, ‘import’ and ‘break’ do the same thing, they trigger the compiler to compile a particular set of code bytes. Sure the code bytes do totally different things, but in essence it's a statement. Less facetiously: You can blur your vision as much as you like to make ‘class’ and ‘def’ look similar, but that doesn't diminish the importance of the distinctions you're ignoring. -- \ “Always do right. This will gratify some people, and astonish | `\ the rest.” —Mark Twain | _o__) | Ben Finney

Both class and function definitions produce callable objects that are assigned to a name with nearly identical syntax. I don't think your analogy with import/break statements is valid. Additionally, both definitions produce very similar byte codes: 3 MAKE_FUNCTION 0 6 STORE_FAST 0 (my_func) 9 MAKE_FUNCTION 0 12 CALL_FUNCTION 0 15 BUILD_CLASS 16 STORE_FAST 0 (MyClass) The only argument I see for requiring empty parens in function definitions is a historical one. On Thursday, January 31, 2013, Ben Finney wrote:

http://www.youtube.com/watch?v=etuPF1yJRzg If only more of us grew up watching sesame street. On Friday, February 1, 2013, Jason Keene wrote:

Jason Keene wrote:
Just to be clear, I wasn't suggesting forcing parens for class definitions. Rather make them optional for functions!
That would introduce an asymmetry between function definitions and function calls -- parens would be required in the call but not the definition. And before you say that this asymmetry currently exists between class definitions and class instantiations, it's not the same situation. What goes between the parens in a class definition is the base classes, not the arguments to the constructor. -- Greg

On 2013-01-31 16:35, Jason Keene wrote:
The parentheses are always required when calling the function, so it makes sense to always require them when defining the function. The case with class definitions is different; they are used in the definition only when you want to specify the superclass. They are always required when creating an instance of the class and in method definitions.

On 1/31/2013 12:15 PM, MRAB wrote:
I think parens for super class are an unfortunate syntax, since it looks just like arguments to the class and is confusing for some beginners: def function(arg): ... function(10) # Similar syntax: 10 corresponds to arg class Thing(Something): ... thing = Thing(10) # How does 10 relate to Something? It doesn't. A better syntax (which I AM NOT PROPOSING) would be: class Thing from Something: --Ned.

On Fri, Feb 1, 2013 at 5:11 AM, Ned Batchelder <ned@nedbatchelder.com> wrote:
What about class Thing = Something: pass I am not proposing this either, but it would emphasize the difference between superclasses and __init__ args. But really, parens are used in many different ways. There doesn't need to be a logical parallel between generator expressions and function calls, for instance. ChrisA

Other strange thing is that the `raise` statement doesn't require to instantiate an Exception object, allowing to pass an Exception class to it. raise NotImplementedError raise NotImplementedError() Is there any difference between this two lines of code? And there is nothing about that fact in python docs. (or I just not found?..) -- Andrew 31.01.2013 20:35, Jason Keene ?????:

On 1/31/2013 4:06 PM, Barry Warsaw wrote:
Questions like this below on python-list, not here.
The main difference (I *think* this is still true) is that in the first example, if the exception is caught in C it can avoid instantiation.
The the second form allows addition of a message, which is usually a good idea. -- Terry Jan Reedy

In a way they do the same thing, they both create an object (function/class) from a suite and assign it to the name given after the keyword (def/class). Sure they do totally different things with the suite in creating the object, but in essence it's a name assignment. On Thursday, January 31, 2013, Steven D'Aprano wrote:

Jason Keene <jasonkeene@gmail.com> writes:
In a way, ‘import’ and ‘break’ do the same thing, they trigger the compiler to compile a particular set of code bytes. Sure the code bytes do totally different things, but in essence it's a statement. Less facetiously: You can blur your vision as much as you like to make ‘class’ and ‘def’ look similar, but that doesn't diminish the importance of the distinctions you're ignoring. -- \ “Always do right. This will gratify some people, and astonish | `\ the rest.” —Mark Twain | _o__) | Ben Finney

Both class and function definitions produce callable objects that are assigned to a name with nearly identical syntax. I don't think your analogy with import/break statements is valid. Additionally, both definitions produce very similar byte codes: 3 MAKE_FUNCTION 0 6 STORE_FAST 0 (my_func) 9 MAKE_FUNCTION 0 12 CALL_FUNCTION 0 15 BUILD_CLASS 16 STORE_FAST 0 (MyClass) The only argument I see for requiring empty parens in function definitions is a historical one. On Thursday, January 31, 2013, Ben Finney wrote:

http://www.youtube.com/watch?v=etuPF1yJRzg If only more of us grew up watching sesame street. On Friday, February 1, 2013, Jason Keene wrote:
participants (12)
-
Andrew Grigorev
-
Barry Warsaw
-
Ben Finney
-
Chris Angelico
-
Eric Snow
-
Ethan Furman
-
Greg Ewing
-
Jason Keene
-
MRAB
-
Ned Batchelder
-
Steven D'Aprano
-
Terry Reedy