Thanks everyone for the replies.
On Thu, Jan 16, 2014 at 1:36 AM, Cameron Simpson <c...@zip.com.au> wrote: > On 16Jan2014 15:53, Ben Finney <ben+pyt...@benfinney.id.au> wrote: > > Roy Smith <r...@panix.com> writes: > > > Ben Finney <ben+pyt...@benfinney.id.au> wrote: > > > > Who says it's frowned on to do work in the initialiser? Where are > they > > > > saying it? That seems over-broad, I'd like to read the context of > that > > > > advice. > > > > > > There are some people who advocate that C++ constructors should not do > > > a lot of work and/or should be incapable of throwing exceptions. The > > > pros and cons of that argument are largely C++ specific. […] > > > > Even simpler: They are mistaken in what the constructor is named, in > > Python. > > Python classes have the constructor, ‘__new__’. I would agree with > > advice not to do anything but allocate the resources for a new instance > > in the constructor. [...] > > > > Python instances have an initialiser, ‘__init__’. That function is for > > setting up the specific instance for later use. This is commonly > > over-ridden and many classes define a custom initialiser, which normally > > does some amount of work. > > > > I don't think ‘__init__’ is subject to the conventions of a constructor, > > because *‘__init__’ is not a constructor*. > > 99% of the time this distinction is moot. When I call ClassName(blah,...), > both the constructor and initialiser are called. > > Informally, there's a rule of thumb that making an object (allocate, > construct and initialise) shouldn't be needlessly expensive. Beyond > that, what happens depends on the use patterns. > > This rule of thumb will be what Rita's encountered, perhaps stated > without any qualification regarding what's appropriate. > > Cheers, > -- > Cameron Simpson <c...@zip.com.au> > > The problem with keeping an open mind is that my ideas all tend to fall > out... > - Bill Garrett <garr...@cs.unc.edu> > -- > https://mail.python.org/mailman/listinfo/python-list > -- --- Get your facts first, then you can distort them as you please.--
-- https://mail.python.org/mailman/listinfo/python-list