Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81827
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torriem+gmail@torriefamily.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.06; 'patterns.': 0.07; 'strict': 0.07; 'variables': 0.07; 'attributes': 0.09; 'namespace': 0.09; 'overwrite': 0.09; 'python': 0.11; 'def': 0.12; 'suggest': 0.14; '"global"': 0.16; 'cleaner': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'globals': 0.16; 'object()': 0.16; 'objects.': 0.16; 'pep8': 0.16; 'prefixed': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'example': 0.22; 'programming': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'module,': 0.24; 'looks': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:g 30': 0.30; 'flying': 0.31; 'object.': 0.31; 'though.': 0.31; 'front': 0.32; 'maybe': 0.34; 'could': 0.34; 'skip:s 30': 0.35; 'something': 0.35; 'really': 0.36; 'keyword': 0.36; 'module.': 0.36; 'surely': 0.36; 'doing': 0.36; 'should': 0.36; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; "you're": 0.61; 'you.': 0.62; "you've": 0.63; 'kind': 0.63; 'organization': 0.63; 'refer': 0.63; 'telling': 0.64; 'more': 0.64; 'experience.': 0.67; 'everywhere.': 0.84; 'adopt': 0.91 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Tue, 02 Dec 2014 20:13:25 -0700 |
| From | Michael Torrie <torriem@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Python handles globals badly. |
| References | <c3363$547e74fe$5419aafe$24179@news.ziggo.nl> |
| In-Reply-To | <c3363$547e74fe$5419aafe$24179@news.ziggo.nl> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16509.1417576416.18130.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1417576416 news.xs4all.nl 2874 [2001:888:2000:d::a6]:38859 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:81827 |
Show key headers only | View raw
On 12/02/2014 07:27 PM, 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: Only if you want to overwrite them, though. Python has support for any number of programming paradigms. That many global variables is screaming for some kind of organization and Python has good mechanisms for doing this in a much neater way. Might I suggest you use a namespace instead? Put all your "globals" in a module, and refer to them via the module. For example (converting to pep8 which looks better to me): import globals as g def some_func(): g.ship_ability_distribute_shield_power = 5 A whole lot cleaner than trying to use the global keyword everywhere. If you've really been programming for 20 years, surely you're familiar with programming patterns. The fact that you have 6 variables all prefixed with "ShipAbility" should suggest something to you. Like maybe all of these attributes could be encapsulated in one "ship" object. Python is very flexible in how you use objects. You can program in strict java-style if you want, or adopt a more freeform approach: ship = object() ship.ability = object() ship.ability.distribute_shield_power = 5 etc.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web