Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95933 > unrolled thread

Re: Python handles globals badly.

Started bytdev@freenet.de
First post2015-09-03 06:22 -0700
Last post2015-09-03 18:41 -0400
Articles 9 — 8 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python handles globals badly. tdev@freenet.de - 2015-09-03 06:22 -0700
    Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2015-09-04 00:03 +1000
    Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2015-09-03 09:50 -0600
    Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-03 10:15 -0600
    Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2015-09-03 10:43 -0600
      Re: Python handles globals badly. Steven D'Aprano <steve@pearwood.info> - 2015-09-04 12:05 +1000
      Re: Python handles globals badly. pepekbabi5@gmail.com - 2015-09-06 15:35 -0700
    Re: Python handles globals badly. MRAB <python@mrabarnett.plus.com> - 2015-09-03 19:29 +0100
    Re: Python handles globals badly. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-03 18:41 -0400

#95933 — Re: Python handles globals badly.

Fromtdev@freenet.de
Date2015-09-03 06:22 -0700
SubjectRe: Python handles globals badly.
Message-ID<3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com>
Reflecting the answers I want to add following first:


I should have better started a new thread.
But now it is here, I want just clarify something before 
I move on (later) with repsonding.


I think this has lead to some confusing.


There are now two main topics in this thread.


First topic: 
"sharing globals between modules"
Where globals is meant as vars used throughout the app.

This is the topic why Skybuck starts the thread.
And yes I agree globals can be bad design
and it is solved via outsourcing to an extra module and used via imports.

I misinterpreted this topic a little by thinking 
the focus is more about the use of the badly "global" keyword
(in my point of view) and added therefore my post here as


Second topic: 
"Forced to use "global" for write-access inside functions 
is over-regulation and should be removed."

This topic has nothing todo with sharing globals.
It is about in the scope of a single module only.

When I have written globals in this topic 
I have meant and mean vars defined in a module outside 
functions and used inside function blocks.

Sorry if this has lead to confusion, but so long 
I have read docs I would say that these vars are 
often named as globals although I meant module vars.

Reason is that module scope is the highest
scope and often referred as the global scope.
That is also why I dislike the word "global" too.


I talk about this construct:

Sample "Bad":
module A
   _x = 0

   def y():
	global x
	_x=1


and I aim for - it would be nicer to allow for simplicity
writing this without the keyword "global"
and give this small responsibility ("write protection")
back to the developer:

Sample "Good":
module A
   _x = 0

   def y():
	_x=1


why - this I have tried and try to explain in my and your posts 
      in the hope a PEP will arise which frees me and hopefully
      a lot other developers getting forced to use "global"
      (If developers need this "global" - ok, but I and 
	hopefully more want not to be forced with that 
        code-contaminator, especially having a lot more vars)


Said that, I will not respond to comments about sharing globals

[toc] | [next] | [standalone]


#95935

FromChris Angelico <rosuav@gmail.com>
Date2015-09-04 00:03 +1000
Message-ID<mailman.67.1441289040.8327.python-list@python.org>
In reply to#95933
On Thu, Sep 3, 2015 at 11:22 PM,  <tdev@freenet.de> wrote:
> Sample "Good":
> module A
>    _x = 0
>
>    def y():
>         _x=1
>
>
> why - this I have tried and try to explain in my and your posts
>       in the hope a PEP will arise which frees me and hopefully
>       a lot other developers getting forced to use "global"
>       (If developers need this "global" - ok, but I and
>         hopefully more want not to be forced with that
>         code-contaminator, especially having a lot more vars)

Okay. Let's suppose that some magic is worked out that makes this
work. Now let's try this example:

def x(q):
    for word in generate_words():
        if word.matches(q):
            return word

def y():
    word = x("blue")
    otherword = x("green")
    if word < otherword: return otherword
    return x("red")

How would you reason about this code? Would you not expect that the
instances of 'word' in each function are completely independent? (And
while this is a contrived example, the exact same thing happens *a
lot*, where the name used in a "return" statement is the same as the
name that thing gets assigned to. After all, if it's a logical name
for that thing in one place, it's likely a logical name in the other,
too.) According to your proposal, they would cease to be independent
if the module grows an attribute 'word'. Since, in Python, such
attributes can be injected from outside, there is literally no way to
reason about this code in isolation. That makes it very difficult to
track down problems.

Definitely do not like this.

ChrisA

[toc] | [prev] | [next] | [standalone]


#95947

FromMichael Torrie <torriem@gmail.com>
Date2015-09-03 09:50 -0600
Message-ID<mailman.73.1441295457.8327.python-list@python.org>
In reply to#95933
On 09/03/2015 07:22 AM, tdev@freenet.de wrote:
> First topic: 
> "sharing globals between modules"
> Where globals is meant as vars used throughout the app.
>
> This is the topic why Skybuck starts the thread.

