C++ Coding Styles

Viewed 45

While browsing a colleagues code today, I stumbled over a notation that I haven't seen before:

#include <iostream>
using namespace std;

int main()
{
    int foo = 1;
    int baa = 2;
    int res = foo == 0 ? 3 : baa == 2 ? 4 : 5;
    cout << "res: " << res;
    return 0;
}

In particular the line int res = foo == 0 ? 3 : baa == 2 ? 4 : 5;, which seems to be a condition based allocation had me confused.

I'm currently on the fence about using this myself. After understanding it, I like it but fear that someone who has to maintain my code will have the same problem as I had. Is there a consensus about what is considered "clean code"? Is it always code that is "easy to understand"?

0 Answers
Related