On Mon, Dec 19, 2011 at 3:07 PM, topazmax <[email protected]> wrote:
> okay - maybe i'm just stupid or something.... but after hours & hours
> of searching & reading
> i've since found a number of posts on the subject but i still not sure
> how to control exactly what gets compiled at different times!
> "a plain java function that will do the same thing..." WHAT??? HOW???
> how does "change a flag" get me the control i want???
>
> the closest example i've seen was quite vague but this is what i got
> out of it if i'm not mistaken:
>
> int final testDebug1 = 1;
>
> if(testDebug1==1) {   do your debugging thing    }
>
> so if i later change testDebug1 = 0 the compiler now considers the
> 'if' block to be dead code so it is not compiled???
> (because test1 will never change (a constant) within the app)
>
> IS THIS CORRECT

Depends on the compiler, and the settings.  I'm not certain about the
Java compiler (which is bad, I certainly should be), but these small
blocks aren't big enough for you to worry about needing to be compiled
away:  on an interpreter the perf impact is minimal, and in a JIT
setting they *can* be compiled away..


> if this so - why does everyone make it sound so complicated and go on
> about languages etc... etc... and leave us wondering if we really got
> the message!!!

Because there are more advanced features that give you greater
control, but in general using preprocessors in Java is considered bad
practice that should be avoided (this is up for heated debate, and I'm
not starting one, so you can feel free to dismiss that idea if you
want).

> am i supposed to know that dead code is not compiled?

It depends, but I would argue that anyone who's taken a few CS courses
and has been around the field for a while would know that it's a
possibility depending on your compiler.. (Maybe you've never taken a
CS course that talks about compilers before, that's fair, in which
case you just learned about it now.)

> OR do i have to use another tool to remove that dead code???? - I
> STILL DON"T KNOW
>

ProGuard does this, and more, you can feel free to read about it.

> never used java or eclipse before so how am i supposed to know these
> things from the answers i read here...
> thanks for your replies just the same LOL

The debugging question is a silly one to worry about perf wise, but
the problem of coping with multiple versions of the platform (and
writing code that behaves differently in different settings) is one
you can at least partially solve by doing these kinds of things, but
it goes way beyond simple 'if then else' tests to interfaces, etc...

Unfortunately I can't find any good summary articles on how to deal
with this problem, if anyone has any links?

kris

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to