commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <>
Subject Re: [digester][PROPOSAL] named stacks
Date Mon, 08 Mar 2004 21:37:44 GMT
On 8 Mar 2004, at 03:20, Martin Cooper wrote:
> On Mon, 1 Mar 2004, robert burrell donkin wrote:
>> On 28 Feb 2004, at 20:06, Martin Cooper wrote:


>>> * Wouldn't you want to throw an exception if someone tries to pop a
>>> value
>>> off an empty or non-existent stack? You didn't specify the behaviour
>>> below, but I'm assuming that you're currently planning on returning
>>> null
>>> in those circumstances?
>> this is a bit of a moot point, i'd say. i'd prefer to return null but
>> the current behaviour (for the existing stack) is (i think) throwing a
>> exception. my feeling is that the exception is really being used for
>> control flow which (i'd say) is a bit wrong.
>> any particular reason why you'd want an exception to be thrown? (i'd 
>> be
>> willing to persuaded that an exception is better.)
> Well, it would seem to me that attempting to pop an item off an empty
> stack is an error in the first place, so an exception seems 
> appropriate.
> Consistency with the default stack also seems like a good thing.

in some ways, this is a tough call.

throwing exceptions would make the API more complex and harder to use 
(due to the additional cases). in this case, i'd say that an 
EmptyStackException would have to be thrown when the stack is empty of 
when nothing has ever been pushed onto that stack. an appropriate 
isEmpty method would also need to be added.

on the other hand, ArrayStack's do accept null's. i had originally 
thought that it'd be better not to allow named stacks to accept null 
and this would allow null to be returned when nothing had been pushed 
onto the stack. but consistency is important and i'd also like named 
stacks to be used interchangeable with the main stacks, maybe even 
giving the main stacks names.

i really prefer not accepting nulls and returning null when there's 
nothing on the stack but i'm now coming round to your point of view 
that maybe consistency is more important.

- robert

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message