Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7267

Re: enhance an array's static type by a lower length-bound.

Newsgroups comp.lang.java.programmer
From Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Subject Re: enhance an array's static type by a lower length-bound.
References <slrnj4nm33.6gl.avl@gamma.logic.tuwien.ac.at> <9b2gcfFcg7U1@mid.individual.net> <slrnj4r1tg.6gl.avl@gamma.logic.tuwien.ac.at> <9b6vg2F6hsU1@mid.individual.net>
Message-ID <slrnj4vr78.6gl.avl@gamma.logic.tuwien.ac.at> (permalink)
Date 2011-08-20 17:20 +0000

Show all headers | View raw


Robert Klemme <shortcutter@googlemail.com> wrote:
> On 18.08.2011 23:44, Andreas Leitgeb wrote:
>> e.g.:
>>     void foo(int[] ia) { ... }
>>     void foo(int[10] ia) { ... }
>>     void foo(int[20] ia) { ... }
> How likely is it that you want to have vastly different implementations 
> of foo() with different array lenghts?

Very unlikely :-)   (see later in this posting about benefits)

>> Hmm, the Class-instances representing arrays e.g. for a call to
>> Class.getMethod() likely would need to be specific for each bound.
>> There'd need to be a way to get a class-object for, say, int[42].
>> May be tricky, but doesn't seem impossible to me.
>> If you know of a specific difficulty here, then I beg you to speak up!
> As far as I can see you would need a Class instance for every 
> combination of base type and min length.  Plus you would need to ensure 
> that type compatibility check methods return the appropriate boolean 
> values.
So far so good.
> If you try to make them inherit (i.e. int[4] "is a" int[3]) things get 
> really crazy because int[4] is also an int[2] and int[1] and int[0]. 
> That doesn't fit Java's inheritance model well.  Now if you only have 
> int[4] and int[1] in the system the superclass of int[4] would be 
> different than if you also had int[2] in the system.  Now add dynamic 
> class loading into the mix...

If, for using (say) int[4200000], the JVM would really need all the 
4200000 other array-"superclasses" in memory at once, then this might
just be one such show-stopper that I searched for.  Thanks :-)

Maybe it could be fixed with some special case, where the superclasses
of a bounded array-class do not really need to be in memory, but this
would surely require a much deeper change than what I anticipated for it.


>>>    What you propose would be useful only if the added
>>> property of arrays would allow for *compile time* checking -
>> Well, that's the intention behind it - to some degree.
> Why only to "some degree"?  Compile time type safety would be the only 
> benefit compared to the current situation.  We do have runtime checks 
> already.

"To some degree":
The compiler would only check assignment to bounded arrays.  (including
the assignment that kind-of-happens to the formal parameters of the called
method)

Thus, the compiler could make sure, that a method taking a bounded array
would never get called with a smaller one (but could still get null, btw).

The compiler would however *not* check the particular indexing operations,
(therefore I wrote: "to some degree") as the array might be larger and
indices higher than the lower bound might just be legal.

> Why do you want to keep that out of the discussion?  When considering 
> technical solutions evaluating cost vs. benefit is always an important 
> part of the evaluation.

Sometimes these two aspects are evaluated separately.  The benefit has
already been evaluated as near-zero, because most arrays in practical 
use (those used internally for certain collections) just do not benefit
from a lower bound on length.
The only usecases so far were algorithms on arrays that require a
particular minimum length (such as obtaining the mean value), and
the anti-pattern of mis-using arrays to store separate fields.

Now, I'm evaluating the cost, and it is already higher than what I
expected (due to the JVM requiring complete chains of classes up to
Object).
The quest to find further costs would be less verbose, if the 
question about benefit weren't always re-raised.

> I think it's clear that what you propose can be solved technically - 

There's changes that (would) take a straight-forward effort to implement,
and there are changes that require some kind of wider refactoring. I'm
curious about the latter ones that would be necessary for implementing
that pseudo-proposal.  Just for the sake of the discussion, actually,
as I already pointed out in the first post of this thread.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-17 15:04 +0000
  Re: enhance an array's static type by a lower length-bound. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-17 12:34 -0500
    Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 13:14 +0000
      Re: enhance an array's static type by a lower length-bound. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-18 10:30 -0500
        Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 18:12 +0000
          Re: enhance an array's static type by a lower length-bound. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-18 20:59 -0500
  Re: enhance an array's static type by a lower length-bound. Robert Klemme <shortcutter@googlemail.com> - 2011-08-17 20:42 +0200
    Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 21:44 +0000
      Re: enhance an array's static type by a lower length-bound. Robert Klemme <shortcutter@googlemail.com> - 2011-08-19 13:24 +0200
        Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-20 17:20 +0000
  Re: enhance an array's static type by a lower length-bound. Roedy Green <see_website@mindprod.com.invalid> - 2011-08-17 22:11 -0700
    Re: enhance an array's static type by a lower length-bound. Lew <lewbloch@gmail.com> - 2011-08-17 23:17 -0700
      Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 10:41 +0000
        Re: enhance an array's static type by a lower length-bound. Patricia Shanahan <pats@acm.org> - 2011-08-18 06:34 -0700
          Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 18:08 +0000
            Re: enhance an array's static type by a lower length-bound. Roedy Green <see_website@mindprod.com.invalid> - 2011-08-18 17:53 -0700
              Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-20 17:31 +0000
                Re: enhance an array's static type by a lower length-bound. Lew <lewbloch@gmail.com> - 2011-08-20 10:50 -0700
                Re: enhance an array's static type by a lower length-bound. Robert Klemme <shortcutter@googlemail.com> - 2011-08-21 10:47 +0200
          Re: enhance an array's static type by a lower length-bound. Michal Kleczek <kleku@poczta.onet.pl> - 2011-08-21 20:27 +0200

csiph-web