I've been naturally tending toward using more ternary operators and writing more branchless code over time. I find it generally elegant and compact. But it's true that it's a little less easy to debug step into or to set breakpoints for.

@ocornut Worth noting that this is largely a cosmetic decision.

Unless you use MSVC, which can be very annoying in following exactly what you wrote, not what is optimal.

Also MSVC: With /O2 you get branches even if you use ternary operator :)

https://gcc.godbolt.org/z/fMhr7qh7G

Compiler Explorer - C++

int f1(int a, int b, int c) { if(a>2137) return a*b; else return c; } int f2(int a, int b, int c) { return a>2137 ? a*b : c; }

@wolfpld @ocornut Ternary operator might not produce branchless code, but you can make it branchless often without it (a common trick when manually writing SIMD code).

https://gcc.godbolt.org/z/Pxa6nG6jo

Compiler Explorer - C++

int f1(int a, int b, int c) { if(a>2137) return a*b; else return c; } int f2(int a, int b, int c) { return a>2137 ? a*b : c; } int f3(int a, int b, int c) { int cnd = (a > 2137); int ab = a*b; return cnd * ab + !cnd * c; }