DEV Community

Cover image for Why default values for environment variables should be avoided
Omar for ClickPesa

Posted on

2

Why default values for environment variables should be avoided

Assuming you expect a particular variable to be present, what should you do if it is not present? I say stop the application immediately.

Based on my experience, default values are the root of almost all evil in development. If you provide default values, means you do not care about the supplied value because you can at any time substitute it with something else.

It means you do not care about the supplied value because you can at any time substitute it with something else.


It is also a good practice to always split configuration from code.


Default values can make debugging a misconfigured application more difficult, as the final config values will likely be a combination of hard-coded default values and environment variables.

Relying purely on environment variables (or as much as possible) means you have a single source of truth for how your application was configured, making troubleshooting easier.

If you enjoyed this story, our blogs have more like it. Checkout dev.to/clickpesa, medium.com/clickpesa-engineering-blog or clickpesa.hashnode.dev

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay