<story><title>An exploration of why Python doesn&apos;t require a &apos;main&apos; function</title><url>https://utcc.utoronto.ca/~cks/space/blog/python/WhyNoMainFunction</url></story><parent_chain></parent_chain><comment><author>pansa2</author><text>One benefit of using a main function in Python is performance. If you’re doing significant computation at the top-level, it’ll probably run faster if moved into a function.&lt;p&gt;I believe this comes from the fact that local-variable lookup is faster than global-variable lookup - because the former is lookup-by-index and the latter is lookup-by-name.&lt;p&gt;The same is true in Julia: “Any code that is performance critical or being benchmarked should be inside a function.” [0]&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;docs.julialang.org&amp;#x2F;en&amp;#x2F;v1&amp;#x2F;manual&amp;#x2F;performance-tips&amp;#x2F;index.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;docs.julialang.org&amp;#x2F;en&amp;#x2F;v1&amp;#x2F;manual&amp;#x2F;performance-tips&amp;#x2F;ind...&lt;/a&gt;</text></comment>
<story><title>An exploration of why Python doesn&apos;t require a &apos;main&apos; function</title><url>https://utcc.utoronto.ca/~cks/space/blog/python/WhyNoMainFunction</url></story><parent_chain></parent_chain><comment><author>jeffreyrogers</author><text>I always saw Python and similar languages (Perl, Ruby, PHP maybe) as attempts at replacements for complicated shell scripts, so it never seemed odd to me that there was no main function, since a shell script has no main either. It just starts executing at the top.&lt;p&gt;Edit: Just saw that ktpsns and I made pretty much the same comment. I&amp;#x27;ll add that when I learned C I found the idea of a main function so confusing at first. I wanted to know why it had to be called main and not whatever else I wanted it to be. On the plus side, it led to me exploring how compilers and linkers work, which made me understand hardware a lot better.</text></comment>