Skip to main content
gamedev.net
🔒 Locked

Two Python questions

Started by Daniel Miller Oct 13, 2005 at 11:40 PM 6 replies 500+ views
Original Post
Daniel Miller
Daniel Miller
1. Could you explain why most python programs check __main__ instead of simply calling main() (or even having a main() at all)? 2. Is it considered bad to use tuples instead of classes (for points, rects, etc.)?
Roboguy
Roboguy
Quote:
Original post by Daniel Miller
1. Could you explain why most python programs check __main__ instead of simply calling main() (or even having a main() at all)?

Do you mean the if __name__ == '__main__' thing? That's to check if it's being loaded as a module or executed.
Quote:

2. Is it considered bad to use tuples instead of classes (for points, rects, etc.)?


I would say yes.
Oluseyi
Oluseyi
Quote:
Original post by Daniel Miller
1. Could you explain why most python programs check __main__ instead of simply calling main() (or even having a main() at all)?

Python executes top-down, beginning at the top of the file. Unlike in C, C++, C# and Java, main isn't a predefined symbol in Python; it has no special significance. The only way to determine that the current module is the execution entry point is to test the module name, which is set to __main__.

Quote:
2. Is it considered bad to use tuples instead of classes (for points, rects, etc.)?

Unequivocally.
Roboguy
Roboguy
Quote:
Original post by Anonymous Poster
Quote:
Original post by Roboguy
If it's a class, you can easily add methods to operate on the point.


It's called over-engineering.


Assuming you are referring to creating a class for that:
Most likely, the methods will be something you'd create anyway to operate on the tuples (such as finding the distance between two points, etc) except if you made a class for it it would be (generally) more organized since you could see which functions operate on which type of data.
Daniel Miller
Daniel Miller
Okay, thanks everyone for your answers. :) I agree completely on the second point (I come from C#/C++). I asked because seemed that pygame used tuples for points, and it stuck out to me.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.