Havent tried but would that still compile #assert: as used in SUnit?

Also remember discussion of this thread with similar topic:
http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/2015-June/111037.html

 
Bye
T.
 

Gesendet: Donnerstag, 28. Januar 2016 um 15:36 Uhr
Von: "Marcus Denker" <marcus.den...@inria.fr>
An: "Pharo Development List" <pharo-dev@lists.pharo.org>
Betreff: Re: [Pharo-dev] Disable assertions (design by contract)

Hello,
 
Yes, we should experiment with that.
 
A compiler option is very easy to add… and easy to understand. And trivial to 
do.
 
1) step one:
 
add the following line at the start of OCASTTranslator>>emitMessageNode:
 

self compilationContext optionDisableAssert ifTrue: [ 
aMessageNode selector == #assert: ifTrue: [ ^methodBuilder pushReceiver ]
 ].
 
2) step 2. There is no step. 2 ;-). Maybe a better version would use plugin… 
changing the code generator like that
is a bit a hack. But it works.
 
You can now turn off all sends to #assert: by enabling the #optionDisableAssert 
compiler option.
e.g. class wide by setting on the class side in
 

compiler
^super compiler options: #(+ optionDisableAssert).
 
 
More magic is, of course, always possible later… I have some ideas.
 
Marcus
 
 

On 28 Jan 2016, at 13:54, Aliaksei Syrel <alex.sy...@gmail.com> wrote: 

Hi
 
Assertions play an important role in design by contract. It is great to have 
assertions in Pharo out of box (Object>>#assert:). However in projects with 
many post- and precondition as also class invariants heavy usage of assertions 
decreases performance...
 
Would it be possible to have a compiler setting (in setting browser) to 
enable/disable assertions and not compile them to bytecode? Compiler should 
ignore the whole assertion statement with removed condition. For example:self 
assert: self hugeInvariant.
with disabled assertion hugeInvariant must not be sent.
 

Thanks,
Alex

Reply via email to