Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java ArrayList 1.7

Name: Anonymous 2011-11-30 10:39

http://www.docjar.com/html/api/java/util/ArrayList.java.html


  374       /**
  375        * Returns the element at the specified position in this list.
  376        *
  377        * @param  index index of the element to return
  378        * @return the element at the specified position in this list
  379        * @throws IndexOutOfBoundsException {@inheritDoc}
  380        */
  381       public E get(int index) {
  382           rangeCheck(index);
  383  
  384           return elementData(index);
  385       }

 596       /**
  597        * Checks if the given index is in range.  If not, throws an appropriate
  598        * runtime exception.  This method does *not* check if the index is
  599        * negative: It is always used immediately prior to an array access,
  600        * which throws an ArrayIndexOutOfBoundsException if index is negative.
  601        */
  602       private void rangeCheck(int index) {
  603           if (index >= size)
  604               throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  605       }



What's the point of having a range check if it only checks if the index is >= to the size and not if it's < 0. This seems stupid and a waste of a method call.



  171       /**
  172        * Increases the capacity of this <tt>ArrayList</tt> instance, if
  173        * necessary, to ensure that it can hold at least the number of elements
  174        * specified by the minimum capacity argument.
  175        *
  176        * @param   minCapacity   the desired minimum capacity
  177        */
  178       public void ensureCapacity(int minCapacity) {
  179           if (minCapacity > 0)
  180               ensureCapacityInternal(minCapacity);
  181       }
  182  
  183       private void ensureCapacityInternal(int minCapacity) {
  184           modCount++;
  185           // overflow-conscious code
  186           if (minCapacity - elementData.length > 0)
  187               grow(minCapacity);
  188       }


ensureCapacity is never called, yet they have it in the class.


BLOAT

Name: Anonymous 2011-11-30 10:53

To fuck with you. Did it work?

Name: Anonymous 2011-11-30 11:05

ensureCapacity is never called, yet they have it in the class.
It's a public method, you retard.

Name: Anonymous 2011-11-30 11:09

using 4 spaces to represent a tab

Name: Anonymous 2011-11-30 12:59

http://www.docjar.com/html/api/java/lang/Integer.java.html

now this is bloat, all for a simple integer class

Name: Anonymous 2011-11-30 13:03

ArrayList class itself is pretty much bloat. good old C arrays.

Name: Anonymous 2011-11-30 13:07

Name: Anonymous 2011-11-30 13:14

>>7
does someone actually use that?

who the fuck would do something like that..

Name: Anonymous 2011-11-30 13:15

>>8
an average Java programmer.

Name: Anonymous 2011-11-30 13:19

that bloat feel when java generics must use objects

Name: Anonymous 2011-11-30 13:29

<--

Name: Anonymous 2011-11-30 16:02

^
|
|

Name: Anonymous 2011-11-30 19:18

LOL
  224       /**
  225        * Returns the number of elements in this list.
  226        *
  227        * @return the number of elements in this list
  228        */
  229       public int size() {
  230           return size;
  231       }


Java is one of those amusingly disgusting examples of abstraction taken to extremes. The sane way to get the length in a language like C would just be accessing a .size field of the structure representing the list object. Instead Java forces you to go through a method call.

Name: Anonymous 2011-11-30 19:21

>>13
If you can access it directly you can also mutate it, with grave consequences.

Name: Anonymous 2011-11-30 19:33

>>14
That's a feature, not a bug. Languages should be designed towards programmers, not mental midgets.

Name: Anonymous 2011-11-30 19:47

>>15
Languages should be designed towards programmers, not mental midgets.
Why? Keep in mind that almost everyone is a mental midget, it makes sense to target them with sub-par languages like Java.

Name: Anonymous 2011-11-30 19:53

>>15
Welcome to java, you could alternating rewrite most of the standard library or at least the parts you use. That's what i do.

There's no point to most of the bloat that's in there for error checking when I know what I'm doing and I'm not going to be an idiot and try to break my own program with bullshit like array.get(-1) or some bullshit like that.

Name: Anonymous 2011-11-30 20:51

>>15
>Languages should be designed towards programmers, not mental midgets.
Real-men languages, yes.
However, Java is an enterprise language: not innovative, and you cannot break anything.
So it's slow, bloated and retarded.

Name: Anonymous 2011-11-30 21:25

>>15
>>16
>>18

Interesting assessments.

Does the Java compiler/interpreter inline such methods, or only when they're declared final? (Or not even then?)

This makes me think about all the performance war between Java, C and C++. If the compiler/interpreter cannot even optimize such a call, how can it be possible, as some claim, for Java to be as fast as C or C++?

Name: Anonymous 2011-11-30 22:07

>>19
You can't inline a function that uses private variables, otherwise that would violate the concept of private variables.

Name: Anonymous 2011-11-30 22:21

no one claims Java to be as fast as C++, let alone C, now as fast as C# maybe in some areas/tests... still C# is newer and frankly better optimized

Name: Anonymous 2011-11-30 22:21

>>19
>Does the Java compiler/interpreter inline such methods, or only when they're declared final? (Or not even then?)
I cannot say. I think that the compiler (.java -> .class) does not do it, since it is really basic. Most optimizations are done at runtime in the JVM, and since there is lot of work on it, I think it may inline those functions.

