Re: Java Generics and Erasure foobar
HackerBob wrote:
The issue here is that you still have to code for valid scenarios. I may
not be able to test every possible scenario but I can specify/limit the
valid ones.
Can you really test every *valid* scenario? What do you mean by that, by
the way? Would information that had been marked valid by some previous
validation step but containing invalid information be considered a valid
input?
Remember that any input to a public API is valid input. Nonsensical,
maybe, but you have to watch for that. A common saying I've heard is
that unit tests only tell you that the code works for the tests; nothing
is said about what they don't test.
So generics will make your code bug proof, more bug resistant? I do not
think so. I think you find your errors sooner in the process which does
add value but not enormous.
It makes common bugs compile-time errors, and warns you if you to
subvert this feature.
I do not think making it harder to write incorrect code is the correct
goal.The goal should be to write correct code easier, more parameters
does not seem like the answer.
By making incorrect code harder to write, correct code is easier to
write. You may be the Programming God, but if your co-developers can't
write correct code to save their lives, the application is not going to
turn out well in the end.
As I said: it takes one statement to crash a program. By making it
harder to write that crashing statement, your application's stability
improves.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth