Assertions

Post Reply
UrbanCyborg
Posts: 625
Joined: Mon Nov 15, 2021 9:23 pm

Assertions

Post 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
Cyberwerks Heavy Industries -- viewforum.php?f=76
ColinP
Posts: 1000
Joined: Mon Aug 03, 2020 7:46 pm

Re: Assertions

Post 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?
Steve W
Posts: 805
Joined: Thu Jul 16, 2020 5:55 pm

Re: Assertions

Post 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.
ColinP
Posts: 1000
Joined: Mon Aug 03, 2020 7:46 pm

Re: Assertions

Post 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.
UrbanCyborg
Posts: 625
Joined: Mon Nov 15, 2021 9:23 pm

Re: Assertions

Post 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
Cyberwerks Heavy Industries -- viewforum.php?f=76
ColinP
Posts: 1000
Joined: Mon Aug 03, 2020 7:46 pm

Re: Assertions

Post 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.
Post Reply

Return to “Module Designer”