views:

79

answers:

2

I am working on a game in JavaFX and I'm sending people the compiled game once in a while for them to try out. As I'm still in the middle of developing it, I have several pieces of code intended solely for developing/debugging.

One example is a gamespeed slider that is of great use for me while testing, but it is VERY buggy and can only be used in a specific manner - in other ways, I don't want code like that in the test releases.

What is the best ways of removing such code?

  • Surrounding the code with if(Config.DEBUG) (setting a parameter in code) ?
    • Using if() but setting parameter in different build configurations?
  • Can SVN branches keep sort of code like this? Or should I change to Git?
  • Is there any way to use annotations for this?
+2  A: 

SVN branches can be used for this, but you keep ending up with the effort of having to merge your branches every so often. I wouldn't do this.

Though perhaps not wildly elegant, I'd go for your first suggestion: Put a configuration parameter somewhere that your build process can change it for you automatically, and if()s around the affected code.

Change your build process so it will create player jars and testing jars at the same time.

Carl Smotricz
+1  A: 

Just use pure if statements, and check if some environment variable or VM option is set, in which case execute your debug code (or test release code, depending on your needs). There should be no performance issues, and the HotSpot JIT might even eliminate these parts.

Sure, it feels somewhat quick-and-dirty to me, but it's simple and it does exactly what you need.

Regarding your other suggestions, using a branch is not a good idea to do this. It's possible, but it will have an overhead you don't really like to deal with. Annotations might be able do the job, but this solution will be more complex than necessary.

candiru