[Python-ideas] globals should accept parenteses for extending beyond 1 line
João Matos
jcrmatos at gmail.com
Mon Jan 23 14:37:44 EST 2017
Hello,
You are correct, my mistake. I should have written global and not globals.
The purpose of using parentheses on the import statement is not (in my
view) for operational efficiency but for appearance/cleaness.
The same applies to using it to global.
One does not need to have 10 global vars. It may have to do with var
name length and the 79 max line length.
This is an example from my one of my programs:
global existing_graph, expected_duration_in_sec, file_size, \
file_mtime, no_change_counter
Anyway, the use of global being rare is of no concern. The point of my
suggestion is standardization.
My opinion is that a standard language is easier to learn (and teach)
than one that has different syntax for the same issue, depending on the
statement.
In short, if the recommended multi-line use for import is
import (a, b,
c)
instead of
import a, b, \
c
Then the same should apply to global.
Best regards,
JM
On 23-01-2017 19:25, Terry Reedy wrote:
> On 1/23/2017 1:43 PM, João Matos wrote:
>> Hello,
>>
>> I would like to suggest that globals should follow the existing rule
>> (followed by the import statement, the if statement and in other places)
>> for extending beyond 1 line using parentheses.
>> Like this:
>> globals (var_1, var_2,
>> var_3)
>>
>> instead of what must be done now, which is:
>> globals var_1, var_2 \
>> var_3
>
> The declaration keyword is 'global'; 'globals' is the built-in
> function. In any case
>
> global var_1, var_2
> global var_3
>
> works fine. There is no connection between the names and, unlike with
> import, no operational efficiency is gained by mashing the statements
> together.
>
> This issue should be rare. The global statement is only needed when
> one is rebinding global names within a function*. If a function
> rebinds 10 different global names, the design should probably be
> re-examined.
>
> * 'global' at class scope seems useless.
>
> a = 0
> class C:
> a = 1
>
> has the same effect as
> a = 0
> a = 1
> class C: pass
>
More information about the Python-ideas
mailing list