M
marlow.andrew
I am familiar with the idea of assertions, from my days with C/C++
(assert.h) and from what Bertrand Meyer says about them in OOSC(II).
And it seems to me that the java assert mechanism is similar. But I
reckon I would never use it for the same reason that I never used the
assert mechanism in C/C++. I preferred to throw an exception that
basically meant a fatal programming error has occurred. It would
always throw if triggered, there was not a mode for production that
made it a no-op. Checking was always on.
The reason I preferred a solution that always checked was because all
too often I come across code that contains assert compiled so that it
is turned off. The code goes wrong but the assertions designed to
detect this never trigger, the program just blows up or otherwise goes
bad.
So do people actually find the java assert mechanism useful? I am
relatively new to java and have not seen it used in any projects I
have been on yet. But I do see lots of advice telling newcomers to use
it and how good it is. Does anyone here prefer to always have the
checking on?
Regards,
Andrew Marlow
(assert.h) and from what Bertrand Meyer says about them in OOSC(II).
And it seems to me that the java assert mechanism is similar. But I
reckon I would never use it for the same reason that I never used the
assert mechanism in C/C++. I preferred to throw an exception that
basically meant a fatal programming error has occurred. It would
always throw if triggered, there was not a mode for production that
made it a no-op. Checking was always on.
The reason I preferred a solution that always checked was because all
too often I come across code that contains assert compiled so that it
is turned off. The code goes wrong but the assertions designed to
detect this never trigger, the program just blows up or otherwise goes
bad.
So do people actually find the java assert mechanism useful? I am
relatively new to java and have not seen it used in any projects I
have been on yet. But I do see lots of advice telling newcomers to use
it and how good it is. Does anyone here prefer to always have the
checking on?
Regards,
Andrew Marlow