Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for avoiding hardcoded values IRL

In theory, source code should not contain hardcoded values beyond 0, 1 and the empty string. In practice, I find it very hard to avoid all hardcoded values while being on very tight delivery times, so I end up using a few of them and feeling a little guilty.

How do you reconcile avoiding hardcoded values with tight delivery times?


1 Answers

To avoid hard-coding values, consider:

  • Using configuration files (e.g., XML or INI formats).
  • Storing values in database tables.

Some values may still need to be hard-coded using constants or enums provided by the language.

Just saw an answer to use "Constant Interface". With all due respect to the poster and the voters, but this is not recommended. You can read more about that at:

http://en.wikipedia.org/wiki/Constant_interface

like image 107
del.ave Avatar answered Oct 19 '25 11:10

del.ave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!