On Mon, Aug 04, 2003 at 10:10:54AM -0400, John Siracusa wrote:
> 
> Does it need to do that?  I mean, sure, eventually it might have to do that
> if I want to do some sort of date manipulation, or even just fetch or print
> the date.  But does it have to really do anything at all during object
> construction other than stash the args somewhere?
[...]
> What about what I mentioned earlier: lazy (or "lazier") evaluation in the
> constructor?  Basically, I want construction with known values to be as fast
> as possible since there's a chance I may not even look at the date fields of
> my objects.  But it's a hassle to have special-case code that either doesn't
> fetch or doesn't set the date fields of my objects, just so I can avoid the
> relatively expansive calls to DateTime->new()

Why not make your module be lazy about whether or not it creates a
DateTime?  It seems to me that 99% of the time you want to do more
than simply create a date and not do anything else with it, in which
case you need to parse the date sometime.  Since making DateTime lazy
will probably mean extra cost (in terms of overall CPU usage and
complexity) it seems like this is not a useful tradeoff.

Also, you may not be able to validate the arguments without doing some
of the processing and deferring a potential error until later seems
like it would lead to confusion.

-ben

Reply via email to