[squeak-dev] How to really make portion of code optional
James Foster
Smalltalk at JGFoster.net
Sun Aug 17 04:44:38 UTC 2008
On Aug 16, 2008, at 1:57 PM, cdrick wrote:
> Hi,
>
> I'm looking for a way to hide/show portion of code depending on if
> it's in development or production mode.
One approach would be to use the class hierarchy to do this. In your
abstract superclass put the shared behavior and in the subclasses put
the unique behavior. Then instantiate one or the other depending on
whether you are in development or in production.
> First idea is to wrap the code in question around a global
> productionMode var. But I was wondering if there is a better way.
> Somethink to really hide these portions of code for efficiency.
The last thing I'd worry about is efficiency. How many times do you
think you would execute the conditional? The thing you ought to worry
about is making the code easy to understand and maintain. The subclass
approach would mean that the conditional would be executed only once
(when you instantiate the object) and the remaining code would be clear.
> I know this is not a big deal (for my project) but I'm quite sure
> something may exist maybe at the VM level, so ...
That would be an unusual approach.
> Thanks in advance,
>
> Cédrick
James Fster
More information about the Squeak-dev
mailing list
|