The answer to this is simple and elegant.  Use a third module to store
globals. Each module that needs it can simply import it.

[toc] | [prev] | [next] | [standalone]


#95955

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-09-03 10:15 -0600
Message-ID<mailman.82.1441296971.8327.python-list@python.org>
In reply to#95933
On Thu, Sep 3, 2015 at 7:22 AM,  <tdev@freenet.de> wrote:
> I think this has lead to some confusing.

I don't think so.

> First topic:
> "sharing globals between modules"
> Where globals is meant as vars used throughout the app.
>
> This is the topic why Skybuck starts the thread.
> And yes I agree globals can be bad design
> and it is solved via outsourcing to an extra module and used via imports.
>
> I misinterpreted this topic a little by thinking
> the focus is more about the use of the badly "global" keyword
> (in my point of view) and added therefore my post here as

The only person whom I see talking about this in this thread is you
disclaiming that you're not talking about it. (And I guess Skybuck is
talking about it, but I don't see those.)

> Said that, I will not respond to comments about sharing globals

> Said that, I will not respond to comments about using OO
or about comparisons made with other languages.

I don't know what comments about using OO you're referring to either.
I only see one suggestion to use classes, and you've already responded
to that. As far as comparisons to other languages, you're the one who
brought up the comparison to Java in the first place.

You seem to be spending a lot of time talking about what you won't
talk about, and very little time talking about your proposal, such as
by what magic you expect the compiler to distinguish globals from
locals without declarations.

[toc] | [prev] | [next] | [standalone]


#95962

FromMichael Torrie <torriem@gmail.com>
Date2015-09-03 10:43 -0600
Message-ID<mailman.89.1441298628.8327.python-list@python.org>
In reply to#95933
On 09/03/2015 10:15 AM, Ian Kelly wrote:
> The only person whom I see talking about this in this thread is you
> disclaiming that you're not talking about it. (And I guess Skybuck is
> talking about it, but I don't see those.)

I have a vague memory of Skybuck talking about globals over a year ago.
That must be what tdev's responding to.

Sadly Skybuck probably ditched Python a long time ago as he was spending
his time trying to make it into Java rather than taking advantage of
idiomatic Python programming.  Those that try to program Java style in
Python are going to be frustrated.

[toc] | [prev] | [next] | [standalone]


#95989

FromSteven D'Aprano <steve@pearwood.info>
Date2015-09-04 12:05 +1000
Message-ID<55e8fc75$0$1644$c3e8da3$5496439d@news.astraweb.com>
In reply to#95962
On Fri, 4 Sep 2015 02:43 am, Michael Torrie wrote:

> Sadly Skybuck probably ditched Python a long time ago

"Sadly"?



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#96085

Frompepekbabi5@gmail.com
Date2015-09-06 15:35 -0700
Message-ID<e8ff7ef3-d42e-4b66-914e-18109837892a@googlegroups.com>
In reply to#95962
idiomatic Python programming.  Those that try to program Java style in 
Python are going to be frustrated. 

[toc] | [prev] | [next] | [standalone]


#95967

FromMRAB <python@mrabarnett.plus.com>
Date2015-09-03 19:29 +0100
Message-ID<mailman.93.1441304994.8327.python-list@python.org>
In reply to#95933
On 2015-09-03 17:43, Michael Torrie wrote:
> On 09/03/2015 10:15 AM, Ian Kelly wrote:
>> The only person whom I see talking about this in this thread is you
>> disclaiming that you're not talking about it. (And I guess Skybuck is
>> talking about it, but I don't see those.)
>
> I have a vague memory of Skybuck talking about globals over a year ago.
> That must be what tdev's responding to.
>
It wasn't as long ago as that; it's been only 9 months! :-)

> Sadly Skybuck probably ditched Python a long time ago as he was spending
> his time trying to make it into Java rather than taking advantage of
> idiomatic Python programming.  Those that try to program Java style in
> Python are going to be frustrated.
>

[toc] | [prev] | [next] | [standalone]


#95977

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2015-09-03 18:41 -0400
Message-ID<mailman.101.1441320074.8327.python-list@python.org>
In reply to#95933
On Thu, 3 Sep 2015 19:29:48 +0100, MRAB <python@mrabarnett.plus.com>
declaimed the following:

>On 2015-09-03 17:43, Michael Torrie wrote:
>> On 09/03/2015 10:15 AM, Ian Kelly wrote:
>>> The only person whom I see talking about this in this thread is you
>>> disclaiming that you're not talking about it. (And I guess Skybuck is
>>> talking about it, but I don't see those.)
>>
>> I have a vague memory of Skybuck talking about globals over a year ago.
>> That must be what tdev's responding to.
>>
>It wasn't as long ago as that; it's been only 9 months! :-)
>

	Still a rather pregnant pause...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web