Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'say,': 0.05; 'think,': 0.07; 'cleanup': 0.09; 'don': 0.09; 'implements': 0.09; 'lines.': 0.09; 'logic': 0.09; 'means,': 0.09; 'subject:How': 0.10; '>on': 0.16; '>the': 0.16; '>to': 0.16; 'definition.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'heap': 0.16; 'imports': 0.16; 'internally': 0.16; 'message-id:@cskk.homeip.net': 0.16; "module's": 0.16; 'needless': 0.16; 'organised': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'terribly': 0.16; 'thinking,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'app': 0.19; 'module': 0.19; 'else,': 0.19; 'first.': 0.19; 'possible,': 0.19; 'thu,': 0.19; 'putting': 0.22; 'header:User-Agent:1': 0.23; 'aspect': 0.24; 'tend': 0.24; 'cheers,': 0.24; 'file.': 0.24; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'function': 0.29; 'wondering': 0.29; 'chris': 0.29; '(like': 0.30; 'along': 0.30; 'code': 0.31; 'usually': 0.31; '13,': 0.31; 'own,': 0.31; 'subject:some': 0.31; "they'll": 0.31; 'file': 0.32; 'probably': 0.32; '(i.e.': 0.33; "i'd": 0.34; 'could': 0.34; 'classes': 0.35; 'one,': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'functions.': 0.36; 'received:com.au': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'nov': 0.38; 'received:211': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'functional': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; "you're": 0.61; 'first': 0.61; 'you.': 0.62; 'content-disposition:inline': 0.62; 'name': 0.63; 'visit': 0.64; 'face': 0.64; 'love': 0.65; 'details': 0.65; 'effective.': 0.68; 'useful.': 0.68; 'etc,': 0.84; 'me;': 0.84; 'routines': 0.84; 'you;': 0.84; 'hate': 0.91 Date: Thu, 13 Nov 2014 19:47:25 +1100 From: Cameron Simpson To: Python Subject: Re: How about some syntactic sugar for " __name__ == '__main__' "? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=dMCfxopb c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=J0QyKEt1u0cA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=pGLkceISAAAA:8 a=XDyFFoVpASJoW-tRMTwA:9 a=CjuIK1q_8ugA:10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415868457 news.xs4all.nl 2970 [2001:888:2000:d::a6]:59967 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80674 On 13Nov2014 19:04, Chris Angelico wrote: >On Thu, Nov 13, 2014 at 6:23 PM, Cameron Simpson wrote: >> Indeed. This aspect is a deal breaker for me; I'd never use it. >> >> I make a point of putting the module's main function right up the top, >> immediately after the imports and any "constants" (let's not dither over >> that term). I _want_ the main function to in the reader's face when they >> visit the module code. All the cogs come later. >> >> And lots of my modules have "main" functions. Terribly useful. > >Hmm, I go the other way. As much as possible, I prefer functions to >call what's above them, not what's below them - so the main function >would always be at the end of the file. [...] My view is that if there's a main (i.e. the module implements a small app all on its own, however tiny), then the main program logic should come first. The details follow later. For a pureply functional module (utility functions, classes built on them, etc) I tend to go your way. But the main, if there is one, comes first. >The very top of the file >should have comments/docstrings etc, then imports, then pure utility >functions that don't call on anything else, then "guts" functions, and >finally routines that are called externally but never internally (like >main). That way, if you're wondering at what some name means, you go >to the top of the file and find the first occurrence; that'll usually >be its definition. Sounds effective. I probably prefer my code (main aside, again) organised the same way. Needless to say, I have a heap of modules that could do with a cleanup along these lines. Cheers, Cameron Simpson If you make people think they're thinking, they'll love you; but if you really make them think, they'll hate you. - Don Marquis