On 5/10/06 6:03 PM, Jesse Brown wrote:
> Re: the scalar context return value - IS it available elsewhere? (the number
> of items added in that call) - total number of items, yes, but new ones?

Yeah, because you're making the call! :)  Example:

    $o->add_widgets(@widgets); # $count = @widgets

    $o->add_widgets({ ... }, { ... }); # $count == 2

>> * Return a reference to an array of added objects
>> * Return the first added object.
>> 
>> Hm, I'm not sure I like those much either.  What I'm worried about is this:
>> 
>>    $widget = $o->add_widgets($some_widget);
>> 
>> The only way that works is if add_widgets() returns the first added
>> object when called in scalar context.  But that's a pretty odd
>> behavior.  Opinions?
> 
> I agree on the last one being odd (though somewhat DWYIM?). Doing my ($widget)
> = $o->add_widgets(etc), seems to make enough sense?

That's too subtle, IMO.  I constantly forget to add the parens when I use
APIs like that.  It annoys me :)

> # Do some thing that MIGHT collect a bunch of new widgets
> my @widgets;
> 
> if ( ! $o->add_widget(@widgets) ) {
> die "No widgets added! (none found?)";
> }

It's silly not to write that more directly:

    # Do some thing that MIGHT collect a bunch of new widgets
    my @widgets = ... ;

    if(@widgets) { $o->add_widget(@widgets) }
    else         { die "No widgets found"   }

> Of course I'm not saying doing it that way is SANE (should always see if you
> have widgets to add first before trying to add them), but it seems that you
> would want to either raise a fatal exception (probably not?), or return false.

If the add_* method returned the items added, or an empty list if no items
were added, then it'd work out okay.  The only odd part is returning the
first item added when called in scalar context (to avoid requiring the
parens around the lvalue).  But maybe that's not worthwhile.  After all, the
method name is plural: add_...s().

I'll think about it a bit more...

-John




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to