[Python-Dev] class Foo(object) vs class Foo: should be clearly explained in python 2 and 3 doc
Chris Angelico
rosuav at gmail.com
Sun Aug 10 03:01:17 CEST 2014
On Sun, Aug 10, 2014 at 10:44 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Looking at your comment here:
>
>> [1]: https://news.ycombinator.com/item?id=8154471
>
> there is a reply from zeckalpha, who says:
>
> "Actually, leaving out `object` is the preferred convention for
> Python 3, as they are semantically equivalent."
>
> How does (s)he justify this claim?
>
> "Explicit is better than implicit."
>
> which is not logical. If you leave out `object`, that's implicit, not
> explicit.
The justification is illogical. However, I personally believe
boilerplate should be omitted where possible; that's why we have a
whole lot of things that "just work". Why does Python not have
explicit boolification for if/while checks? REXX does (if you try to
use anything else, you get a run-time error "Logical value not 0 or
1"), and that's more explicit - Python could require you to write "if
bool(x)" for the case where you actually want the truthiness magic, to
distinguish from "if x is not None" etc. But that's unnecessary
boilerplate. Python could have required explicit nonlocal declarations
for all names used in closures, but that's unhelpful too. Python
strives to eliminate that kind of thing.
So, my view would be: Py3-only tutorials can and probably should omit
it, for the same reason that we don't advise piles of __future__
directives. You can always add stuff later for coping with Py2+Py3
execution; chances are any non-trivial code will have much bigger
issues than accidentally making an old-style class.
ChrisA
More information about the Python-Dev
mailing list