Page 1 of 1
Assertions
Posted: Mon Sep 25, 2023 10:08 pm
by UrbanCyborg
How does VM support assertions? There's no apparent mechanism for enabling or disabling them, and no access to the command line that I'm aware of.
Reid
Re: Assertions
Posted: Tue Sep 26, 2023 7:22 pm
by ColinP
I'm guessing from the mention of command line arguments that you mean being able to switch assertions on and off in production code?
Presumably so that if a user encounters a problem with one of your modules you can switch assertions on in their environment to perform diagnostics.
If so I'd use a manufacturer property to do this and trap something like a CTRL click on the company logo to switch the flag on and off.
Or maybe you mean something different?
Re: Assertions
Posted: Tue Sep 26, 2023 10:06 pm
by Steve W
An assertion is a statement in the Java programming language that enables you to test your assumptions about your program. For example, if you write a method that calculates the speed of a particle, you might assert that the calculated speed is less than the speed of light.
Re: Assertions
Posted: Tue Sep 26, 2023 10:43 pm
by ColinP
Just to be clear I'm talking about ad hoc assertions rather than ones using the assert statement in Java.
To enable or disable assert statements you need access to the command line and to use -ea or -da switches whereas with ad hoc assertions an internal flag can be used.
Besides I think assert statements are not recommended for design by contract use. i.e. like the require and ensure keywords in Eiffel. Instead you are supposed to check and throw exceptions, So by an ad hoc assertion what I mean is wrapping such a check within an if statement controlled by a flag.
Re: Assertions
Posted: Wed Sep 27, 2023 3:42 pm
by UrbanCyborg
Colin, your ad hoc assertions are what I'm using now; I was interested in VM's support (if any) for Java asserts using the keyword. I suspect that at some level VM just generate a command line for the compiler; I just didn't know if there was any way to access and modify it. Or some other mechanism I haven't spotted. For now, I don't so much care about enabling them in a user's production environment, just enabling them in mine (then disabling them before publish).
Reid
Re: Assertions
Posted: Wed Sep 27, 2023 9:11 pm
by ColinP
The only switches so far available in VMD are -Xlint:all and -Xdiags:verbose but it would be trivial to add an assertion switch. Maybe make a direct feature request, you never know.