Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80672 > unrolled thread

Re: How about some syntactic sugar for " __name__ == '__main__' "?

Started byChris Angelico <rosuav@gmail.com>
First post2014-11-13 19:04 +1100
Last post2014-11-13 19:04 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How about some syntactic sugar for " __name__ == '__main__' "? Chris Angelico <rosuav@gmail.com> - 2014-11-13 19:04 +1100

#80672 — Re: How about some syntactic sugar for " __name__ == '__main__' "?

FromChris Angelico <rosuav@gmail.com>
Date2014-11-13 19:04 +1100
SubjectRe: How about some syntactic sugar for " __name__ == '__main__' "?
Message-ID<mailman.15766.1415865872.18130.python-list@python.org>
On Thu, Nov 13, 2014 at 6:23 PM, Cameron Simpson <cs@zip.com.au> 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. 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. Most people already do this with their imports,
putting them all at the top - I like to go further and make it unusual
for this not to be the case. (Of course, the nature of live projects
and constant editing is that there will be violations of the
principle, and I don't code-churn just to fix it. But that's still the
ideal.)

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web