I'm currently a student in college learning, and for the most part enjoying, the wonderful world of programming. I'm lucky enough to know about SO, and have a friend who's been in the game since he was fairly young, so I get exposed to some things that haven't come up in class.
One such thing was the conditional ?: operator. I had no idea it existed until a few days ago. I'm not sure how I feel about using it on my current project, though. I work in an environment of almost entirely non-programmers. The program I'm currently translating from VB6 to C# was written by a mechanical engineer (and breaks some basic programming tenets, like unnecessary use of gotos). I was hoping somebody would be able to give me the benefits and drawbacks of the ?: operator as opposed to the standard if-else statement. The obvious ones being:
Conditional ?: Operator
- Shorter and more concise when dealing with direct value comparisons and assignments
- Doesn't seem to be as flexible as the if/else construct
Standard If/Else
- Can be applied to more situations (such as function calls)
- Often are unnecessarily long
Readability seems to vary for each depending on the statement. For a little while after first being exposed to the ?: operator, it took me some time to digest exactly how it worked. Would you recommend using it wherever possible, or sticking to if/else given the nature of the generally-non-programming environment I'm in?