Assertions are used in standard java framework, but have hard side effects : stopping the program immediately. (cf http://www.oracle.com/us/technologies/java/assertions-139853.html "...The program will be aborted if the expression evaluates to false..") With java it is possible, since the IDE and program are separated.
With Pharo you cannot, if you assert or throw an error in a sensible place, you are likely to hang your image or to go for multiple errors poping everywhere since you will break the state of an important object.
I do not think so. It is like putting a "self haltâ (or âHalt nowâ). It is all done using exceptions.
Another thing is that with dbc paradigm (assertions about your code), there is no 'one invariant' but lots of, you will not be able to express them in a single method, even if you could it would be hundreds lines and you would have to copy them in all methods you will want to check. The complete horror to maintain when you change your code.
I would not be that pessimistic.
The use of pragmas make it possible to activate or deactivate those contracts at compilation time, there will no overhead in standard execution without contracts. Think of the pragmas as a way to "inject" invariant compiled code into the compiled method for testing, then you recompile without for release.
Adding invariants will have *big* performance impact, probably several orders of magnitude, I'll measure. The overhead will of course come from calls of the checking framework, but no doubt that with run-time reflexivity checking, you will have something as sluggish too and you'll want to deactivate them at compile time â¦
currently, the class Object define the method: -=-=-=-=-=-=-=-=-= Object>>assert: aBlock "Throw an assertion error if aBlock does not evaluates to true. We check for true explicitly to make the assertion fail for non booleans" aBlock value == true ifFalse: [AssertionFailure signal: 'Assertion failedâ] -=-=-=-=-=-=-=-=-= It looks like a pretty convenient way to handle assertion. Nearly the same as in standard Java. Java offers the âassertâ keywords, that you can disable by setting adequate option in the JVM. If you want to disable the assertions in your class, you can simply redefine #asset: that does nothing. Sure, you can imagine a solution using pragmas, but sincerely, I do not think it will be more flexible than using #assert:. Again, Javaâs assertions are very similar to what we have now. However, I am pretty convinced there are great opportunities on writing assertions. It is really hard to write them, which is why not many are doing so. Cheers, Alexandre
--
Alain
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.