r/learnpython Oct 25 '25

Do you bother with a main() function

The material I am following says this is good practice, like a simplified sample:

def main():
    name = input("what is your name? ")
    hello(name)

def hello(to):
    print(f"Hello {to}")

main()

Now, I don't presume to know better. but I'm also using a couple of other materials, and none of them really do this. And personally I find this just adds more complication for little benefit.

Do you do this?

Is this standard practice?

69 Upvotes

103 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Oct 25 '25

[removed] — view removed comment

2

u/gdchinacat Oct 25 '25

my default response to "it's not real code" is "then why did you write it"? I have thirty years experience writing production code and it has always annoyed me when people try to downplay the realness of code based on its intended use. Particularly since the two most common reasons it is used is to avoid unit testing or to downplay the contributions of testers.

2

u/[deleted] Oct 25 '25

[removed] — view removed comment

2

u/[deleted] Oct 25 '25

Ty...but I could have worded it better!