https://kotlinlang.org logo
Title
y

Youssef Shoaib [MOD]

04/25/2023, 5:52 AM
How would you name a read-only type whose mutable version already has a basic name? Specifically, we have some
VecX
types that are mutable vectors, and I'm struggling to find a name for a new read-only Vector type that they should implement. I'm thinking maybe
ReadOnlyVecX
but it seems to be too long. The issue is that changing the name of
VecX
to
MutableVecX
would be a big change, especially considering that most Vec-based code would be using mutability, while the read-only versions likely will be used to specify that method parameters and results can't be modified. I also thought maybe
VecXVals
could be an apt name since the interface would really only define the `val`s required to represent that vector, but it still doesn't seem elegant enough
e

Emil Kantis

04/25/2023, 5:59 AM
ReadOnlyVecX
or
ImmutableVecX
imo. Its not really that long imo, and IDEs should complete most of it for you anyway.
y

Youssef Shoaib [MOD]

04/25/2023, 6:01 AM
I thought of
ImmutableVecX
but it's misleading because the type won't actually be immutable.
r

Ruckus

04/25/2023, 6:10 AM
Depending on the intended use case of the read only variant, something like
VecXView
could work (or another word like preview, window, copy, etc).
y

Youssef Shoaib [MOD]

04/25/2023, 6:32 AM
Funny that you suggested that. I've been thinking of adding
VecXView
as a way of getting a live-updated vector. The more I think about it, the better the name works. I could then have
VecXMutableView
for the read-write version of that type that basically internally holds a bijection of sorts to convert back and forth. I think I'm gonna go with
VecXView
unless I get an epiphany of a better name. Thank you!
m

mcpiroman

04/25/2023, 8:48 AM
To keep the analogy with stdlib you could make `Vec`and `MutableVec : Vec`(as with
List
and
MutableList
)
e

ephemient

04/26/2023, 1:34 AM
IMO you should pick which bits of
UnmodifiableFoo
 |- MutableFoo
 \- ImmutableFoo
     \- PersistentFoo
you want, and then maybe give a shorter name to the most common one of them
e.g. stdlib only has
UnmodifiableList
(which it calls
List
) and
MutableList
, with `ImmutableList`/`PersistentList` being supplied by
kotlinx.immutable
Scala has
scala.collection.Seq
  |- scala.collection.mutable.Seq
  \- scala.collection.immutable.Seq
which is also a choice you could make