Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What (besides the words if and else and the curly braces) makes the if/else equivalent more verbose)?


In C and C++, ternaries are frequently used on the right hand side of an assignment statement. if/else can't be used in such a context.

Here's a concrete example:

    const int min = x < y ? x : y;

    int min;
    if (x < y)
        min = x;
    else
        min = y;
Note also that this prevents variable min from being made const, unless you are using c++ and wrap the entire if/else in an immediately invoked lambda, which of course would require additional verbosity.




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

Search: