placeybordeaux
placeybordeaux

Reputation: 2216

What are the tradeoffs, besides being more or less functional, in using a var List or val mutable.List

I understand that the functional style prefers var or val List of a mutable, and I understand why, but I am thinking about purely time/space trade offs.

I am currently interfacing with a java library and have to write tons of non idomatic code in scala anyways..

Upvotes: 0

Views: 136

Answers (2)

tgr
tgr

Reputation: 3608

In my oppinon the greatest use of immutable List is, that there are no side-effects if you share them between objects. This is important if you start using concurency or even parrallelism.

By the way: Scala uses Builder to change existing Lists and 'recycles' the former List, so this is not as expensive as you might expect it to be.

Edit

As I got you now to get benchmarks I found this one verry good, because they show the code they used.

Upvotes: 2

Nicolas
Nicolas

Reputation: 24769

Maybe several pointers can help you to understand, why there is not a so big penalty when you use immutable structure:

Upvotes: 3

Related Questions