J
Jan Burse
Lew said:I don't think I get your last paragraph here. What pain? What additional
classes? Why?
The discussion was about some custom HashMap, call this
class XXX. If one does use inline loops such as:
for (int i = 0; i<table.length; i++) {
Entry e = table;
while (e!=null) {
/* do something */
}
}
The one does not need to defined an interator for the
custom HashMap, call this iterator class YYY.
These iterators which implement the interface Iterator
(or Enumerator) are usually not much visible Java collection
classes, since they are realized as inner classes.
But they add to the LOCs and the number of classes:
With Iterator Without Iterator
XXX N + K LOCs N LOCs
YYY M LOCs
Total N + K + M N
K is for the iterator factories inside the collection
class. Pain = N + K + M - N = K + M.
Since nobody would use class YYY anyway, since XXX
is anyway internal to the whole multi-indexing
framework and not visible by the client of the framework,
its not only a pain but also not a necessity.
I'm willing to lay odds that for your use cases
the difference made by accessors and mutators is
not the low-hanging fruit.
For gambling you can go to Las Vegas, or if you
are up to something more serious, you could educate
yourself.
First of all originally Android didn't have a JIT.
See for example:
Second for my setter/getter claim you might want
to read this page:
http://developer.android.com/guide/practices/design/performance.html
There is a section about Avoid Internal Getters/Setters.
I copy the essential part for your eyes here:
"In native languages like C++ it's common practice to use getters (e.g.
i = getCount()) instead of accessing the field directly (i = mCount).
This is an excellent habit for C++, because the compiler can usually
inline the access, and if you need to restrict or debug field access you
can add the code at any time.
On Android, this is a bad idea. Virtual method calls are expensive, much
more so than instance field lookups. It's reasonable to follow common
object-oriented programming practices and have getters and setters in
the public interface, but within a class you should always access fields
directly.
Without a JIT, direct field access is about 3x faster than invoking a
trivial getter. With the JIT (where direct field access is as cheap as
accessing a local), direct field access is about 7x faster than invoking
a trivial getter. This is true in Froyo, but will improve in the future
when the JIT inlines getter methods."
Bye