On Monday 20 March 2006 14:21, Mikhail Loenko wrote:
> 2006/3/19, Chris Gray <chris.gray@kiffer.be>:
> > I prefer to let these things happen automatically whenever possible.
> > Introducing an explicit check adds extra bytecodes and probably extra CPU
> > cycles in the non-null case. On some VMs null.someMethod() might be
> > slower in the null case, but if the RI also throws NPE then these cases
> > should be truly exceptional in the sense that they indicate a programming
> > error or a missing resource.
>
> I do not agree that performance in case of 'exceptional' behavior
> is not important.
>
> Would you use for example a browser that hangs your machine up for an hour
> if you type wrong URL? Or if it crashes when some site misses some gif
> file?
<aside>I can remember browsers that did that (or at least waited for DNS to
time out).</aside>
I never claimed that performance in case of 'exceptional' behavior is not
important. However it is less important than performance in the normal case;
for example it would not make sense for Apache to optimise the processing of
mistyped URLs at the expense of correctly-typed ones. Ideally the most
frequently executed code paths should also be the shortest.
There are cases where a 'catch' clause can be executed very often, such as the
ClassNotFoundException which is thrown when a class loader delegates to its
parent and the parent does not find the class. In such cases one might
consider optimising this path; but NPEs generally do not fall into this
category, they most often indicate a programmer error (not user error) or the
absence of some required resource (installation error). That is what I meant
by "truly exceptional".
Respectfully,
Chris
--
Chris Gray /k/ Embedded Java Solutions BE0503765045
Embedded & Mobile Java, OSGi http://www.k-embedded-java.com/
chris.gray@kiffer.be +32 3 216 0369
|