0
Planned

Refactoring: Ternary Statements: Using Ternaries for their Side Effects

Norpyx 3 Π³ΠΎΠ΄Π° Π½Π°Π·Π°Π΄ β€’ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ Alexander 3 Π³ΠΎΠ΄Π° Π½Π°Π·Π°Π΄ β€’ 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();
}

БСрвис ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΠΎΠ² Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π½Π° ΠΏΠ»Π°Ρ‚Ρ„ΠΎΡ€ΠΌΠ΅ UserEcho