PROPOSAL: Conditional Statement

Joseph D. Darcy Joe.Darcy at Sun.COM
Sun Mar 29 20:18:47 PDT 2009


Matt Mastracci wrote:
> Neal,
>
> There are a number of small benefits, IMHO:
>
> 1.  The conditional syntax takes up a single line for simple choice,  
> vs. 3 or 5 lines (depending on whether your IDE inserts braces for  
> simple if statements) using the normal if syntax.  This makes it  
> easier to scan source, but doesn't decrease readability.
>
> 2.  When changing the return value of a function that uses  
> conditionals from int to void, you currently have to expand the  
> conditional out or assign the value to an unused temporary:
>
> public int foo() {
>      return flag ? bar() : baz();
> }
>
> Old refactorings:
>
> public void foo() {
>      if (flag) {
>          bar();
>      } else {
>          baz();
>      }
> }
>
> @SuppressWarnings("unused")
> public void foo() {
>      int unused = flag ? bar() : baz();
> }
>
> New refactoring:
>
> public void foo() {
>      flag ? bar() : baz();
> }
>
> 3.  Consistency with the conditional expression.  There's no way to  
> take advantage of the conditional operator for functions with void  
> return types.  By creating a construct where this is possible, it  
> makes the language more consistent.
>   

I don't find these benefits to be sufficiently large to warrant adding a 
new statement form.

-Joe



More information about the coin-dev mailing list