Re: pbr vs multiple returns
Jason Gade wrote:
>
>
> I can see the argument for multiple returns in some cases but I would rather
> use PBR in this particular case.
>
> Using ooeu syntax:
function pop( sequence * stack )
object tos -- why have a stack that only holds numbers?
tos = stack[$]
stack = stack[1..$-1] -- Matt, does this make a copy or not?
return tos
end function
...
top = pop(my_stack) -- my_stack is actually modified by the pop() function
>
> This makes the most sense to me.
No, it would *not* make a copy with ooeu, which can be a big benefit if
stack is large, and/or you pop a lot.
Just because, if I wanted to do this in eu (i.e., have a generic pop
function) I'd pass an id to pop, and have that be an index into a
sequence that kept all the stacks. Usage is just as easy (although you
couldn't do funky things to the stack--which might or might not be a good
thing--because it'd be hidden from the users) but you wouldn't be as fast.
That might or might not be an issue in this case.
Matt
|
Not Categorized, Please Help
|
|