DEV Community

Discussion on: What do you think about the ternary operator?

Collapse
 
cathodion profile image
Dustin King

I think languages need it. I think it's necessary for making the code flow in the same order as how things work in your mind. But I don't think it improves readability except in Lisp (because it's just a regular If statement).

In Lisp (It's been a few years, so forgive me any syntax errors) it's:

(setq variable (if condition something somethingElse))

In Python what it actually is is:

variable = something if condition else somethingElse

Whereas I'd like it to be:

variable = if condition something else somethingElse