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


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

Python handles globals badly.

Started by"Skybuck Flying" <skybuck2000@hotmail.com>
First post2014-12-03 03:27 +0100
Last post2014-12-03 20:31 +0000
Articles 16 on this page of 36 — 19 participants

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


Contents

  Python handles globals badly. "Skybuck Flying" <skybuck2000@hotmail.com> - 2014-12-03 03:27 +0100
    Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2014-12-03 13:35 +1100
    RE: Python handles globals badly. "Clayton Kirkwood" <crk@godblessthe.us> - 2014-12-02 18:53 -0800
    Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2014-12-02 20:13 -0700
      Re: Python handles globals badly. "Skybuck Flying" <skybuck2000@hotmail.com> - 2014-12-03 05:32 +0100
        Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2014-12-03 15:42 +1100
        Re: Python handles globals badly. Dave Angel <davea@davea.name> - 2014-12-03 00:02 -0500
        Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2014-12-02 22:23 -0700
          Re: Python handles globals badly. Marko Rauhamaa <marko@pacujo.net> - 2014-12-03 08:52 +0200
            Re: Python handles globals badly. Joel Goldstick <joel.goldstick@gmail.com> - 2014-12-03 02:17 -0500
        Re: Python handles globals badly. Joshua Landau <joshua@landau.ws> - 2014-12-03 13:07 +0000
        Re: Python handles globals badly. mm0fmf <none@mailinator.com> - 2014-12-03 18:04 +0000
          Re: Python handles globals badly. sohcahtoa82@gmail.com - 2014-12-03 10:16 -0800
            Re: Python handles globals badly. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-04 11:57 +1100
              Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2014-12-04 12:10 +1100
              Re: Python handles globals badly. Joel Goldstick <joel.goldstick@gmail.com> - 2014-12-03 20:23 -0500
            Re: Python handles globals badly. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-12-03 22:57 -0500
            Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2014-12-03 21:11 -0700
    Re: Python handles globals badly. Ben Finney <ben+python@benfinney.id.au> - 2014-12-03 14:21 +1100
    Re: Python handles globals badly. "Skybuck Flying" <skybuck2000@hotmail.com> - 2014-12-03 05:17 +0100
      Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2014-12-03 15:36 +1100
      Re: Python handles globals badly. Tony the Tiger <tony@tiger.invalid> - 2014-12-04 20:27 +0000
    Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-12-03 12:35 +0000
      Re: Python handles globals badly. "Skybuck Flying" <skybuck2000@hotmail.com> - 2014-12-04 00:02 +0100
        Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-12-04 01:32 +0000
        Re: Python handles globals badly. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-12-03 23:01 -0500
        Re: Python handles globals badly. jtan <admin@grails.asia> - 2014-12-04 13:03 +0800
          Re: Python handles globals badly. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-04 22:35 +1100
            Re: Python handles globals badly. jtan <admin@grails.asia> - 2014-12-04 22:38 +0800
        Re: Python handles globals badly. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-12-04 10:24 +0000
        Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2014-12-04 21:29 +1100
          Re: Python handles globals badly. Marko Rauhamaa <marko@pacujo.net> - 2014-12-04 14:51 +0200
            Re: Python handles globals badly. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-12-04 20:56 -0500
            Re: Python handles globals badly. William Ray Wing <wrw@mac.com> - 2014-12-04 23:17 -0500
        Re: Python handles globals badly. alister <alister.nospam.ware@ntlworld.com> - 2014-12-04 19:54 +0000
    Re: Python handles globals badly. Peter Pearson <pkpearson@nowhere.invalid> - 2014-12-03 20:31 +0000

Page 2 of 2 — ← Prev page 1 [2]


#81832

FromChris Angelico <rosuav@gmail.com>
Date2014-12-03 15:36 +1100
Message-ID<mailman.16512.1417581411.18130.python-list@python.org>
In reply to#81830
On Wed, Dec 3, 2014 at 3:17 PM, Skybuck Flying <skybuck2000@hotmail.com> wrote:
> I hope python one day gets rid of it;
>
> 1. To stop the confusion.
> 2. To stop the doubt.
> 3. To stop the wasted lines.
> 4. To program with more confidence.
> 5. To stop to have to inspect what's going on if one wants to know for sure.
> 6. To stop any weird programming mistakes because a global declaration was
> not used somewhere in a function, it's probably easier to miss, cause in the
> programmers mind he's thinking: "it's global".
>
> Now it's just some
> half-ass-fucked-up-not-really-global-variable-unless-you-specify-it-local-to-be-global-holy-shit-batman-feel-the-brain-pain
> ?!
>

