views:

80

answers:

2

Suppose you have

private static const INCLUDE_MY_DEBUG_CODE:Boolean = false;

public function runMyDebugCode():void
{
    if ( INCLUDE_MY_DEBUG_CODE )
    {
        callADebugFunction();
    }
}

private function callADebugFunction():void
{
    ...
}

Given there is no other reference to callADebugFunction, will it be guaranteed that callADebugFunction is not part of the compiled build?

A: 

I highly doubt it. Since something IS referencing that function (regardless of whether or not it is reached at runtime), it is most likely that this code will in fact get compiled into your SWF/SWC file.

There are better ways to prevent debugging code from ending up in release builds. See zdmytriv's answer.

Lior Cohen
Who knows what compiler optimizations there are ? :)
Bozho
True enough, and yet, when considering the overall maturity of Adobe's compilers, I'm willing to take a bet here and stand behind my answer :)
Lior Cohen
Lior is correct, the function would be compiled into the application.All functions are included in referenced classes. Flex will exclude whole classes if they aren't referenced, but no finer-grained than that.
Sly_cardinal
+7  A: 

If there no references to the file/class - then it's not going to be compiled.

In your case if you have reference from outside to this class - all the methods are going to be compiled.

Use compilation variables to eliminate debug code from release.

Go to Project->Properties->Flex Compiler and add

For debugging mode:

-define=CONFIG::release,false -define=CONFIG::debugging,true

or for release:

-define=CONFIG::release,true -define=CONFIG::debugging,false

Then in you function runMyDebugCode()

CONFIG::debugging { 
    trace("this code will be compiled only when release=false and debugging=true");
}


CONFIG::release { 
    trace("this code will be compiled only when release=true and debugging=false");
}
zdmytriv
+1. Was going to suggest that after getting more details from the asker.
Lior Cohen
That's what I was looking for - thanks.
Stefan