You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by sai pabbathi <sa...@gmail.com> on 2012/02/24 17:14:10 UTC

[IDEAS] Collections and Generics

Hello All,

I've been thinking about creating my own version of collections and
Generics for a while now. I'm a java guy and I crave to have Collections on
the client side. Having the collections and generics would not hurt, it
would actually reduce the coding errors, and development time as most of
the time we will be working around the data in any type of application.
Some times I have to run the application to know the type of data that is
in the ArrayCollection, even though flex provides 'Vector' as way to
introduce generics into flex, it is not as powerful as the ArrayCollection,
and not many are aware of its existence.

Also having a good set of collections like Map, Set, List, Queues would
help develop more robust client side applications.

P:S: I'm unaware if adobe has already planned to roll out collections in
the near future. Its just an Idea!

-- 
  Sai Pabbathi
  ACE 4.0
  SCJP 5.0

Re: [IDEAS] Collections and Generics

Posted by Left Right <ol...@gmail.com>.
> In other words: haXe's generics are "compile-time" checks not runtime
safe.

Same as Java, Same as C++. Of course, that doesn't mean it is good... but
the runtime wasn't built having those things in mind, because you cannot
affect the runtime, that's the only thing you can do.

But, if to be honest, generics mean something entirely different. In an
interesting way, what Adobe posted as a roadmap for AS evolution speaks
about actual generics, but, I'm guessing it will take several years before
we hear about that.

Vector in AS3, strictly speaking, isn't a generic, it's a class created
from template. This is, in a plain talk "generic", but not so per exact
definition of the term. "Generic" is usually applicable in system with
multiple dispatch, when arguments combinations are considered. I.e.

(defgeneric combine (a b)
  (:documentation "Combines strings and integers"))

