r/computerscience • • Aug 05 '25

Why do some programming languages have a "main" function and don't allow top-level statements?

Only language I've used with this design choice is C++ and while I didn't have much issues with it I still wonder why? Wouldn't that make the language more restrictive and difficult to use? What's the thought process behind making a language that requires a main function and not allowing any statements in the global scope?

40 Upvotes

74 comments sorted by

View all comments

Show parent comment

1

u/FarmboyJustice Aug 07 '25

I think you missed the part where this discussion is not about interpreted languages. This discussion. NOT the OP, but THIS discussion. The one you are in right now. Not every comment on every other comment.

1

u/[deleted] Aug 07 '25

It's definitely not though. Only one comment by Ikatz21 brought up compilers. Reread all of the comments in the chain.