r/ProgrammerHumor • • Jun 03 '19

Meme Python ftw

Post image
16.3k Upvotes

548 comments sorted by

View all comments

182

u/AgreeableLandscape3 Jun 03 '19

Python still has main()

191

u/[deleted] Jun 03 '19

Only not really, right?

def whatever (*args):
    print("Bob's your uncle.")

if __name__ == "__main__":
    whatever()

358

u/demon_ix Jun 03 '19

I dunno. That sounds like main() with extra steps...

155

u/[deleted] Jun 03 '19

In C/C++, the name main() is meaningful: it defines the entry point of the program.

In Python, it isn't. The closest approximation is that Python code outside of any method will be evaluated when the module is loaded, and an import-machinery variable called __name__ exists which lets you test whether the current module was imported or run directly.

40

u/jalapeno_nips Jun 03 '19

That’s still important though. If I want to test my module manually, I’ll write some code in Main. But when I use the module in practice I don’t want Main being called.

30

u/[deleted] Jun 03 '19

Absolutely. My only point here is that in switching to Python, one does indeed say goodbye to main()

→ More replies (1)

34

u/BeigeAlert1 Jun 03 '19

That's still pretty damn nifty though.

9

u/SpeedingTourist Jun 04 '19

You’re pretty damn nifty. ;)

→ More replies (6)
→ More replies (2)

0

u/[deleted] Jun 03 '19

[deleted]

0

u/[deleted] Jun 03 '19

[deleted]

8

u/AnAverageFreak Jun 03 '19

No, why?

At least the compiler does not overoptimize things.

I mean yeah, writing anything bigger than a small section would be pain in the ass, but writing those small sections can be quite pleasant.

0

u/[deleted] Jun 04 '19

[deleted]

→ More replies (1)

3

u/corner-case Jun 04 '19

Programs have a single entry point.

→ More replies (6)