If you want C-like infinitely nested scopes, you basically have to
have declared variables, which Python doesn't want. There are other
languages which are very Python-like but do have declared variables
and infinitely-nested scopes, but I'm not sure I want to deal with
this kind of anger on another mailing list, so I won't name one. Once
again, though, you need to (a) learn the language before getting
irate, and (b) play to its strengths, not its weaknesses. Python's
requirement to declare all globals is a major weakness when you have
hundreds of globals, so don't do that (or don't complain about how
your code looks when you do).

ChrisA

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


#81946

FromTony the Tiger <tony@tiger.invalid>
Date2014-12-04 20:27 +0000
Message-ID<5480c3c3$0$32983$c3e8da3$12bcf670@news.astraweb.com>
In reply to#81830
On Wed, 03 Dec 2014 05:17:04 +0100, Skybuck Flying wrote:

> Should global be added to a or not ?!

Only when you alter its content. Think of it as a write enabling flag:
http://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them


 /Grrr
-- 
          ___                  ___
 (\_--_/)  | _ ._    _|_|_  _   |o _  _ ._
 ( 9  9 )  |(_)| |\/  |_| |(/_  ||(_|(/_|
 stripes are forever - as overripe ferrets

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


#81860

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-12-03 12:35 +0000
Message-ID<mailman.16534.1417610132.18130.python-list@python.org>
In reply to#81824
On 03/12/2014 02:27, Skybuck Flying wrote:
> Excuse is: "bad programming style".
>
> I don't need snot telling me how to program after 20 years of
> programming experience.
>
> This is so far the only thing pissing me off in python.
>
> Now I have to declare "global" in front of these variables every where I
> want to use em:

Another example of a bad workman always blames his tools.

-- 
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]


#81873

From"Skybuck Flying" <skybuck2000@hotmail.com>
Date2014-12-04 00:02 +0100
Message-ID<b9ec4$547f9679$5419aafe$42415@news.ziggo.nl>
In reply to#81860

"Mark Lawrence"  wrote in message 
news:mailman.16534.1417610132.18130.python-list@python.org...

On 03/12/2014 02:27, Skybuck Flying wrote:
> Excuse is: "bad programming style".
>
> I don't need snot telling me how to program after 20 years of
> programming experience.
>
> This is so far the only thing pissing me off in python.
>
> Now I have to declare "global" in front of these variables every where I
> want to use em:

"
Another example of a bad workman always blames his tools.
"

Euhm, so why don't you program with just 0 and 1's then ? ;)

Bye,
  Skybuck :) 

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


#81878

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-12-04 01:32 +0000
Message-ID<mailman.16544.1417656796.18130.python-list@python.org>
In reply to#81873
On 03/12/2014 23:02, Skybuck Flying wrote:
>
>
> "Mark Lawrence"  wrote in message
> news:mailman.16534.1417610132.18130.python-list@python.org...
>
> On 03/12/2014 02:27, Skybuck Flying wrote:
>> Excuse is: "bad programming style".
>>
>> I don't need snot telling me how to program after 20 years of
>> programming experience.
>>
>> This is so far the only thing pissing me off in python.
>>
>> Now I have to declare "global" in front of these variables every where I
>> want to use em:

This reminds of of a quote from a colleague some 25 years ago "Real time 
programming is easy, you just make all the data global".  Perhaps you 
attended the same school?

>
> "
> Another example of a bad workman always blames his tools.
> "
>
> Euhm, so why don't you program with just 0 and 1's then ? ;)
>

I did with the M6800 in the late 70s.  Thankfully maybe 12 years ago I 
came across Python and it was love at first sight.  I've never looked back.

-- 
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]


#81880

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2014-12-03 23:01 -0500
Message-ID<mailman.16546.1417665908.18130.python-list@python.org>
In reply to#81873
On Thu, 4 Dec 2014 00:02:25 +0100, "Skybuck Flying"
<skybuck2000@hotmail.com> declaimed the following:

>
>Euhm, so why don't you program with just 0 and 1's then ? ;)

	Why settle for hammer&chisel to make one tombstone a month when one can
use a diamond grit bit on a router and produce a tombstone every other day.

	15 times the productivity.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


#81889

Fromjtan <admin@grails.asia>
Date2014-12-04 13:03 +0800
Message-ID<mailman.16551.1417688317.18130.python-list@python.org>
In reply to#81873

[Multipart message — attachments visible in raw view] — view raw

How can Skybuck use so much globals. Wouldn't that introduce a lot of
thread safety problems?

On Thu, Dec 4, 2014 at 9:32 AM, Mark Lawrence <breamoreboy@yahoo.co.uk>
wrote:

