W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2013

Re: [whatwg] [Notifications] Constructor should not have side effects

From: Stewart Brodie <stewart.brodie@antplc.com>
Date: Tue, 29 Jan 2013 18:07:34 +0000
To: <whatwg@whatwg.org>
Message-ID: <gemini.mhefom00zwv7k072p.stewart.brodie@antplc.com>
Glenn Maynard <glenn@zewt.org> wrote:

> On Tue, Jan 29, 2013 at 7:36 AM, Charles McCathie Nevile <
> chaals@yandex-team.ru> wrote:
> 
> > Really? This doesn't seem like a good idea, so I'd be interested to know
> > why. Is there an explanation laid out somewhere?
> 
> Just to ask from another perspective: why doesn't it seem like a good
> idea?

All the information required to "activate" the object may not be available
at the point at which the object is constructed.

For example, how can you add event listeners to something that doesn't exist
yet?  Particularly if you want to use a closure with the new object.


> Having objects that begin their job when constructed simply avoids an
> extra step for the user (telling it to start), and reduces the number of
> possible states (eg. eliminating the UNSENT state), which generally
> simplifies things. Supporting reuse of objects is generally not a useful
> optimization (in my experience), so not supporting it also simplifies
> things a bit. Reducing the number of different-but-equivalent ways of
> doing the same thing is also generally good API design.

I agree - but I don't see what this has to do with separating construction
from activation.


-- 
Stewart Brodie
Team Leader - ANT Galio Browser
ANT Software Limited
Received on Tuesday, 29 January 2013 18:08:02 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:12 GMT