(defmethod combine ((a string) (b integer))
  (concatenate 'string a (write-to-string b)))

(defmethod combine ((a integer) (b string))
  (concatenate 'string (write-to-string a) b))

would be an illustration of what it actually means. I.e. you define a
generic method, and then you define specializations of the method. Or, in
some other languages the declaration of generic itself is implied, and it
is created as soon as any methods are found.

Or, if you consider a more modern language - HaXe, then any variable, or
function argument that you did not type explicitly is generic, because it
will accept any type, which is suitable in the context you provided.

As it happens with vectors, you can only use a particular method derived
from a generic template, but you don't do generic programming per se. That
part has been done for you by the template generator.

Re: [IDEAS] Collections and Generics

Posted by Martin Heidegger <mh...@leichtgewicht.at>.
On 25/02/2012 02:14, Omar Gonzalez wrote:
> I didn't understand that statement either.
> Martin, what did you mean by that?

I meant that it is converted to "Object" at compile time. Check the 
bytecode of the attached swc. Was shocked when I first saw that! ;)
In other words: haXe's generics are "compile-time" checks not runtime safe.

yours
Martin.

Re: [IDEAS] Collections and Generics

Posted by Omar Gonzalez <om...@gmail.com>.
On Fri, Feb 24, 2012 at 9:13 AM, David Arno <da...@davidarno.org> wrote:

> > From: Martin Heidegger [mailto:mh@leichtgewicht.at]
> > Sent: 24 February 2012 16:57
> > Hello David,
> >
> > I guess you don't want to know how haXe implements generics for avm
> bytecode.
> I'm puzzled as to why you assume this to be honest.
>
> David.
>
> I didn't understand that statement either.

Martin, what did you mean by that?

--
Omar Gonzalez
s9tpepper@apache.org
Apache Flex PPMC Member

RE: [IDEAS] Collections and Generics

Posted by David Arno <da...@davidarno.org>.
> From: Martin Heidegger [mailto:mh@leichtgewicht.at] 
> Sent: 24 February 2012 16:57
> Hello David,
>
> I guess you don't want to know how haXe implements generics for avm
bytecode.
I'm puzzled as to why you assume this to be honest.

David.


Re: [IDEAS] Collections and Generics

Posted by Martin Heidegger <mh...@leichtgewicht.at>.
Hello David,

I guess you don't want to know how haXe implements generics for avm 
bytecode.

yours
Martin.

RE: [IDEAS] Collections and Generics

Posted by David Arno <da...@davidarno.org>.
> From: Martin Heidegger [mailto:mh@leichtgewicht.at] 
> Sent: 24 February 2012 16:51
> ActionScript3 does not support generics. 

That's not strictly speaking true. AS3 supports the Vector class after all,
which is a generic class. It understands instantiating an instance of a
generic class. However the language doesn't (yet) have the syntax to support
defining generic classes and - even if it did - the mxmlc compiler is
hard-coded to only handle generics via the Vector class. The AVM2 definitely
supports generics, which is why haXe can use generics to target SWFs.

David.



Re: [IDEAS] Collections and Generics

Posted by Martin Heidegger <mh...@leichtgewicht.at>.
Hello Sai,

ActionScript3 does not support generics. You will not be able to
create new "well-performing" basic types like Array. There are many 
approaches
around like as3commons[1], as3-collections[2], addicted2flash [3] or 
Maashaack [4] but the
performance is not really good.

I once developed a generic Linked List with performance in mind but its 
rather difficult to really use [1]

Things like Omars VectorList might be useful but I think that is 
different from what you are talking about - right?

yours
Martin.

[1] 
http://code.google.com/p/as3-commons/source/browse/trunk#trunk%2Fas3-commons-collections%2Fsrc%2Fmain%2Factionscript%2Forg%2Fas3commons%2Fcollections
[2] http://code.google.com/p/as3-collections/
[4]http://code.google.com/p/maashaack/source/browse/#svn%2Ftrunk%2FAS3%2Fsrc%2Fsystem%2Fdata
[3] 
http://code.google.com/p/addicted2flash/source/browse/#svn%2Ftrunk%2Fsrc%2Fcom%2Faddicted2flash%2Futil
[4] http://nanosome.org/util/latest/index.html#nanosome/util/list/List.html

On 25/02/2012 01:14, sai pabbathi wrote:
> Hello All,
>
> I've been thinking about creating my own version of collections and
> Generics for a while now. I'm a java guy and I crave to have Collections on
> the client side. Having the collections and generics would not hurt, it
> would actually reduce the coding errors, and development time as most of
> the time we will be working around the data in any type of application.
> Some times I have to run the application to know the type of data that is
> in the ArrayCollection, even though flex provides 'Vector' as way to
> introduce generics into flex, it is not as powerful as the ArrayCollection,
> and not many are aware of its existence.
>
> Also having a good set of collections like Map, Set, List, Queues would
> help develop more robust client side applications.
>
> P:S: I'm unaware if adobe has already planned to roll out collections in
> the near future. Its just an Idea!
>


Re: [IDEAS] Collections and Generics

Posted by Roland Zwaga <ro...@stackandheap.com>.
>
> Also having a good set of collections like Map, Set, List, Queues would
> help develop more robust client side applications.
>
> P:S: I'm unaware if adobe has already planned to roll out collections in
> the near future. Its just an Idea!
>

AS3Commons also offers quite an extensive number of collection classes:

http://as3commons.org/as3-commons-collections/index.html

cheers,

Roland

Re: [IDEAS] Collections and Generics

Posted by Martin Heidegger <mh...@leichtgewicht.at>.
On 25/02/2012 03:11, Gordon Smith wrote:
>> hopefully generics will be supported by the Falcon compiler.
> Unfortunately, they won't be, at least not in the first release. We're just working on compiling the existing language faster and in less memory.
>
> As discussed in the recent Flash Runtime whitepaper, Adobe plans to evolve the language, but primarily to help with the company's new gaming and video initiative. Whether generics are part of that future hasn't been decided yet.
>
> Also, whether Adobe will continue to contribute to Apache future compiler changes to support new language features seems unclear at the moment. I haven't seen anybody write anything about that, and it probably hasn't gotten a lot of thought yet.
>
> Gordon Smith, Falcon team, Adobe
Hello Gordon,

thanks for the information! If adobe really stays to its plans [1] with 
releasing a ActionScript specification then the Apache community can 
just improve the compiler on its own. Theoretically speaking it would be 
possible to implement generics with mxmlc but I guess waiting for Falcon 
makes more sense. If adobe wants to profit of the community efforts to 
improve Falcon then I suggest to not work on a separate branch.

yours
Martin.

[1] http://blogs.adobe.com/avikchaudhuri/2011/01/19/setting-the-context 
<http://blogs.adobe.com/avikchaudhuri/2011/01/19/setting-the-context/>

RE: [IDEAS] Collections and Generics

Posted by Gordon Smith <go...@adobe.com>.
> hopefully generics will be supported by the Falcon compiler.

Unfortunately, they won't be, at least not in the first release. We're just working on compiling the existing language faster and in less memory.

As discussed in the recent Flash Runtime whitepaper, Adobe plans to evolve the language, but primarily to help with the company's new gaming and video initiative. Whether generics are part of that future hasn't been decided yet.

Also, whether Adobe will continue to contribute to Apache future compiler changes to support new language features seems unclear at the moment. I haven't seen anybody write anything about that, and it probably hasn't gotten a lot of thought yet.

Gordon Smith, Falcon team, Adobe


-----Original Message-----
From: David Arno [mailto:david@davidarno.org] 
Sent: Friday, February 24, 2012 8:49 AM
To: flex-dev@incubator.apache.org
Subject: RE: [IDEAS] Collections and Generics

I have a small library of immutable collections (Tuple, OrderedList, HashMap plus type-safe versions of OrderedList and HashMap) at https://github.com/DavidArno/AS3Immutable. I'd be more than happy to donate these if we did want to build a set of collection classes into the SDK.
They'd probably need a bit of work on them to make them faster as I wasn't interested in speed when I wrote them though.

And hopefully generics will be supported by the Falcon compiler. I know I'm planning it with my Goshawk efforts.

David.


RE: [IDEAS] Collections and Generics

Posted by David Arno <da...@davidarno.org>.
I have a small library of immutable collections (Tuple, OrderedList, HashMap
plus type-safe versions of OrderedList and HashMap) at
https://github.com/DavidArno/AS3Immutable. I'd be more than happy to donate
these if we did want to build a set of collection classes into the SDK.
They'd probably need a bit of work on them to make them faster as I wasn't
interested in speed when I wrote them though.

And hopefully generics will be supported by the Falcon compiler. I know I'm
planning it with my Goshawk efforts.

David.


Re: [IDEAS] Collections and Generics

Posted by Omar Gonzalez <om...@gmail.com>.
On Friday, February 24, 2012, Alex Harui wrote:

>
>
>
> On 2/24/12 8:30 AM, "Omar Gonzalez" <omarg.developer@gmail.com<javascript:;>>
> wrote:
>
> > I agree with you about having more robust collections. I just wanted to
> > mention I have created a VectorCollection for working with Vector
> objects,
> > you can check it out here: https://github.com/s9tpepper/VectorTools
> I didn't look at the code yet.  How did you solve the problem of using a
> VectorCollection in APIs?  IIRC, that is still an issue in the AVM.
>
> --
> Alex Harui
> Flex SDK Team
> Adobe Systems, Inc.
> http://blogs.adobe.com/aharui


I'm not sure what you mean. I have used VectorCollection in s:List style
components, so it's compatible.

--
Omar Gonzalez
s9tpepper@apache.org
Apache Flex PPMC Member

Re: [IDEAS] Collections and Generics

Posted by Omar Gonzalez <om...@gmail.com>.
On Fri, Feb 24, 2012 at 11:19 AM, Alex Harui <ah...@adobe.com> wrote:

>
>
>
> On 2/24/12 11:11 AM, "Omar Gonzalez" <om...@gmail.com> wrote:
>
> > Then its just a matter
> > of retrieving the first item of the Vector and reflecting its type to
> > create an instance of and return the Vector list of selectedItems.
> IIRC, the issue is the creating and returning a different vector is a loop
> that coerces every item in the vector which is "bad".  There once was a
> plan
> to allow auto-conversion of Vector.<*> but I don't think that happened.
>
> --
> Alex Harui
> Flex SDK Team
> Adobe Systems, Inc.
> http://blogs.adobe.com/aharui
>
>
Well, selectedItems returns a Vector.<Object> [1] so there must be some
coercion going on somewhere, I just haven't looked at the source for s:List.

[1]
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/List.html#selectedItems

--
Omar Gonzalez
s9tpepper@apache.org
Apache Flex PPMC Member

Re: [IDEAS] Collections and Generics

Posted by Left Right <ol...@gmail.com>.
Long time ago in the galaxy far away I did this:
http://code.google.com/p/e4xu/source/browse/trunk/templates/List.as.fdtthese
are templates that FlashDevelop can process. In a certain sense, they
can be used just the same as vectors are used in AS3 with a certain bonus
of possible inheritance and abstraction of similar operations (sorting,
adding, removing and so on). The problem with this approach is the clumsy
syntax and no runtime code generation. (Did you know you could create a
vector of any class at runtime - well, you can, which is nice...)

I would imagine that as3-commons does it better, if you bring it's
libraries for runtime code generation.

Vectors, however, have other disadvantages... when serialized they loose
type information. They are serializable, and AMF has a special tag for
them, but it's halfway there - every vector is sent as a vector of
Object... bah.. no idea what had prevented the implementors from specifying
the actual type, but that's how things are...

Re: [IDEAS] Collections and Generics

Posted by Alex Harui <ah...@adobe.com>.


On 2/24/12 11:11 AM, "Omar Gonzalez" <om...@gmail.com> wrote:

> Then its just a matter
> of retrieving the first item of the Vector and reflecting its type to
> create an instance of and return the Vector list of selectedItems.
IIRC, the issue is the creating and returning a different vector is a loop
that coerces every item in the vector which is "bad".  There once was a plan
to allow auto-conversion of Vector.<*> but I don't think that happened.

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [IDEAS] Collections and Generics

Posted by Omar Gonzalez <om...@gmail.com>.
>
>  You
>> might say that List's selectedItems returns a Vector.<Object> but then it
>> can't return a Vector.<String>
>>
>
>
I just realized you mentioned selectedItems, I haven't actually tested that
either but that's a good point. If I add code to ensure the source is of
type Vector it shouldn't be difficult to add some reflection code to check
that if its type Vector it should return a Vector. Then its just a matter
of retrieving the first item of the Vector and reflecting its type to
create an instance of and return the Vector list of selectedItems.

--
Omar Gonzalez
s9tpepper@apache.org
Apache Flex PPMC Member

Re: [IDEAS] Collections and Generics

Posted by Omar Gonzalez <om...@gmail.com>.
>
>
> Actually, I was more simply asking about if you have a property or method
> or
> parameter of type VectorCollection.<Object>.  I thought you couldn't pass
> in
> a VectorCollection of ints or a VectorCollection of strings into a
> VectorCollection of Objects.  It was a problem for straight up Vector.  You
> might say that List's selectedItems returns a Vector.<Object> but then it
> can't return a Vector.<String>
>

That's correct, I also tried using Vector.<*>, but that was also a no go.
If you look at VectorList [1], it accepts a parameter source:Object as that
was the only way I could accept a Vector of any type. I should really add
some reflection code here to at least make sure the object being injected
in the constructor is actually a Vector. Besides that there really isn't
any need to strong type it to Vector.<*> or Vector.<Object> since the rest
of the code is not reliant on any method calls specific to the class.


>
> Also, what does getItemAt return?  Does it cause type-coercion?
>

getItemAt() is identical to ArrayList and returns an Object type so its
compatible with any type of Vector declaration.


> --
> Alex Harui
> Flex SDK Team
> Adobe Systems, Inc.
> http://blogs.adobe.com/aharui
>
>
[1]
https://github.com/s9tpepper/VectorTools/blob/master/src/almerblank/flex/utils/vector/VectorList.as

Re: [IDEAS] Collections and Generics

Posted by Alex Harui <ah...@adobe.com>.


On 2/24/12 10:03 AM, "Omar Gonzalez" <om...@gmail.com> wrote:


> I think I just figured out what you were asking, if you mean using the
> VectorCollection for AMF sending/receiving I have not tested that at all. I
> was mainly using VectorCollection for displaying models in List type
> components. I do remember running into issues with reflection on Vector
> objects when I was writing PlugrMan (http://plugrman.com/) to hook into
> different AMF libraries, but its been a while since I did that work so I
> don't remember exactly what problems I ran into.
> 

Actually, I was more simply asking about if you have a property or method or
parameter of type VectorCollection.<Object>.  I thought you couldn't pass in
a VectorCollection of ints or a VectorCollection of strings into a
VectorCollection of Objects.  It was a problem for straight up Vector.  You
might say that List's selectedItems returns a Vector.<Object> but then it
can't return a Vector.<String>

Also, what does getItemAt return?  Does it cause type-coercion?
-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [IDEAS] Collections and Generics

Posted by Omar Gonzalez <om...@gmail.com>.
On Fri, Feb 24, 2012 at 9:28 AM, Alex Harui <ah...@adobe.com> wrote:

>
>
>
> On 2/24/12 8:30 AM, "Omar Gonzalez" <om...@gmail.com> wrote:
>
> > I agree with you about having more robust collections. I just wanted to
> > mention I have created a VectorCollection for working with Vector
> objects,
> > you can check it out here: https://github.com/s9tpepper/VectorTools
> I didn't look at the code yet.  How did you solve the problem of using a
> VectorCollection in APIs?  IIRC, that is still an issue in the AVM.
>
> --
> Alex Harui
> Flex SDK Team
> Adobe Systems, Inc.
> http://blogs.adobe.com/aharui
>
> I think I just figured out what you were asking, if you mean using the
VectorCollection for AMF sending/receiving I have not tested that at all. I
was mainly using VectorCollection for displaying models in List type
components. I do remember running into issues with reflection on Vector
objects when I was writing PlugrMan (http://plugrman.com/) to hook into
different AMF libraries, but its been a while since I did that work so I
don't remember exactly what problems I ran into.

--
Omar Gonzalez
s9tpepper@apache.org
Apache Flex PPMC Member

Re: [IDEAS] Collections and Generics

Posted by Sai Pabbathi <sa...@gmail.com>.
That's a good start!

On Fri, Feb 24, 2012 at 10:30 AM, Omar Gonzalez
<om...@gmail.com>wrote:

> On Fri, Feb 24, 2012 at 8:14 AM, sai pabbathi <saipabbathi1@gmail.com
> >wrote:
>
> > Hello All,
> >
> > I've been thinking about creating my own version of collections and
> > Generics for a while now. I'm a java guy and I crave to have Collections
> on
> > the client side. Having the collections and generics would not hurt, it
> > would actually reduce the coding errors, and development time as most of
> > the time we will be working around the data in any type of application.
> > Some times I have to run the application to know the type of data that is
> > in the ArrayCollection, even though flex provides 'Vector' as way to
> > introduce generics into flex, it is not as powerful as the
> ArrayCollection,
> > and not many are aware of its existence.
> >
> > Also having a good set of collections like Map, Set, List, Queues would
> > help develop more robust client side applications.
> >
> > P:S: I'm unaware if adobe has already planned to roll out collections in
> > the near future. Its just an Idea!
> >
> > --
> >  Sai Pabbathi
> >  ACE 4.0
> >  SCJP 5.0
> >
>
> I agree with you about having more robust collections. I just wanted to
> mention I have created a VectorCollection for working with Vector objects,
> you can check it out here: https://github.com/s9tpepper/VectorTools
>
> If there's enough interest I can look at donating it to the SDK and
> expanding or adding to it, otherwise, its there in my repo. :)
>
> --
> Omar Gonzalez
> s9tpepper@apache.org
> Apache Flex PPMC Member
>



-- 
--Sai Pabbathi
  ACE 4.0
  SCJP 5.0

Re: [IDEAS] Collections and Generics

Posted by Alex Harui <ah...@adobe.com>.


On 2/24/12 8:30 AM, "Omar Gonzalez" <om...@gmail.com> wrote:

> I agree with you about having more robust collections. I just wanted to
> mention I have created a VectorCollection for working with Vector objects,
> you can check it out here: https://github.com/s9tpepper/VectorTools
I didn't look at the code yet.  How did you solve the problem of using a
VectorCollection in APIs?  IIRC, that is still an issue in the AVM.

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [IDEAS] Collections and Generics

Posted by Omar Gonzalez <om...@gmail.com>.
On Fri, Feb 24, 2012 at 8:14 AM, sai pabbathi <sa...@gmail.com>wrote:

> Hello All,
>
> I've been thinking about creating my own version of collections and
> Generics for a while now. I'm a java guy and I crave to have Collections on
> the client side. Having the collections and generics would not hurt, it
> would actually reduce the coding errors, and development time as most of
> the time we will be working around the data in any type of application.
> Some times I have to run the application to know the type of data that is
> in the ArrayCollection, even though flex provides 'Vector' as way to
> introduce generics into flex, it is not as powerful as the ArrayCollection,
> and not many are aware of its existence.
>
> Also having a good set of collections like Map, Set, List, Queues would
> help develop more robust client side applications.
>
> P:S: I'm unaware if adobe has already planned to roll out collections in
> the near future. Its just an Idea!
>
> --
>  Sai Pabbathi
>  ACE 4.0
>  SCJP 5.0
>

I agree with you about having more robust collections. I just wanted to
mention I have created a VectorCollection for working with Vector objects,
you can check it out here: https://github.com/s9tpepper/VectorTools

If there's enough interest I can look at donating it to the SDK and
expanding or adding to it, otherwise, its there in my repo. :)

--
Omar Gonzalez
s9tpepper@apache.org
Apache Flex PPMC Member