Hacker News new | past | comments | ask | show | jobs | submit login

  enum situation { boring, clear, cleaver }
    if context.proves(cond1)
      return cleaver
    if context.proves(cond2)
      return clear
    return boring

    switch( selector(context) )
      cleaver: make_something_cleaver()
      clear: make_something_clear()
      default: make_something_stupid_simple()
Not completely the same situation, though, as there are no assignation here. For simple cases (`v = e0 ? e1 : e2`), ternary operator sure is fine, but for more complex cases, `some_var = selector(context)` tend to be a clearer path. That will also be better rendered in your API as the function fine documentation will have more chance to be extracted properly.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact