Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't think I like this choice of identifiers. It is conventional to start class names with an uppercase letter, so you'd think that you could say <code>isinstance(x, Event)</code>, but you can't. I think a name such as <code>make_event</code> that unambiguously identifies the function as a function would have been better.</p> <p>This issue has already been <a href="http://mail.python.org/pipermail/python-dev/2008-September/082117.html" rel="nofollow">discussed</a> on the mailing list, where the BDFL <a href="http://mail.python.org/pipermail/python-dev/2008-September/082144.html" rel="nofollow">states</a>:</p> <blockquote> <p>This started out as an experiment in API design, where I tried to make things look as much like the similar Java API as possible (I didn't want to invent yet anotherwobbly wheel). I specifically wanted these <em>not</em> to be classes so that people wouldn't start subclassing them. At the time PEP-8 wasn't well established (if at all) and I wanted the factory functions to look like classes. I think in 2.7 / 3.1 we can change the factory functions to conform to PEP-8 (leaving the old names in for a couple of release).</p> </blockquote> <p>The change he mentioned hasn't been done yet, but I think it's pretty safe to say that nowadays the naming scheme is seen as misguided and should not be proliferated.</p> <p>You're right when you say that these factory functions were introduced to mimic a sealed class. The BDFL <a href="http://mail.python.org/pipermail/python-dev/2008-September/082186.html" rel="nofollow">says</a></p> <blockquote> <p>Allowing them to be subclassed makes it harder to replace them on some platforms with equivalent but faster implementations.</p> </blockquote> <p>I don't think this scheme is too common. Most of the time, there is no incentive to replace classes with equivalent implementations, and if a class is not designed for subclassing, you can mention that in the documentation.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload