Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate mutable.Stack #9068

Closed
scabug opened this issue Jan 2, 2015 · 8 comments
Closed

Deprecate mutable.Stack #9068

scabug opened this issue Jan 2, 2015 · 8 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jan 2, 2015

There is just no reason to keep this class, it is only a wrapper around a mutable reference to List. immutable.Stack has already been deprecated (in scala/scala@3cc99d7), to me it looks like it is just an oversight that the mutable variant isn't deprecated as well.

@scabug
Copy link
Author

scabug commented Jan 2, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9068?orig=1
Reporter: @sschaef
Affected Versions: 2.11.4

@scabug
Copy link
Author

scabug commented Jan 2, 2015

@Ichoran said:
I would like to get a sense of the usage in the wild before we decide on deprecation. I would like to, but the cost of leaving it in is not enormous, so if it would be painful I'd want to reconsider. (That said, I don't know why one would want to use this class. Deprecation can be viewed as instruction, I guess.)

@scabug
Copy link
Author

scabug commented Jan 4, 2015

Chris Martin (chris-martin) said (edited on Jan 4, 2015 10:12:56 AM UTC):
Is this about discouraging impurity, or are you saying that you don't think {{mutable.Stack}} adds any value over a var of type List?

If the deprecation instructions would be to rewrite

val stack: collection.mutable.Stack[A] = ???

val x = stack.pop()

stack.push(y)

as

var stack: List[A] = ???

val x = stack.head
stack = stack.tail

stack +:= y

then I think the result is clearly worse.

@scabug
Copy link
Author

scabug commented Jan 4, 2015

@Ichoran said:
[~chris-martin] The specific example you give adds value, but not very much value. And you lose value at the same time. Take for instance

  var stack: List[A] = ???
  stack = prefix ::: stack

You'd think that

  var stack: mutable.Stack[A] = ???
  stack = prefix ++: stack

might work, but you'd be wrong because ++: isn't overridden. (Even +: isn't overridden.) You have to use pushAll instead. And dropWhile? Nope, it defers back to TraversableLike, which makes a new builder and reallocates the tail all over again.

So you are left with a convenience class that looks like it nicely encapsulates mutability, but in fact is full of unexpected performance gotchas because it turns out that to override everything relevant is actually really tedious and difficult to keep straight, especially as the library evolves.

It's better to just be honest about the situation and deprecate it than to try to fix all the problems now and then maintain the fixes every time the library changes.

@scabug
Copy link
Author

scabug commented Jan 4, 2015

Chris Martin (chris-martin) said:
Would it be feasible to deprecate only the inheritance, and let a simpler Stack class survive on its own?

I'd find it rather disheartening if Scala lost its stack as a result of getting lost down rabbit holes like ++: which are so distant from the purpose of a stack.

@scabug
Copy link
Author

scabug commented Jan 4, 2015

@sschaef said:
Java has the Deque interface, you can use that one if you really want a push/pop API.

@scabug
Copy link
Author

scabug commented Jan 19, 2016

@szeiger said:
As discussed in the Scala team meeting, we should deprecate this in 2.12.

@scabug
Copy link
Author

scabug commented Jul 5, 2016

@szeiger said:
PR: scala/scala#5260

@scabug scabug closed this as completed Aug 11, 2016
@scabug scabug added this to the 2.12.0-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants