You are not logged in.

#1 2005-06-26 08:43:17

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

global variables in python

I used to do some web development in PHP and it was always a general rule that global variables were bad. This was in an environment that has a lot of data coming from an outside source etc. In a Python script I'm working on at the moment I've got a few objects which all need access to the same 3 tuples. I realise I could pass them to each of the objects for use without many dramas but are globals still evil? It's a simple script that uses Evas to draw some stuff and the only outside data coming into play will be from MPD, should I be concerned and pass the variables or is the easy way out okay here?

Thanks for any opinions on this smile

Offline

#2 2005-06-26 08:57:22

sweiss
Member
Registered: 2004-02-16
Posts: 635

Re: global variables in python

I think global variables are said bad for the coder himself. If you could deal with it then it's alright. What I would do if I were you is creating a class with the tuples as its members, and then passing an object of that class to the objects.

Maybe that's a prettier way of doing what you wish.

Offline

#3 2005-06-26 09:05:37

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: global variables in python

As long as you make sure you don't have any race conditions involving the global, and you aren't cluttering up your namespace needlessly, I don't see why it would be a problem.

Now, 'register globals'..that is the php evil, and might be what you were thinking of.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#4 2005-06-26 10:28:16

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Re: global variables in python

sweiss wrote:

I think global variables are said bad for the coder himself. If you could deal with it then it's alright. What I would do if I were you is creating a class with the tuples as its members, and then passing an object of that class to the objects.

Maybe that's a prettier way of doing what you wish.

Yeah that's not bad actually, I just didn't really want to pass the exact same  3 objects around which looks cluttered but one isn't so bad smile

Offline

#5 2005-06-27 14:54:15

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: global variables in python

make a "config" class which has the tuples as members... I can't recall how you make a a class "static" though...

Offline

#6 2005-06-27 14:56:48

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: global variables in python

Hehehe!! This is Python, not OOP!!!

IIRC, you don't make static classes in Python. You use modules! Python is Way Cooler than OOP.

(Diehard Java Programmer here, eh?)

Dusty

Offline

#7 2005-06-27 20:49:27

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: global variables in python

use the globals cam,
just make sure that the names are long and ugly,


arch + gentoo + initng + python = enlisy

Offline

#8 2005-06-27 21:11:51

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: global variables in python

hahah, nice signature!
the phrakWM team is still considers the code pre-alpha (and I actually just removed a big chunck to redesign it)

Offline

#9 2005-06-27 21:46:40

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: global variables in python

Don't leave me out. I am the unofficial head of finding a decent name for phrakWM. I think I deserve voting privleges!

Dusty

Offline

#10 2005-06-27 21:50:29

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: global variables in python

phrakture wrote:

hahah, nice signature!
the phrakWM team is still considers the code pre-alpha (and I actually just removed a big chunck to redesign it)

just take your time phrakture, compared to the speed of which enlightenment  is developed you probably are faster,


arch + gentoo + initng + python = enlisy

Offline

#11 2005-06-27 21:51:41

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: global variables in python

I seriously debated "phrik" for a while, just because it sounded nifty...

oh and, by the way, HIJACK!

Offline

#12 2005-06-27 21:54:47

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Offline

#13 2005-06-27 23:33:51

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Re: global variables in python

Oi phrik is pretty cool, vote++

Offline

#14 2005-06-28 00:25:20

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: global variables in python

I think you should call it "hijack"


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#15 2005-06-28 15:44:07

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: global variables in python

or cacti

Offline

#16 2005-06-28 15:49:26

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: global variables in python

maybe cactiph.

The window manager with a lisp.

Only, it plays on three prominent names here -- cactus, phrakture, and iphitus. So that's cool.

Phrames?
Phrodo?
Phink?

Jingo?
Ridcully?
Vetinari?
Atuan?

Offline

#17 2005-06-28 16:15:23

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: global variables in python

Jigalo
NotEnsmer
BitHatWm
I-am-in-charge-wm
Dance of a thousand orangutans.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#18 2005-06-28 16:17:14

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: global variables in python

Whatever else, it should NOT(!!!) have wm in the title.

Dusty

Offline

#19 2005-06-28 16:25:07

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: global variables in python

iPhusty? sounds like something made by apple

Offline

#20 2005-06-28 18:54:49

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: global variables in python

iPhusty...
iPhustyWM.

:twisted:


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#21 2005-06-28 19:35:08

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: global variables in python

Cactus, what is it you have against me?

Offline

#22 2005-06-28 19:43:34

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: global variables in python

what's wrong with phrakwm?
or maybe phrak with a number like phrak42 or something,


arch + gentoo + initng + python = enlisy

Offline

#23 2005-06-28 23:03:23

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: global variables in python

Dusty wrote:

Cactus, what is it you have against me?

?
Nothing. Apparently I once again failed at being midly humerous.
*sigh*


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

Board footer

Powered by FluxBB