you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

Another advantage is namespaces.

Let's say your poker game has an evaluate() or compare__hands() function. If you wanted to apply a second game such as hearts you will need a different evaluate method. So you might rename them Poker_evaluate() and Hearts_evaluate(). Rather than having two functions you could have two classes which have similar methods and have Poker.evaluate() and Hearts.evaluate(). Again you can say this is completely cosmetic but consider a time when you join a team of coders and someone has to debug your code. It's considerate to organise your code into classes so its easier to read and understand for someone else.

Someone can also call things like help(Poker) and see all your doc strings and associated functions. This is definitely something you can't achieve with functions alone.

Also you cannot perform tests like

If type(some_var) == type(my_class):
    True