[josm-dev] r4188 - removal of debug code
Paul Hartmann
phaaurlt at googlemail.com
Sun Aug 21 17:46:25 BST 2011
On 08/21/2011 02:21 PM, Dirk Stöcker wrote:
> On Sun, 21 Aug 2011, Stefan Breunig wrote:
>
>>> I'd have a really hard time believing that the JVM can't optimize stuff
>>> like this:
>>
>> and right you are;
>> http://stackoverflow.com/questions/1813853/ifdef-ifndef-in-java/1813871#1813871
>>
>>
>> It's compiled out, even if the main function isn't static. If you are
>> in doubt, just javap -c at the class file and search for a debug string
>> with debug = false and with debug = true and see if it works for the
>> class at hand.
>
> Hmm, I don't really trust this. It possibly works for easy situations,
> but I have seen to much "this should be optimized out" code remain in
> release versions to really rely on that feature.
Then just use the pattern in the easiest possible form - it does all
that is required. Even if the unlikely event should happen and the debug
code remains in the class file, it doesn't matter in this case. For most
parts of the sources, performance is not an issue, so a no op call here
an there is basically nothing.
There are clearly limits, what the Java Compiler can optimise out, e.g.
everything that could be accessed by reflection must stay.
For a similar reason I don't really like the java logging framework. You
always have the cost of argument construction, even if the logger is
turned off. (Yes, you can do 'if (logger.isDebugEnabled() {
logger.debug(...); }' but it's quite verbose.)
> I know sometimes I'm old-fashioned (not wanting git, don't using all
> these fancy new tools for specific tasks, not relying on compiler
> automatics, ...), but most of this comes from experience: E.g. if you do
> re-engineering of Assembler code to find a bug in your software and
> find, that the compiler is broken you loose your trust in compilers.
>
> I hope you all can live with that. :-)
>
> P.S. I'm even one of the few people not using IDE's at all, as I learned
> programming before graphical-all-in-one-interfaces became available.
> Which on the other hand means I still can work from 80x25 ASCII remote
> terminals without any problems.
Now I know, why you don't do unit testing: It's a pain without an IDE.
:) Anyway, you should give IDEs a try, e.g. interactive debugging can be
quite useful.
Paul
More information about the josm-dev
mailing list