DEV Community

Cover image for Code Smell 186 - Hardcoded Business Conditions
Maxi Contieri ⭐⭐⭐
Maxi Contieri ⭐⭐⭐

Posted on • Originally published at


Code Smell 186 - Hardcoded Business Conditions

You are FTX and your code allows special cases

TL;DR: Don't add hard business rules to your code.


  • Open / Closed Principle Violation

  • Hardcoding

  • Testability


  1. Reify the condition.

  2. Create configuration options and set the exception on the configuration behavior.

  3. Don't use Settings/Configs.


According to Reuters, in a recent FTX scandal, there was a hardcoded condition to skip risk controls to its own portfolio.

The code was explicit and developers were aware of that rule.

Sample Code


if (currentExposure > 0.15 && customer != "Alameda") {
  // Be extra careful not to liquidate

Enter fullscreen mode Exit fullscreen mode



  // This follows the Tell, Don't ask principle
Enter fullscreen mode Exit fullscreen mode


[X] Semi-Automatic

We can search for primary hardcoded conditions (related to primitive types).

We might have more false positives than actual problems.


  • Hardcoding


If you make code reviews, pay special attention to this kind of hard coding.


More Info


Code Smells are just my opinion.


Photo by Alexander Mils on Unsplash

Computer science inverts the normal. In normal science, you're given a world, and your job is to find out the rules. In computer science, you give the computer the rules, and it creates the world.

Alan Kay

This article is part of the CodeSmell Series.

Top comments (0)

11 Tips That Make You a Better Typescript Programmer


1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!