三元运营商和维护

A.R*_*.R. 0 c# maintenance code-readability

程序员A喜欢一些三元运算符,尤其是嵌套运算符.更好的是,他声称它们使代码更易于阅读和维护,因为它们可以适应更少的线路.程序员B认为,当三元嵌套时可读性会丢失,反过来代码变得难以维护.

看看下面的块:

private int MyFunction(bool condA, bool condB)
{
  // Programmer A says:
  // Nested ternary --> This is easier to read and maintain because it is on one line.  Ternaries can be nested 4 or 5 deep and it is no problem.
  return condA ? condB ? 20 : -10 : -20;

  // Programmer B says:
  // Unwrapped --> This is more readable as it better describes the step by step evaluation of the conditions and their results.
  if (!condA) { return -20; }
  if (!condB) { return -10; }
  return 20;
}
Run Code Online (Sandbox Code Playgroud)

其他人对这两种思想流派有什么看法?最好的方法是什么?

编辑:有更好的方法吗?

Dan*_*rth 8

显然,程序员A将"短"代码与"可维护和可读"代码混淆.