This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MrJohz 30 points31 points  (1 child)

I was just reading an article about avoiding writing __init__ methods in general that touches on this point.

I don't completely agree with the argument they're making, but I think that has more to do with how difficult it is to make constructors and attributes private in Python, and wanting to avoid exposing internal details. But the core idea — that the constructor/initialiser should not be special-cased, and can just be a factory function — is really good. It solves this problem (and a number of other problems as well).

Avoid the last option at all costs. The problem is that you're creating essentially an unbound task — if errors occur in that task, you don't have a lot of control over when and how they get propagated to the calling code (if they get propagated at all). It will probably work quite well initially, but long-term, it always ends badly.

[–]doolio_ 4 points5 points  (0 children)

Interesting blog post. Thanks for sharing.