[Python-ideas] Just __main__

Steven D'Aprano steve at pearwood.info
Mon Jun 18 23:26:16 CEST 2012


Andrew McNabb wrote:
> On Mon, Jun 18, 2012 at 12:39:05PM -0700, Bruce Leban wrote:
>> The special value of __name__ and the proposed __main__() function are both
>> a bit magic. However, when I write if __name__ == '__main__' it's at least
>> clear that that if statement *will* be executed. It's just a question of
>> when the condition is true and if I don't know I can find out fairly
>> easily. (As I did the first time I saw it and probably other people on this
>> list did too.) On the other hand, it's not at all obvious that a function
>> named __main__ will be executed automagically.
> 
> Given that C, Java, and numerous other languages automagically execute a
> function called "main", I would argue that a "__main__" function would
> actually be _less_ surprising than "if __name__ == '__main__'" for most
> new Python users.

What makes you think that "most" new users will be experienced in C or Java?

I think it is more likely that the majority of new users will have no 
experience in programming at all, or that their primary experience will be in 
PHP or Javascript.

But we're all just guessing really. I don't think any of us know what 
languages most current Python users came from, let alone what future ones will 
come from.

But as a matter of principle, I would prefer to assume that new users come in 
with as few preconceived ideas as possible, rather than assuming that they 
expect Python to be just like <insert language of choice here>.





-- 
Steven



More information about the Python-ideas mailing list