Hacker News new | ask | show | jobs
by bruce343434 37 days ago
Because you can deduplicate certain parts of the logic which make the whole thing less error prone, such as

    if c
      x=1
    else
      x=2
If I ever want to change x, or refactor this code some other way, its a more brittle process over x=c?1:2

The ternary expression also takes up much less space so there is less of an emphasis on it, this can be a stylistic tool in a programmer's toolbox

1 comments

the oposite is also true, you can have misleading side effects coming from joining things into a single expression