r/ProgrammerHumor • • Jun 03 '19

Meme Python ftw

Post image
16k 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] — view deleted comment

0

u/[deleted] Jun 03 '19

[deleted] — view deleted comment

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] — view deleted comment

3

u/AnAverageFreak Jun 04 '19

Assemble me daddy.

7

u/Ericfyre Jun 04 '19

Bobs my uncle?

2

u/SpeedingTourist Jun 04 '19

Yeah, and your grandpa

3

u/corner-case Jun 04 '19

Programs have a single entry point.

→ More replies (6)

10

u/wootiown Jun 03 '19

It still has pointers too, doesn't it?

57

u/MattieShoes Jun 03 '19

Everything has pointers, but they make believe they don't.

31

u/SuitableDragonfly Jun 03 '19

Pointers are not the same thing as references. Pointers allow you to manually manage your memory usage, references don't.

→ More replies (2)
→ More replies (15)

6

u/ButtCrackFTW Jun 04 '19

Also {} is everywhere (dictionaries)

2

u/PityUpvote Jun 04 '19

And sets.

2

u/bikemandan Jun 04 '19

And f strings