> On 03/12/2014 23:02, Skybuck Flying wrote:
>
>>
>>
>> "Mark Lawrence"  wrote in message
>> news:mailman.16534.1417610132.18130.python-list@python.org...
>>
>> On 03/12/2014 02:27, Skybuck Flying wrote:
>>
>>> Excuse is: "bad programming style".
>>>
>>> I don't need snot telling me how to program after 20 years of
>>> programming experience.
>>>
>>> This is so far the only thing pissing me off in python.
>>>
>>> Now I have to declare "global" in front of these variables every where I
>>> want to use em:
>>>
>>
> This reminds of of a quote from a colleague some 25 years ago "Real time
> programming is easy, you just make all the data global".  Perhaps you
> attended the same school?
>
>
>> "
>> Another example of a bad workman always blames his tools.
>> "
>>
>> Euhm, so why don't you program with just 0 and 1's then ? ;)
>>
>>
> I did with the M6800 in the late 70s.  Thankfully maybe 12 years ago I
> came across Python and it was love at first sight.  I've never looked back.
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Freelance Grails <http://grails.asia/> and Java <http://javadevnotes.com/>
 developer

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


#81900

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-12-04 22:35 +1100
Message-ID<54804719$0$12988$c3e8da3$5496439d@news.astraweb.com>
In reply to#81889
jtan wrote:

> How can Skybuck use so much globals. Wouldn't that introduce a lot of
> thread safety problems?

Of course it would. But I expect that Skybuck probably doesn't even know
what threads are. Or if he does, he probably doesn't believe that they
should be used.

Thread safety is just the start of the problems with global variables:

http://c2.com/cgi/wiki?GlobalVariablesAreBad

Globals in Python are less bad than in many other languages, since they are
localised to a single module only. And the use of a few globals here and
there as needed is perfectly fine for small scripts. But using dozens of
them to avoid passing arguments to functions, that's just awful code.


-- 
Steven

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


#81914

Fromjtan <admin@grails.asia>
Date2014-12-04 22:38 +0800
Message-ID<mailman.16563.1417708675.18130.python-list@python.org>
In reply to#81900

[Multipart message — attachments visible in raw view] — view raw

I wish him all the luck while having sleep deprivation trying to solve
production issues :)

On Thu, Dec 4, 2014 at 7:35 PM, Steven D'Aprano <
steve+comp.lang.python@pearwood.info> wrote:

> jtan wrote:
>
> > How can Skybuck use so much globals. Wouldn't that introduce a lot of
> > thread safety problems?
>
> Of course it would. But I expect that Skybuck probably doesn't even know
> what threads are. Or if he does, he probably doesn't believe that they
> should be used.
>
> Thread safety is just the start of the problems with global variables:
>
> http://c2.com/cgi/wiki?GlobalVariablesAreBad
>
> Globals in Python are less bad than in many other languages, since they are
> localised to a single module only. And the use of a few globals here and
> there as needed is perfectly fine for small scripts. But using dozens of
> them to avoid passing arguments to functions, that's just awful code.
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Freelance Grails <http://grails.asia/> and Java <http://javadevnotes.com/>
 developer

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


#81891

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-12-04 10:24 +0000
Message-ID<mailman.16553.1417688690.18130.python-list@python.org>
In reply to#81873
On 04/12/2014 05:03, jtan wrote:
> How can Skybuck use so much globals. Wouldn't that introduce a lot of
> thread safety problems?
>

I actually don't know.  However buying very strong thread from your 
local store and making sure that you have a very sharp needle does help 
alleviate threading safety problems.  I do know that using globals is 
almost as bad as top posting on this list.

-- 
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]


#81893

FromChris Angelico <rosuav@gmail.com>
Date2014-12-04 21:29 +1100
Message-ID<mailman.16554.1417688990.18130.python-list@python.org>
In reply to#81873
On Thu, Dec 4, 2014 at 4:03 PM, jtan <admin@grails.asia> wrote:
> How can Skybuck use so much globals. Wouldn't that introduce a lot of thread
> safety problems?

A lot of programs don't use threads, and therefore cannot have thread
safety problems - or, looking at it the other way, do not care about
thread safetiness. It's like having Neil Armstrong wear water wings to
make sure he won't drown in the Sea of Tranquility.

ChrisA

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


#81904

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-12-04 14:51 +0200
Message-ID<87a933a88t.fsf@elektro.pacujo.net>
In reply to#81893
Chris Angelico <rosuav@gmail.com>:

> A lot of programs don't use threads, and therefore cannot have thread
> safety problems - or, looking at it the other way, do not care about
> thread safetiness. It's like having Neil Armstrong wear water wings to
> make sure he won't drown in the Sea of Tranquility.

The water wings would be too unwieldy since they'd have to be six times
as large on the moon. It's all about risk/benefit analysis.


