Closed CeylonMigrationBot closed 9 years ago
[@quintesse] Well for one you can't make one Array.instance()
and Array.toArray()
, you need one for each primitive type + one for objects. The instance()
can be overloaded, but the toArray()
would need to be split into several different methods.
No, because Array is mutable.
So when assigning an array to a sequence we always have to make a copy?
[@ikasiuk]
So when assigning an array to a sequence we always have to make a copy?
No, I think Gavin was referring to the interface, not the mutability of the data.
[@quintesse] If that so, then maybe I didn't explain myself correctly, what if we could erase T[]
to arrays as well? Not getting rid of Array
which would still be necessary to be mutable. But Integer[]
would be erased to int[]
and Foo[]
simply to Foo[]
which would mean that we could directly assign an Array<Integer>
to an Integer[]
and in Java it would just be a simple assignment as well.
[@gavinking]
what if we could erase T[] to arrays as well?
I've always hoped we could do that. I don't see any reason why it should not work.
[@quintesse] BTW what I said about toArray()
is not entirely true, right now it's pretty much a hack, it returns Object
and when we call it the code looks at the actual Java target type and just adds a cast to that type. All this is not handled in the boxing code itself because that doesn't have the real target types, only the Ceylon types, so it had to be moved to some part of the code that did have that information. Not really pretty.
[@ikasiuk] The more I think about @gavinking 's proposal in this thread the more I like it. And perhaps it's really better not to try to force Array
(which after all exists mainly for interop) into Ceylon's scheme for fixed-size collections. That leaves us more flexibility for both the Array
implementation and the design of the collection hierarchy.
But I have one question: shouldn't we disallow non-constant implementations of ConstantList
? Ok, it might be hard to really enforce that in a waterproof way. But conceptually it would make sense to consider all ConstantList
s as constant not just in size and outlaw non-constant implementations. That could have significant advantages and help promote immutability in Ceylon programs.
[@FroMage] Assigning all issues without milestone to M4. Yell if this is wrong.
[@ikasiuk] It is actually not just acceptable if Array
is not a FixedSized
(and instead directly extends List
), it is in fact more correct: we need the Array
class to represent native arrays, but JavaScript arrays are not of fixed size! So it would be tricky to properly represents a JavaScript array by a fixed-sized Array
because native JS code can easily change its size.
[@quintesse] @ikasiuk I think this issue should either be closed, woken up or be turned into a new issue discussing specifics. Moving to M5 for now.
[@tombentley] What's the status of this issue following the changes we've made in M5? Can we close it (opening more specific issues as required)
[@quintesse] Still no comments? Shall we consider it closed then?
[@ikasiuk] Yes, I'm not aware of any open points specifically related to this issue.
[@ikasiuk] Some time ago we completely revised Ceylon's collections model. So perhaps it's time to examine if the result meets our expectations. While trying to do so I have come across a few points that bother me. I am writing them down here so you can hopefully tell me that I'm just too anxious and overcritical :-) Note that I'm not saying the current model isn't good (in fact it's pretty neat), but that doesn't necessarily mean we can't do better.
Complexity and trickery
To properly understand the current collection type hierarchy I actually had to draw a class diagram even though I participated in the discussion that led to it. That's not good: the relation between the basic types like
Collection
,List
,T[]
andArray
should be easy to understand for newcomers. And that's not the case currently. I would not feel comfortable having to explain this part of Ceylon to someone in detail.One thing that's not nice is that a
String
is not aCharacter[]
. While that may be excusable it points to an underlying problem: becauseFixedSized
isof None|Some
it cannot be properly implemented by a single class. That makes the implementation ofArray
andString
a bit complicated. Currently, testing whether aString
isSome
orNone
usingif (is...)
reveals that it is neither [Update: fixed]! Consequentially, the linecauses a
ClassCastException
at runtime [Update: fixed]. Errors like this can probably be fixed but I really don't feel comfortable with the amount of complexity required to integrateArray
andString
into the collection type hierarchy.if (nonempty)
I guess a main reason for introducing
FixedSized
isif (nonempty)
. But I'm beginning to think thatif (nonempty)
is not as useful as I expected: I simply don't need it very often and when I do then in most cases it could better be written as something likeif (exists f=l.first)
. In the remaining cases it's nice but not irreplaceable. Don't get me wrong: in theory I like the idea a lot, it's just practically not as relevant to me as anticipated.Another problem with
if (nonempty)
is that it only applies toFixedSized
s. So you can use it onT[]
,Array
s andString
s, but basically nothing else. In particular, it looks likeT...
will meanIterable<T>
soon. That will obviously be a common way to pass sequences of values to functions, andif (nonempty)
cannot be used on them. The same goes for all mutableList
s as well asSet
s and otherCollection
s.If you write code that uses
if (nonempty)
and thus needs aFixedSized
then you will likely have to convert an input list to aT[]
first at some point. On the other hand if you don't want to require aFixedSized
you'll write code that checks emptiness by other means thanif (nonempty)
. This means a certain dualism, a bit like between arrays and lists in Java. I always disliked that in Java and had hoped we could get rid of it in Ceylon because I think it adds unnecessary complexity. A list of things should always basically look the same, and be handled in the same way. Consistency makes the language easier to learn and increases the readability of the code.Comparing if (nonempty) to iteration
A good example of a mechanism where this works great is iteration: we can write
for (x in l)
for almost anything. So if we need something likeif (nonempty)
then why doesn't it work as universally as iteration? One might answer that this is because the sequence in question must have a fixed size, so that its size cannot change inside theif
block. But the same problem exists with iterators: an iterator typically throws aConcurrentModificationException
if the underlying sequence is modified during iteration. So if we wanted to be safe we would have to restrict iterators to immutable, or at least fixed-sized, sequences. But we don't do that because it would be much too impractical.Isn't it similarly impractical for
if (nonempty)
? So perhapsif (nonempty ne=l)
should rather be equivalent to something likeif (exists ne=l.nonEmpty)
, withnonEmpty
returning some kind of non-empty view of the sequence. Modification of the sequence would then be disallowed inside theif
block, exactly analogous to iteration.[Migrated from ceylon/ceylon.language#78] [Closed at 2013-03-11 19:54:29]