Hacker News new | ask | show | jobs
by zamalek 2112 days ago
Ruby currently supports "Rightward conditionals":

    user.delete() if deleteUser
It is probably thought that this feature would result in similar readability improvements.
2 comments

Python has the same "rightward conditional" thing.

Any time I use it, I wish python had just gone with the normal ternary (? :) operator.

> Python has the same "rightward conditional" thing.

No, python writes the ternary operator with words, it doesn't have rightward conditionals.

The key difference is that the else clause is required in the Python ternary, where it's optional in a conditional.

Doesn't make it any less irritating.
I don't find that more readable at all. I prefer:

    if deleteUser
      user.delete()
    end
It's easier for me to read. It doesn't try to hide away logic. And if the line gets longer if the conditional gets more complex or I want to add an else I can without reformatting.
It works well for some cases. You end up with

return if a.nil? return if attempts < max_attempts

In this case "return if" becomes like a keyword and you can ignore it and focus on the rest of the expression. It also seems very readable for other simple values like `return false if ...`. But I agree, as soon as the code to the left of the `if` gets non-trivial it is harder to read.

It's subjective, the point is that some people prefer it.