[Python-ideas] start, test, init

spir denis.spir at gmail.com
Mon Dec 2 13:35:31 CET 2013


On 12/01/2013 09:32 PM, Ron Adam wrote:
>
>
> On 12/01/2013 06:45 AM, spir wrote:
>> # __main__ = start
>> def start (args):
>>      init()
>>      # process args
>>      ...
>>
>>
>> What do you think? (bis)
>
> I think you are describing good programming practices for larger modules. And I
> think most people who have been programming in python for any length of time
> develop some form of what you are describing.
>
> The only difference is that they wouldn't need the conditional logic at the
> bottom of the module.  But that also serves as bit of self documentation as to
> what the module or script does, is more flexible, and only adds a line or two if
> the rest is put into functions or classes.
>
>
> As for the testing case... I'd like for python to have a -t option that only
> sets a global name __test__ to True.  Then that covers most of your use cases
> without adding a whole lot.  Sometimes less is more.
>
>     if __test__:
>         test()
>     elif __name__ == '__main__':
>         main()
>
> That's just one possible combination of using __test__ and __name__.

That is all right, in my view; except maybe the point on flexibility (the 
solution of std func names is highly flexible). However, this does not address 2 
related issues:
* Why has the idiom "(el)if __name__ == '__main__':" has to be that obscure? and 
involve unnecessary knwoledge of Python arcanes (for a newcomer)
* Having a std (albeit not required) high-level software structure is a net gain 
for the community of Python programmers (instead of everyone doing their own 
way... when they do).

Denis


More information about the Python-ideas mailing list