mardi 1 novembre 2016

Fed up with properties files

Once again, in the source code of our applications, I find lots of constants defined in a properties file in Java. Why that? In these files, one can only define strings. Reference to property entries are also strings. They're not checked at build time. Hence, they cannot be interpreted by an IDE. You cannot jump easily to your property value. It's a shame, as this is why we use heavy IDEs! Why are you carrying out such a sabotage???

In my case, a Java file references constants that are declared in another Java file where they reference… Properties! That's indirection for the sake of indirection.

In lots of situations, properties are useful though. You sometimes want to be able to configure your application without building it again. You want to be able to setup parameters specific to your running environment. You want to be able to change some parameters and see them applied without restarting the application, such as logger configuration.

That represents very few cases though. This is not a good idea to store to every constant that are used by your application in those files. In most cases, changing a constant value should be thoroughly tested. It is not something to be done by everyone, without going into build phase.

So please, stop using properties by default. Create one only when you cannot avoid it.