Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or return
In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or return [message #292681] Mon, 10 October 2005 21:49 Go to next message
Eclipse UserFriend
Originally posted by: outiejun.yeah.net

Hi, everyone

In the eclipse platform APIs or JDT and others, it seems that they use
arrays as arguments or return types as many as possible without using List
or other collections. Why? Are there any benifits or just a development rule
for eclipse core development?

Thanks
Re: arrays [message #292688 is a reply to message #292681] Tue, 11 October 2005 07:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

I suspect it's more to do with being able to declare the right type and memory efficiency (with objects like ArrayList being larger than a simple array). Most of the time, these arguments are thrown away after use, and so they take up less space in the 'nursery' part of the heap.

That's just my opinion; I don't know why the original APIs were chosen.
Re: In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or re [message #292699 is a reply to message #292681] Tue, 11 October 2005 09:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

outiejun wrote:
> Hi, everyone
>
> In the eclipse platform APIs or JDT and others, it seems that they use
> arrays as arguments or return types as many as possible without using List
> or other collections. Why? Are there any benifits or just a development rule
> for eclipse core development?
>
> Thanks
>
>

No benefits. Arrays can still be improperly typed and don't offer
immutability. I used to use them a lot but I changed to collections
because there is really no advantage with arrays, unless they are
extremely unlinely to change or are part of core classes that are used
very frequently and in high number or instances

CL
Re: arrays [message #293068 is a reply to message #292688] Mon, 17 October 2005 11:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

With APIs, declaring and enforcing the right type is the main reason for
using arrays. There can be the added benefit of performance, although
arrays that cross API boundaries often need to be copied to ensure the
caller does not tamper with internals.
--

Alex Blewitt wrote:
> I suspect it's more to do with being able to declare the right type and memory efficiency (with objects like ArrayList being larger than a simple array). Most of the time, these arguments are thrown away after use, and so they take up less space in the 'nursery' part of the heap.
>
> That's just my opinion; I don't know why the original APIs were chosen.
Re: In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or re [message #293070 is a reply to message #292699] Mon, 17 October 2005 11:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

CL [dnoyeb] Gilbert wrote:
> No benefits. Arrays can still be improperly typed and don't offer
> immutability. I used to use them a lot but I changed to collections
> because there is really no advantage with arrays, unless they are
> extremely unlinely to change or are part of core classes that are used
> very frequently and in high number or instances

You don't believe that arrays provide some type safety? If you have an
API with Object[] there is no additional type safety, but if you declare
the array type you can be sure that it only contains objects that are
instances of that type...
Re: In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or re [message #293093 is a reply to message #293070] Tue, 18 October 2005 03:19 Go to previous messageGo to next message
Eclipse UserFriend
John Arthorne wrote:
> CL [dnoyeb] Gilbert wrote:
>
>> No benefits. Arrays can still be improperly typed and don't offer
>> immutability. I used to use them a lot but I changed to collections
>> because there is really no advantage with arrays, unless they are
>> extremely unlinely to change or are part of core classes that are used
>> very frequently and in high number or instances
>
>
> You don't believe that arrays provide some type safety? If you have an
> API with Object[] there is no additional type safety, but if you declare
> the array type you can be sure that it only contains objects that are
> instances of that type...

John,

I agree with you, but if you consider JFace, most of the API use
Object[] instead of a collection. So I don't think there is any type
safety benefit ...
On the other hand you have to do a lot of "instanceof" tests or "cast"
operations which are time consuming.
So I'm not entirely convinced about the performance either (at least
it's not really better than using collections)
Re: In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or re [message #293099 is a reply to message #292699] Tue, 18 October 2005 08:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: douglas.pollock.magma.ca

CL [dnoyeb] Gilbert wrote:
> No benefits. Arrays can still be improperly typed and don't offer
> immutability. I used to use them a lot but I changed to collections
> because there is really no advantage with arrays, unless they are
> extremely unlinely to change or are part of core classes that are used
> very frequently and in high number or instances

I'd like to share an anecdote. I used to use Collection instances for most
of the code relating to commands and key bindings. I then switched over to
using arrays. The switch gave me about 5-10% CPU improvement and about 20%
memory improvement.

I think the biggest gains are avoiding iterators and minimizing unused
space. These are not intrinsic problems with the Collections library, but
I feel they are encouraged by the nature of the API. Take, for example,
the copy constructor in ArrayList. It adds 10% of unused space to the end
of the copied ArrayList. An add that exceeds the size will throw 50% of
extra space on the end of the ArrayList. Most people would use this
without realizing this side effect. In general, we have more information
available about how the data will grow, and so can optimize how an array
will grow.

If an array is returned from an API, then the user can choose to use the
array as is, or use Arrays.asList to convert it to a collection.



cheers,
d.
Re: In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or re [message #293239 is a reply to message #293070] Thu, 20 October 2005 08:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

John Arthorne wrote:
> CL [dnoyeb] Gilbert wrote:
>
>> No benefits. Arrays can still be improperly typed and don't offer
>> immutability. I used to use them a lot but I changed to collections
>> because there is really no advantage with arrays, unless they are
>> extremely unlinely to change or are part of core classes that are used
>> very frequently and in high number or instances
>
>
> You don't believe that arrays provide some type safety? If you have an
> API with Object[] there is no additional type safety, but if you declare
> the array type you can be sure that it only contains objects that are
> instances of that type...

Yes, you can be sure of what it contains, but not of what you can put
into it. Collections are just the opposite. You can put anything into
them, but can't be sure of what you get out of them.

Object [] x = new Integer[5];
x[0] = new String(""); //class cast exception

Thats no advantage with respect to type safety to me. This is why we
needed Generics so desperately.

CL
Re: In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or re [message #293303 is a reply to message #293239] Thu, 20 October 2005 13:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

CL [dnoyeb] Gilbert wrote:
> Yes, you can be sure of what it contains, but not of what you can put
> into it. Collections are just the opposite. You can put anything into
> them, but can't be sure of what you get out of them.
>
> Object [] x = new Integer[5];
> x[0] = new String(""); //class cast exception
>
> Thats no advantage with respect to type safety to me. This is why we
> needed Generics so desperately.

That's a bit like saying if you declare all your fields and variables to
be of type "Object" you don't get type safety. Well, that's true, but
it doesn't mean it's not possibly to use more appropriate types to get
the safety you need. A generic collection is no better than a typed
array as far as type safety is concerned (with a lot of added
syntactical gunk thrown in for good measure).
--
Re: In the eclipse platform APIs or JDT and others, it seems that they use arrays as arguments or re [message #293311 is a reply to message #293303] Thu, 20 October 2005 15:59 Go to previous message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

John Arthorne wrote:
> CL [dnoyeb] Gilbert wrote:
>
>> Yes, you can be sure of what it contains, but not of what you can put
>> into it. Collections are just the opposite. You can put anything
>> into them, but can't be sure of what you get out of them.
>>
>> Object [] x = new Integer[5];
>> x[0] = new String(""); //class cast exception
>>
>> Thats no advantage with respect to type safety to me. This is why we
>> needed Generics so desperately.
>
>
> That's a bit like saying if you declare all your fields and variables to
> be of type "Object" you don't get type safety. Well, that's true, but
> it doesn't mean it's not possibly to use more appropriate types to get
> the safety you need. A generic collection is no better than a typed
> array as far as type safety is concerned (with a lot of added
> syntactical gunk thrown in for good measure).
> --

Its nothing like using Object. An Object reference will always return
an instance that is a type Object. An Object reference will always
accept an instance that is of type Object. You can view arrays as not
behaving this way. Object []'s elements will always return an instance
that is a type Object. However, Object []'s elements will not accept an
instance just because it is of type Object.

There is a significant difference there. This knowledge is just the
opposite of Collection as stated previously.

Generic collection aleviate this issue. In fact it was generics that
first clued me in to the existance of this issue because of some
warnings from the compiler.

Object [] is fine for getting things out, but you have _no idea_ what
you can safely put into it.


CL
Previous Topic:Internationalization with Eclipse 3.2
Next Topic:Making an RCP application out of an editor
Goto Forum:
  


Current Time: Fri May 09 20:03:17 EDT 2025

Powered by FUDForum. Page generated in 0.04192 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top