0
Заплановано

Refactoring: Ternary Statements: Using Ternaries for their Side Effects

Norpyx 10 місяців тому оновлено Alexander 10 місяців тому 3

I think a great addition to the Conditionals portion of the Refactoring Guides would be to discourage using Ternary Expressions as Statements. This is highly discouraged, and you don't see it often, but it's been known to be present in some very, very legacy code. I've witnessed certain devs finding it in legacy code and using it because it's novel, and it tends to add to code clutter and can severely increase cognitive load when sifting through complex conditionals.

Example:

DON'T:

const foo = "bar";
foo === "bar" ? quux() : zim();

DO:

const foo = "bar";
if (foo === "bar") {
    quux()
} else {
    zim();
}

DIR2.0
This effectively comes down to:
- Don't use Ternary Expressions as Statements
+1
Заплановано

Hi!

This is a good one. I'll add it to my todo.