Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Actually, leaving out `object` is the preferred convention for Python 3, as they are semantically equivalent. In Python 2, they mean different things, and you generally want to mean `class Name(object):`. Explicit is better than implicit.


Why is this a 'preferred convention' for Python3? Doing this causes a lot of confusion for Python beginners that write code in Python2 (i.e. it causes them to accidentally use old-style classes). A better practice is to add the extra word i.e. 'class ClassName(object):' for both Python2 and Python3 code. This is especially true if you are writing Python tutorials. Since we are going through this Python2 to Python3 transition it is better to minimize the differences in the cases where they don't really matter (i.e. add the extra 'object' word).


It's considered a wart that old style classes even exist in the first place. Classes look way nicer without it.

Imagine having to write `extends Object` for every Java class you make.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: