Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16405
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Total newbie question: Best practice |
| Date | 2011-11-29 21:12 +0000 |
| Organization | Norwich University |
| Message-ID | <9jl06gFg9oU1@mid.individual.net> (permalink) |
| References | <jb3e06$37h$1@dont-email.me> <mailman.3134.1322598844.27778.python-list@python.org> |
On 2011-11-29, Arnaud Delobelle <arnodel@gmail.com> wrote: > As for the main() function, I don't think it is standard > practice in Python. There is no requirement to have a main() > function. You can use the idiom: I don't start off with a main function, but if my script gets long and complicated, or if global names have proliferated and have become confusing, I'll refactor the whole thing into functions, including a "main". With most globals moved into main's namespace, calling subroutines from main forces me to define the context that's actually necessary for each part of the program. The resultant refactored programs are much easier to test, read and maintain. TLDR: "Called-only-once" functions like main are useful as documentation, hooks for testing, and for unraveling a snarl of global variables. -- Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Total newbie question: Best practice Colin Higwell <colinh@somewhere.invalid> - 2011-11-29 20:06 +0000
Re: Total newbie question: Best practice Arnaud Delobelle <arnodel@gmail.com> - 2011-11-29 20:34 +0000
Re: Total newbie question: Best practice Neil Cerutti <neilc@norwich.edu> - 2011-11-29 21:12 +0000
Re: Total newbie question: Best practice Chris Angelico <rosuav@gmail.com> - 2011-11-30 07:36 +1100
Re: Total newbie question: Best practice Dave Angel <d@davea.name> - 2011-11-29 16:57 -0500
Re: Total newbie question: Best practice Colin Higwell <colinh@somewhere.invalid> - 2011-11-29 23:08 +0000
RE: Total newbie question: Best practice Shambhu Rajak <Shambhu.Rajak@kpitcummins.com> - 2011-11-30 08:50 +0000
Re: Total newbie question: Best practice "Pedro Henrique G. Souto" <pedro.h.souto@gmail.com> - 2011-11-30 09:36 -0200
csiph-web