I saw some guy defining configurations (like key, some static names, etc.) inside a class names Constants
which has const
properties.
I know that it is most elegant way to use configuration files for this kind of scenarios as described here but what is the advantages? I can assume that there must a performance benefit even if it is a little.
The advantages are that you can change those value at runtime, with constants you can only change the values at compile time (meaning if you need to change something, you need to recompile and redeploy).
I still use constants and "Constants" classes for internal settings that I know won't need to be changed at runtime. These save you a little bit of overhead in reading, parsing, and setting up your configuration classes (ConfigurationManager
etc). But if there's even a remote chance you might want to make an adjustment at runtime or after deployment, the performance savings isn't worth the extra hassle (IMHO).
The advantage to config files is that you can change values without compiling.
There is an advantage in using a const if there is no possible way that the value will ever change. The performance gain is negligible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With