SShortSingh.
Back to feed

Why Using 'or' for Default Config Values Is a Silent and Dangerous Bug

0
·1 views

A developer running a real-money trading bot discovered that a single line of code caused the bot to operate with an unintended default capital value for months. The root cause was using Python's 'or' operator to fall back to a default, which silently substitutes the default not only when a variable is missing but also when its value is zero or any other falsy value. When an environment variable was wiped during a system restore, the program raised no error and continued running with the hardcoded fallback undetected. The same flaw exists across languages, including JavaScript's '||' operator and Go's empty-string checks, making it a widespread anti-pattern in configuration handling. The recommended fix is to either require critical variables to be explicitly set — crashing loudly on absence — or use language constructs like Python's 'getenv(key, default)' or JavaScript's nullish coalescing operator '??' that distinguish between a missing value and a legitimate zero.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

How Chinese Super Apps Work Architecturally — And Why Flutter Cannot Replicate Them

Chinese super apps like WeChat, Alipay, and Douyin are software platforms built on three layers: a native host shell, an embedded mini-program runtime, and third-party mini-programs that update without going through app stores. The key technical component is the embedded script runtime, which executes isolated third-party code using JavaScript engines rather than natively compiled frameworks. Apple's App Store Guideline 2.5.2 prohibits apps from downloading or executing new native code post-review, which is why Flutter's AOT-compiled Dart binaries cannot legally serve as a dynamic mini-program runtime on iOS. Each major Chinese super app has developed its own proprietary JS-based engine — such as WeChat's MINA framework with its dual-thread JSCore architecture — to work within these platform constraints. The article outlines four Flutter-compatible approaches for developers seeking to build multi-service apps, while clarifying what is and is not achievable within the Flutter ecosystem today.

0
ProgrammingDEV Community ·

Developer builds offline cold email scorer in single HTML file, no dependencies

A B2B sales writer frustrated by vague cold-email advice built a deterministic email scoring tool packed into a single 220-line HTML file with no frameworks, APIs, or external dependencies. The tool accepts a subject line and body, then returns a score out of 100 across eight measurable checks including subject length, spam phrases, word count, readability, and call-to-action detection. The developer deliberately avoided AI model calls to ensure identical inputs always produce identical outputs and to eliminate privacy concerns around real sales emails. Every scoring threshold — such as a subject line ceiling of 55 characters and a body word count sweet spot of 50 to 150 — was manually justified and documented rather than delegated to a black-box model. The project is publicly available on GitHub under an MIT license.

0
ProgrammingDEV Community ·

Splitting React layout components improves accessibility and cross-framework portability

A developer discovered that a React design-system layout component broke when migrated to a Next.js App Router project, because the component assumed it owned both persistent chrome and per-page content in a single composition. Next.js separates layout and page ownership across different lifecycle boundaries, making that assumption invalid. The accessibility relationships — particularly a skip link targeting a focusable page heading via a shared ID — silently broke alongside the composition model. The fix involved splitting the single layout into two explicit components: a shell owning the skip link and landmark, and a page content component owning the focusable heading. Making the accessibility contract explicit between components, rather than hiding it inside one monolithic unit, restored both portability and correct focus behaviour.

0
ProgrammingDEV Community ·

Designer finds AI accelerates UI/UX execution without replacing core design thinking

A UI/UX designer sharing on DEV Community reports that integrating AI tools into their workflow has significantly sped up the process from concept to tangible prototype. The designer follows a structured pipeline — from product requirements and user flows to wireframes, AI-assisted exploration, and testing — where AI aids ideation but not decision-making. Key design judgments, such as what to build, what to cut, and how to serve users, remain entirely the designer's responsibility. The designer notes that AI tools are improving rapidly each month, making it increasingly important to use them without sacrificing the reasoning behind design choices. The post concludes with an open question to the community about their own experiences using AI in design or development workflows.

Why Using 'or' for Default Config Values Is a Silent and Dangerous Bug · ShortSingh