bytes-java icon indicating copy to clipboard operation
bytes-java copied to clipboard

Rethink type system: Mutable vs Immutable

Open patrickfav opened this issue 6 years ago • 2 comments

Currently the default type is described as "immutable" but in realty it's just a "copy-on-write" instance.

It would make more sense if the default instance is mutable, with wrapper to make it immutable.

patrickfav avatar Jan 12 '19 19:01 patrickfav

If purpose is performance, then mutability is important. If purpose is functional style, then it is easier to work with immutable data.

petrukhnov avatar Mar 07 '19 09:03 petrukhnov

The idea is to be mutable by default, as most simple use cases do not use Bytes as a type system (me guessing) - so you have the performance benefit without thinking about it. If, on the other hand, Bytes is used in APIs it would make sense to offer immutable types so an API may choose to protect it's internal arrays.

Im in the middle of the rewrite, but it is sometimes not easy to support both while having the some out-facing API.

patrickfav avatar Mar 07 '19 10:03 patrickfav