See this: http://shootout.alioth.debian.org/u64q/which-programming-languages-are-fastest.php?gcc=on&gpp=on&java=on&calc=chart (quad-core) or this: http://shootout.alioth.debian.org/u64/which-programming-languages-are-fastest.php?gcc=on&gpp=on&java=on&calc=chart (mono-core): Java is very good, but not on the level of C or C++.
However, I'm currently working at a company that produces a OLAP DBMS for financial companies, and it's highly multi-threaded (at clients' we make it run on computers with 50 or 100 cores, and hundreds of GO of RAM). It performs far better than the competitors' products, who are mostly in C or C++, thanks to the ease of multithreading and parallelizing in Java.
Yes, faster than C.

Name: Anonymous 2011-12-01 0:18

The only thing that disadvantages java over seeples and C, is the inability to specify manual memory allocation. You can use garbage collection in seeples and see if you leverage a library for it, and use strict conventions about pointers if it happens to be a copying collector. But this takes effort, and not many people do it, and it doesn't eliminate memory errors, since you can still do manual memory management on the side, and arbitrary things with pointers. So when one programs in see and seeples, they are much more likely to use stack allocation and malloc/free to meet their needs. In java, one is unable to explicitly specify usage of the stack or manual memory management, so it rests with an optimizing compiler to avoid the gc when possible. It isn't too difficult to detect when a value can be allocated on the stack in some cases, like


double length = new Vector(x, y, z).magnitude();


The result of new Vector(x, y, z) is never saved anywhere, so it is impossible for a reference to it to exist after the running function returns, or after that expression is done being evaluated for that matter.

Getting a compiler to detect ownership rules and institute manual memory management could be difficult to do in general. I'm not sure if people try to do this. This would require looking at the entire program as a whole, and using data flow analysis to examine where values can go. This would be difficult, but I'm sure it could be done for many simple usage cases. Detecting when reference counting would be sufficient is probably much easier, and would likely yield results that are just as good.

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2011-12-01 3:21

If the compiler/interpreter cannot even optimize such a call, how can it be possible, as some claim, for Java to be as fast as C or C++?
Very aggressive space/speed tradeoff (.NET is similar) ---  things like GC make memory allocation almost intantaneous (until you run out of memory and GC is needed, that is), and inlining everything also has similar effects.

(This only works up to the size of the cache, and then cache misses start occurring and everything slows down again.)

Name: Anonymous 2011-12-01 12:15

>>22

I've seen a number of benchmarks with opposite results. For some reason I feel that, instead of trying to find the truth about these issues, people attempt to defend their own, usually biased, point of view, for no apparent rational reason.

It seems, from what you proposed, that Java performs better than C in the very case where it is harder to write good quality, aggressive parallel algorithms in C than it is in Java. In other words, Java performs better because it is algorithmically superior than the C version; they're not at all the "same" programs (if anywhere meaningful to say that).

Now I'm curious to investigate further how exactly Java makes it easier than C to write parallel code. It is surely difficult to write good quality, scalable parallel C or C++ code, even with modern libraries. However, if I recall correctly, Java has no advantages, at least not language-wise, for that, apart synchronized. Does the VM perform auto-parallelization?

>>23

There are a number of other things which (should) impact Java in favor of C too, apart the memory allocation issue. I've mentioned the inlining of such simple forwarding methods as one of them. Another one is the fact that evey method in Java is virtual (correct me if I'm wrong), making a method call two or three steps slower than a C function call (or non-virtual C++ method call); this is obviously addressed by the JVM however, since method invocation speed is one of the most known Java features.

>>24

The space/speed tradeoff can also be performed in C or C++, for example, by using a pool allocator or some sort of custom allocator thereof. There are a number of alternative implementations for standard allocators, such as Hoard (http://www.hoard.org/). In a couple of experiments I've done some time ago, the optimizer was even able to completely eliminate some calls to the allocator in some situations. The downside is that, since most of the implementation had to be visible for every TU, the compilation time grew to intolerable levels.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-12-01 14:42

>>22
>faster than C
I've seen many languages described as this, yet all cases reduce to "crappy C code is slower than optimized X code".
If we assume that you have to optimize low-level languages require more optimization and detail than high-level ones(due being less abstract), and typical high-level programmer neglecting low-level optimizations, expecting the VM/Compiler/The invisible hand of the market/God/The tooth fairy optimize the code.

Name: Anonymous 2011-12-01 15:11

>>23
You can use garbage collection in seeples and see if you leverage a library for it
Not really.

Name: Anonymous 2011-12-01 21:33

You would think that memory consumption would be a large factor for a large-scale database. That's what I don't get with all the projects like Cassandra, Hadoop, etc: Why do they use Java, where they have to deal with the memory overhead of object allocations, jagged arrays, forced signedness, etc.
I can see how the overhead of the JVM itself and the JIT isn't so significant in large server configurations, but you never have enough RAM in big data, so how can they afford to waste X% of it?

Name: Anonymous 2011-12-02 8:55

why doesn't java have unsigned variable types

Name: Anonymous 2011-12-02 10:00

>>29
or operator overloading
because it is shit

Name: Anonymous 2011-12-02 10:16

>>28
Because ENTERPRISE

Don't change these.
Name: Email:
Entire Thread Thread List