Question: I just saw this block of code on the [Wikipedia](http://en.wikipedia.org/wiki/%3F:#.3F:_in_style_guidelines) article on conditional operators:

```
Vehicle new_vehicle = arg == 'B' ? bus      :
                      arg == 'A' ? airplane :
                      arg == 'T' ? train    :
                      arg == 'C' ? car      :
                      arg == 'H' ? horse    :
                      feet;

```

I've changed the code a little, but the idea is the same. Would you find this use of the conditional operator acceptable? It's much more concise than the `if`-`else` construct, and using a switch would definitely open up a whole new set of opportunities for bugs (fall-throughs anyone?). Also, `if`-`else`s and `switch` can't be used as R-values, so you'd have to create the variable first, initialize it and then assign as necessary.

I for one really like this, but I'm wondering what others think.

But the formatting is essential.

EDIT: I still like this. But I understand those who say "the `switch` statement was made for this". OK, maybe so. But what if the conditions are function calls that return `bool`? Or a million other things you can't switch on.

Are you switch lovers really trying to convince me that a huge `if`-`else` chain is better? Yes, programmers who don't know how to use the conditional operator will not understand this. They should learn how to use it. It's not arcane.

Answer: 
This is a great example of conditional operator use. I use it in this manner all the time in C++, Java, and Perl.
In my opinion what you've done is acceptable due to the simplicity of the example. If you were doing more things with each case this type of construct could rapidly get messy. For that reason I would prefer a switch or even nested if then elses (if there aren't too many cases), formatted as follows:

```
  if (A) {
      //Do A stuff
  }
  else if (B) {
      //Do B stuff
  }
  else if (C) {
      //Do C stuff
  }
  else {
      //Do default stuff
  }

```

It's about the readability of the code, which lends itself to the maintainability of the code. I've never been a huge fan fan of the conditional operator, because I don't like to see multiple expressions on a single line. Conditional operators can be difficult to follow when single stepping the code in a debugger. The simpler the code the easier it is to concentrate on what the code is doing.