Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
I take it you're never had a conversation with Brian Goetz. If you had, you'd know exactly where all the fuckery originates.
SomeNone80035dI mean, it's good to have consistent APIs between different data structures, but honestly, all a stack should have is peek(), pop(), and push(), while a deque should have add, remove, and peek operators for either end. Nothing else. I guess KISS was not a working motto for the designers.
Fast-Nop2698435dI'd guesstimate that the reason was to allow the stack to inherit e.g. the copy and realloc methods of vector.
Obviously, that would have better been done with a common base class like "dynamic container" from which both vector and stack would inherit.
However, that didn't work because stack was probably forgotten and only introduced as afterthought. Which is exactly the shocker, to forget an important data structure like the stack in the design.
@Fast-Nop That's what i exactly think of, i mean if you look at how Microsoft does this in C#:
System.Collections.Generic.Stack<T> implements System.Collections.Generic.IEnumerable<T>, and System.Collections.Generic.IReadOnlyCollection<T> and System.Collections.ICollection, and System.Collections.ICollection has only two methods CopyTo() and the inherited GetEnumerator() method from System.Collections.Generic.IEnumerable<T>
In Java, java.util.Stack<T> extends java.util.Vector<T> which implements java.util.List<T> which extends java.util.Collection<T>, and the last interface define all those useless methods, like the development team couldn't abstract anything