DEV Community

Discussion on: Stop using if else

Collapse
 
danielgomezrico profile image
Daniel Gomez

Can you share why would this be more readable/maintainable? I'm worried about you saying that this is "more readable and maintainable" without giving quality arguments about why that's true, that may let people believe that this is a must always.

I just went into a discussion about this topic, and some people argue that:

const condition = true

const value = {
   false: "first",
   true: "second
}[condition]
Enter fullscreen mode Exit fullscreen mode

Is better than a simple if like:

const value = condition? "first" : "second"
Enter fullscreen mode Exit fullscreen mode

This is an abuse/overuse of a language feature or structure which involves more concepts and more time on your brain in order to understand what is happening when you read it.

I also believe that this enlarge possible problems in devs minds like "Primitive types obsession" and "Declarative Dilussion", check:

WDYT?

Some comments have been hidden by the post's author - find out more