Configure everything you can

It’s 2:30 in the morning. You have finally gotten to sleep. Then your phone starts ringing. What the HELL does the Directory of DevOps want with me? It turns out that now is when the annual URL update decreed by marketing is getting released and your utility which has become a linchpin in the deployment pipeline is broken. The utility needs to be recompiled with the new URL value to successfully complete the deployment before the new version of the application is released to the public later this morning.

I frequently see a lot of code, and some from people that are senior engineers, which is littered with hard coded values for variables that should be pulled out into some sort of configuration. Over the years I have had it hammered into my head by teachers, colleagues, managers, mentors, etc. that configuration should NOT be in code. Apparently not everybody has benefitted from the same “encouragement”.

For the purposes of this discussion I’ll define configuration as any value that could change over time and should be parameterized in some way and passed into the application. User credentials, URLs, min and max settings, pretty much anything that would show up in code like

myUrl = "https://dev.mysite.com"

These types of lines of code should be pulled out and grabbed from a config file, inserted as a command line parameter, taken from an environment variable or any other method that does not involve recompiling the code to deliver a change.

I call out URLs specifically in my example because these tend to fall under the “they don’t change very often” category and are often thought safe to stick in the code, especially in small utilites that are considered temporary one-offs. It doesn’t take much for today’s temporary one-off to become tomorrow’s permanent production software.

Just about every modern language and runtime comes with libraries and constructs that help integrate command line parameters, configuration (files, databases, JSON, consul, and so on) and options into your software. Get familiar with them and use them liberally. Take a blood oath to never use hard coded values again! Your future self and anybody else that picks up your code in the future will thank you

Scroll to Top