English 中文(简体)
Best practices on separating debug/developing code java/javafx
原标题:

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?
最佳回答

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.

问题回答

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签