[squeak-dev] How to really make portion of code optional

Michael van der Gulik mikevdg at gmail.com
Sun Aug 17 21:41:04 UTC 2008


On Sun, Aug 17, 2008 at 10:56 PM, cdrick <cdrick65 at gmail.com> wrote:

> Thanks James and Laurent,
>
> Actually this question was more to learn is it was possible. I
> remember a post about keeping or not comment in the source code...
>
> To be more precise, it's for log output of the inference system
> (http://nars.seasidehosting.st/). In each step, there can be something
> like 10 lines processes depending on entities are infered. The thing
> is this log output chunks are mixed in the code in several places. I
> could maybe use a better trigger mechanism like sending a signal with
> the entity in question, but still, there will be this message sent (or
> the test). I used stream and it seems ok (regarding performance), just
> wanted to know if we could deactivate some portion of code as
> everything seems possible here ;). I'll remind the subclass tip
> though.



 Hi Cédrick.

For this sort of thing, I usually use:

self assert: [some code].

When you put your code into production, you can make the implementation of
Object>>assert: be a "^self", which has very little overhead.

You could apply the same to logging, by implementing a similar method:

self log: [ 'Some error occured.' ]. " The return value of the block is
logged. "

Otherwise Keith Hodges has a logging framework, or you could use Toothpick (
http://www.metaprog.com/Toothpick/) which I believe has a Smalltalk
implementation.

Gulik.

-- 
http://people.squeakfoundation.org/person/mikevdg
http://gulik.pbwiki.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20080818/3c5f75fb/attachment.htm


More information about the Squeak-dev mailing list