Marko

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


#81969

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2014-12-04 20:56 -0500
Message-ID<mailman.16603.1417744616.18130.python-list@python.org>
In reply to#81904
On Thu, 04 Dec 2014 14:51:14 +0200, Marko Rauhamaa <marko@pacujo.net>
declaimed the following:

>Chris Angelico <rosuav@gmail.com>:
>
>> A lot of programs don't use threads, and therefore cannot have thread
>> safety problems - or, looking at it the other way, do not care about
>> thread safetiness. It's like having Neil Armstrong wear water wings to
>> make sure he won't drown in the Sea of Tranquility.
>
>The water wings would be too unwieldy since they'd have to be six times
>as large on the moon. It's all about risk/benefit analysis.

	Actually, since the pull of gravity is 1/6th that of earth, but the
density of the "water" is the Sea is the same, the water wings should be
smaller to provide the same degree of lift.

	Of course, the lack of atmospheric pressure is going to result in the
water wings expanding, perhaps to the bursting point...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


#81974

FromWilliam Ray Wing <wrw@mac.com>
Date2014-12-04 23:17 -0500
Message-ID<mailman.16606.1417756648.18130.python-list@python.org>
In reply to#81904
> On Dec 4, 2014, at 8:56 PM, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
> 
> On Thu, 04 Dec 2014 14:51:14 +0200, Marko Rauhamaa <marko@pacujo.net>
> declaimed the following:
> 
>> Chris Angelico <rosuav@gmail.com>:
>> 
>>> A lot of programs don't use threads, and therefore cannot have thread
>>> safety problems - or, looking at it the other way, do not care about
>>> thread safetiness. It's like having Neil Armstrong wear water wings to
>>> make sure he won't drown in the Sea of Tranquility.
>> 
>> The water wings would be too unwieldy since they'd have to be six times
>> as large on the moon. It's all about risk/benefit analysis.
> 
> 	Actually, since the pull of gravity is 1/6th that of earth, but the
> density of the "water" is the Sea is the same, the water wings should be
> smaller to provide the same degree of lift.
> 
> 	Of course, the lack of atmospheric pressure is going to result in the
> water wings expanding, perhaps to the bursting point...
> -- 
> 	Wulfraed                 Dennis Lee Bieber         AF6VN
>    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Wrong, again I’m afraid.  Assume for a moment you are under a dome pressurized to one standard atmosphere in some future moon colony and are in a swimming pool.  Both you AND the water are under 1/6th as much gravitational pull.  Neither your density nor the water’s density has changed. Density is a function of the atomic weight of the elements making up both you and the water and the inter-atomic/molecular spacing of those elements.  Neither has changed.  Therefore the volume of buoyant material (in the case of water wings, air) necessary to keep you above water is the same on earth as it would be on the moon.  

-Bill

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


#81939

Fromalister <alister.nospam.ware@ntlworld.com>
Date2014-12-04 19:54 +0000
Message-ID<zZ2gw.31496$yS3.6644@fx24.am4>
In reply to#81873
On Thu, 04 Dec 2014 00:02:25 +0100, Skybuck Flying wrote:

> "Mark Lawrence"  wrote in message
> news:mailman.16534.1417610132.18130.python-list@python.org...
> 
> On 03/12/2014 02:27, Skybuck Flying wrote:
>> Excuse is: "bad programming style".
>>
>> I don't need snot telling me how to program after 20 years of
>> programming experience.
>>
>> This is so far the only thing pissing me off in python.
>>
>> Now I have to declare "global" in front of these variables every where
>> I want to use em:
> 
> "
> Another example of a bad workman always blames his tools.
> "
> 
> Euhm, so why don't you program with just 0 and 1's then ? ;)
> 
> Bye,
>   Skybuck :)

Because I DO know how to use my tools.



-- 
God isn't dead.  He just doesn't want to get involved.

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


#81872

FromPeter Pearson <pkpearson@nowhere.invalid>
Date2014-12-03 20:31 +0000
Message-ID<ce9a99FtjcbU1@mid.individual.net>
In reply to#81824
On Wed, 3 Dec 2014 03:27:45 +0100, Skybuck Flying wrote:
>
> I don't need snot telling me how to program after 20 years of programming 
> experience.
[snip]

After 20 years of programming, I had a lot to learn about programming.
That was 29 years ago, and I *still* have a lot to learn about
programming.  That's why I greatly enjoy this particular newsgroup.

The last time I saw a stack of globals like that was in 1973.  Program
for driving a lathe.  Didn't work.  Best of luck to you.

-- 
To email me, substitute nowhere->runbox, invalid->com.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

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


csiph-web