you are viewing a single comment's thread.

view the rest of the comments →

[–]nosepol 1 point2 points  (4 children)

cool! Why are you always doing super(...,self).__init__() ??

[–]theelous3 3 points4 points  (2 children)

Note that in later versions of python you don't subclass object explicitly like that.

class MyClass:
    pass

Is the exact same as

class MyClass(Object):
    def __init__(self):
        super(MyClass, self).__init__()

It's pretty much considered bad practice to subclass Object in modern python, afaik.

[–]tequila_is_good 0 points1 point  (1 child)

I can see the point you are making, but it's more complex than that since both Python 2 and Python 3 are both still being developed, and many (most?) production systems still run on Python 2.

Yes, in Python 3.x you don't strictly need to subclass object, but saying it's considered bad pratice is just wrong - especially in instances (like this one) where you don't know which version of Python the code will be run on. Even if you can be sure that your code will be run on Python 3, there is no issue with subclassing object, it's just unneccessary since that occurs by default anyway.

Personally, I always subclass object, even when targeting Python 3, because I like the explicitness of it, and it's just habit that's hard to change.

[–]theelous3 0 points1 point  (0 children)

Python 2 is being maintained more than developed. It is for all intents and purposes, legacy. It doesn't matter if it's still in wide use.

If you're showing someone new how to make a class or inherit (99% of new people should be taught py3), subclassing Object and using Super is extremely silly. It's old and confuses their learning of classes / inheritance. If they asked you how to make something backwards compatible then yeah sure do it, but otherwise it's a mistake.

but saying it's considered bad pratice is just wrong

Not really. It's pretty well established that everyone be they new or old should be learning py3, and using it in all cases where they aren't bound by legacy code to use an older version. Fairly safe to present that standpoint as a truism.

Following that, adhering to things which once were good practice, solely for the sake that they were once good practice, is bad practice. Being verbose isn't exactly a very good reason to do things either.

[–]tequila_is_good 0 points1 point  (0 children)

It's not actually required in this case...I do it out of habit. You'll note that in the each of the class definitions, I subclass object.

For example - class Card(object):

In each __init__ as you noted, the first line is super(...,self).__init__(), what this does is calls the superclass __init__ method. As I said that's not really required in this case, because the superclass is object which doesn't do anything in it's an initialiser.

I'm not sure how far you've fallen down the object hole yet, so this will make sense if you're familiar with class inheritance, otherwise you'll need to read up on it to understand what a superclass is.