Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Disclaimer: I know very little about python internals.

There is a "true" main function for the interpreter itself. From the perspective of the operating system and CPU the python code isn't executing, the interpreter is.

But conceptually, the python code probably doesn't have main function. Python code is so far abstracted from how the CPU works that it likely doesn't need one.



Just seems kinda odd to me to distinguish Fortran and Python here, based on how many levels of abstraction there are between the user code and the main function.

How would you place Bash scripts then? Or a JITed language like Julia?


I only mention python because people were asking about it. There are really two unrelated questions here:

1) How does a computer start executing your code? 2) What kind of abstractions does a programming language provide?

Having anything other than a function as a top level most likely implies an abstraction. The second question is pretty much irrelevant when you are talking about interpreted languages. These aren't programs at all from the perspective of the CPU.

JIT is a different story, and one that I know very little about on a technical level. What happens when pypy generates some native code? Does it generate a function and call it? Does it have some other convention? I have no idea.


Python doesn't require you to have anything around a series of statements. Whereas Fortran requires at least one top-level program block. That program is a top-level function, which directly corresponds to MAIN__ in compiled code.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: