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


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

Re: Python handles globals badly.

Started bytdev@freenet.de
First post2015-09-02 15:25 -0700
Last post2015-09-04 01:06 +0200
Articles 6 — 5 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-02 15:25 -0700
    Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-02 16:57 -0600
    Re: Python handles globals badly. Vladimir Ignatov <kmisoft@gmail.com> - 2015-09-02 20:16 -0400
    Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-03 02:10 +0100
    Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-03 02:15 +0100
    Re: Python handles globals badly. "Sven R. Kunze" <srkunze@mail.de> - 2015-09-04 01:06 +0200

#95901 — Re: Python handles globals badly.

Fromtdev@freenet.de
Date2015-09-02 15:25 -0700
SubjectRe: Python handles globals badly.
Message-ID<253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com>
Reflecting the answers I want to add following:

Considering class usage is something I thought about 
but is not the way I want use Python so far. 
If so, I could stay on oo-scripting languages as well.

It is the good idea of Python about modules which are singletons 
and therefore have already its state (so in some way they are already somehow 
like classes - except the bad annoying thing with the "global" statement).


That said, it is not an overusing of globals cause globals are module vars only.
Or have you never written singletons or other classes in e.g Java, C++ with 
lots of static and class members and methods using this members. 
With globals in Python are not meant traditional globals (app spanning vars) as already said.
Globals in Python are like class-members and statics in OO-languages. Globals are module scope!
And therefore it is not the devil or evil problem or code desaster problem
or LUA's opposite approach. 

(local/nonlocal statements I think are needed cause of lambda functionality and 
 is not what I try to discuss here)

Hopefully this clarifies a bit more my point of view and you can 
now agree that using "global" is not only over-regulated but also ugly code.
At least the developer should be free to use the "global"-statement 
(if one really need this?) or not (myself, and hopefully a lot other).  

Therefore still hoping a new PEP will arise.


@Mark Lawrence  
This response I have not checked. Can you provide arguments or clarify your statement?

[toc] | [next] | [standalone]


#95907

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-09-02 16:57 -0600
Message-ID<mailman.44.1441234678.8327.python-list@python.org>
In reply to#95901
On Wed, Sep 2, 2015 at 4:25 PM,  <tdev@freenet.de> wrote:
> That said, it is not an overusing of globals cause globals are module vars only.
> Or have you never written singletons or other classes in e.g Java, C++ with
> lots of static and class members and methods using this members.

I do use lots of static members in Java. 99.99% of them are constants,
which if translated to Python globals would not require a global
declaration anyway.

Class members are not like Python globals. Class members are like
Python class attributes.

> With globals in Python are not meant traditional globals (app spanning vars) as already said.
> Globals in Python are like class-members and statics in OO-languages. Globals are module scope!
> And therefore it is not the devil or evil problem or code desaster problem
> or LUA's opposite approach.
>
> (local/nonlocal statements I think are needed cause of lambda functionality and
>  is not what I try to discuss here)

The local statement I was talking about has nothing to do with
closures, which I think is what you mean. Within a given function, the
compiler needs to have some way of knowing whether a given name is
local or global. Currently that's done by the "global" keyword and by
checking whether the name is ever assigned within the function.

If the "global" keyword is no longer required, then there would have
to be some other way for the compiler to distinguish locals from
globals. The obvious solution would be to use a "local" keyword
instead. That seems to me like it would be a lot more annoying.

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


#95909

FromVladimir Ignatov <kmisoft@gmail.com>
Date2015-09-02 20:16 -0400
Message-ID<mailman.46.1441239411.8327.python-list@python.org>
In reply to#95901
Hi,

my 0.02

I don't personally use globals. And don't like "object oriented" code
(my code more inclined toward "functional" style). But sometimes I
feel like passing various minor values (like settings) all around app
via regular parameters is just too much work.  So I use
"pseudo-global" object which holds various stuff in its attributes.
And I pass that object around my code. But that is just one parameter,
not myriads of them.

Vladimir

http://itunes.apple.com/us/app/python-code-samples/id1025613117

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


#95911

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-09-03 02:10 +0100
Message-ID<mailman.47.1441242669.8327.python-list@python.org>
In reply to#95901
On 03/09/2015 01:16, Vladimir Ignatov wrote:
> Hi,
>
> my 0.02
>
> I don't personally use globals. And don't like "object oriented" code
> (my code more inclined toward "functional" style). But sometimes I
> feel like passing various minor values (like settings) all around app
> via regular parameters is just too much work.  So I use
> "pseudo-global" object which holds various stuff in its attributes.
> And I pass that object around my code. But that is just one parameter,
> not myriads of them.
>
> Vladimir
>
> http://itunes.apple.com/us/app/python-code-samples/id1025613117
>

Conceptually something like this 
https://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named 
?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


#95913

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-09-03 02:15 +0100
Message-ID<mailman.50.1441243208.8327.python-list@python.org>
In reply to#95901
On 02/09/2015 23:25, tdev@freenet.de wrote:
> Therefore still hoping a new PEP will arise.
>
> @Mark Lawrence
> This response I have not checked. Can you provide arguments or clarify your statement?
>

The over use of globals is never to be encouraged, which is precisely 
what this would do.  You could try raising this on python-ideas but I 
suspect you'd be wasting your time, so writing a PEP would almost 
certainly be a waste of time.  Still, if you've got free time go ahead, 
I won't stop you.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


#95980

From"Sven R. Kunze" <srkunze@mail.de>
Date2015-09-04 01:06 +0200
Message-ID<mailman.104.1441321620.8327.python-list@python.org>
In reply to#95901
On 03.09.2015 00:25, tdev@freenet.de wrote:
> It is the good idea of Python about modules which are singletons
> and therefore have already its state (so in some way they are already somehow
> like classes - except the bad annoying thing with the "global" statement).

So, what you really want is a better language support for singletons?

[toc] | [prev] | [standalone]


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


csiph-web