Actions

EmSys

CCoding Style - Be Clear3

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Be Clear ...

The ?: operator is fine for short expressions where it can replace four lines of if-else with one, as in

max = ( a > b ) ? a : b;
  • Clarity is not the same as Brevity

Often the clearer code will be shorter, as in the bit-shifting example, but it can also be longer; as in the conditional expression recast as if-else.

  • The proper criterion is ease of understanding.