28 December 2008

What did we loose with hiding object's address?

Let's list advantages:

  • More control over application security! Mostly, it's impossible to get forbidden information.
  • Information has to be delivered overtly.
  • Garbage collector can work easier, more reliable and it's not so rare to be faster than manual deallocating memory. What's more, programmers have more time for code quality and efficiency.


  • Programmer is obliged to predict which data will be needed in future.
  • Natural (physical) objects order has been lost.

Let's look closer to consequences of natural ordered lost. At first, it may seem like there is no negative impact and for most common problems it's truth.
Secondly, after a closer look we may notice that accessing objects by address is not necessary. However, there are some groups of algorithms that need some kind of order, like binary-search. For example:
We have two collections of objects and we wand to do some operation on them like: intersection.

How big is that task (approximately)?
n : size of 1st collection
m : size of 2nd collection
k : average size important information in single object

Now time in java in == sense :

  • n*m

Now time in java in .equals(...) sense :

  • n*m*k

Now time if programmer provide Comparator (it might be impossible):

  • min(n,m)*log(max(n,m))*k
  • +time to write valid comparator and rewrite it on any data structure change.
  • +sorting time n*log(n)*k + m*log(m)*k (this do not have to be done each time)

Same task with some (like physical in memory) order:

  • min(n,m)*log(max(n,m))
  • +sorting time n*log(n) + m*log(m) (this do not have to be done each time)

So if we get some data (static for object) we would be able to make some algorithms real-time. For example, I may say that a simple optimalization of searching in a dictionary can widely decrease server's usage. For me, it was 30%.
It does not have to be address, Handle^someRandom is appropriate as well.
Solving this problem would not make the impact of all Java community, but it would allow to make reliable and fast tools for programmers that would be a great advantage.

The main problem is that object address in Java is not constant, so I'll need to check if there are some static handlers that would allow to make one step forward after successful step back.

Of course, I disagree with allowing to access object with handlers.

1 comment:

  1. Bez obrazy, ale twój angielski jest taki, że nie da się tego czytać - proponuję spróbować po polsku.