[Python-ideas] Fwd: Make parenthesis optional in parameterless functions definitions

Michel Desmoulin desmoulinmichel at gmail.com
Fri Apr 1 07:49:03 EDT 2016



Le 01/04/2016 04:37, Joao S. O. Bueno a écrit :
> On 31 March 2016 at 14:57, Steven D'Aprano <steve at pearwood.info> wrote:
>> On Thu, Mar 31, 2016 at 09:29:36PM +0500, Mahan Marwat wrote:
>>
>>> I have an idea of making parenthesis optional for functions having no
>>> parameters. i.e
>>>
>>> def greet: # note the missing parenthesis
>>>     print('hello')
>>
>> -1
>>
>> I don't think that the benefit (two fewer characters to type) is worth
>> the effort of learning the special case. Right now, the rule is simple:
>> the def keyword ALWAYS needs parentheses after the name of the function,
>> regardless of whether there is one argumemt, two arguments, twenty
>> arguments, or zero arguments. Why treat zero as special?
> 
> Because class definitions already do so?

Yes, and because after more than a decade of Python, I still forget to
type out the parenthesis some time, then go back and realize that it's
silly that I have to since I don't with classes.

That, and:

- it's a common student error;
- really it wouldn't hurt anyone.

Is there really a strong case against it than just "it's not pure" ?
I've seen of lot of this argument on the list lately and I find it
counter productive.

There are dozen of good way to oppose an idea, just saying "we got a
moral stand to not do it" is not convincing. Espacially in a language
with so many compromised like len(foo) instead of foo.len, functional
paradigme and Poo and immutability and mutability, etc.

Python has an history of making things to get out of the way:

- no {} for indentation;
- optional parentheses for tuples;
- optional parenthesis for classes;

If this changes does not hurt readability, ability to debug and doesn't
make your code/program any worst than it was but does't help even a
little, why not ?

> 
> So, if it is possible to omit parentheses when inheriting from the
> default object when declaring a class, not needing parenthesis for
> default parameterless functions would not be an exception - it would
> be generalizing the idea of "Python admits less clutter".
> 
> 
> For that, I'd think of this a good idea - but I don't like changing
> the idea syntax in such a fundamental way - so I am +0 on this thing.
> 
> I think this can be an interesting discussion - but I dislike people
> taking a ride on this to suggest omitting parentheses on function
> calls as well - that is totally broken. :-)

+1. This is for another thread (that hope will die).
> 
>   js
>  -><-
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
> 


More information about the Python-ideas mailing list