Re: Why Generics?
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 May 2005 18:17:24 +0100
tzvika.barenholz@xxxxxxxxx wrote:
> > > Remember that you must always fail as early as possible! Generics
> > > turn Runtime Errors (class cast exceptions) into compile time errors.
> > > This
> > > has tremendous values.
> >
> > For this to have "tremendous value" then it must be the case that class
> > cast exceptions are being thrown in expensive-to-change code (deployed
> > or late in testing) on frequent basis. That is not my experience.
[...]
> It greatly depends on whether or not you ship your code. Of course if
> it's you who is the 'client' or someone in the next cubicle, you are
> right. But sometimes its halfway around the world.
This is something of a simplification. I agree that code that has shipped
(however far it's gone physically) has a higher cost to change than code that
has not shipped. Code that has shipped to many customers has a higher cost
than code that has shipped to only a few, or even none. Etc. But what your
analysis misses is factoring in the probability of there being a problem in the
first place. If that were mathematically, exactly, zero then clearly it
doesn't matter how far the code has shipped. If the probability is low enough
then even when multiplied by the large cost of late changes, the resulting
probable cost is low.
It is not enough to say "it would be bad if it happened", you also have to ask
how likely it is to happen before you decide what preventative measures are
justified.
As others have said, class cast exceptions are so rare that many people have
never even seen one -- not even in development code (I never have) -- so the
probability of there being one in any given shipped application is very low.
Given that multiplier, it is unlikely that there is "tremendous" value to be
found in "eliminating" them. Not unless the cost of failure is absolutely
stratospheric (hundreds of human lives, say).
BTW, if you really mean that you think this is a serious issue (I have no
reason to suppose that you do) then you shouldn't be using Java -- there are
many possible errors that it /could/ catch at compile time, but actually leaves
until runtime. E.g null pointer exceptions, infinite loops, array bounds
exceptions, illegal modification of supposedly read-only objects, etc. Not
that testing any or all of these would be without its own cost in flexibility,
expressiveness, and usability of the language, but they /could/ be tested for.
Null pointer exceptions /do/ happen in real life, yet null-ness isn't part of
Java's type system... <shrug/>
-- chris
.
- Follow-Ups:
- Re: Why Generics?
- From: Dale King
- Re: Why Generics?
- From: tzvika.barenholz@xxxxxxxxx
- Re: Why Generics?
- From: Mike Schilling
- Re: Why Generics?
- References:
- Why Generics?
- From: David Blickstein
- Re: Why Generics?
- From: tzvika.barenholz@xxxxxxxxx
- Re: Why Generics?
- From: Chris Uppal
- Re: Why Generics?
- From: tzvika.barenholz@xxxxxxxxx
- Why Generics?
- Prev by Date: Re: Why Generics?
- Next by Date: Re: Why Generics?
- Previous by thread: Re: Why Generics?
- Next by thread: Re: Why Generics?
- Index(es):
Relevant Pages
|