Actions

EmSys

CCoding Style - Be Clear

From EdWiki

Revision as of 06:51, 7 March 2012 by Jshankar (Talk | contribs) (1 revision)

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

Be Clear

  • Programmer’s endless creative energy is some times used to write the most concise possible code, or to find clever ways to achieve a result.
subkey = subkey >> ( bitoff – ( (bitoff >> 3) << 3 ) );

is equivalent to

subkey = subkey >> (bitoff & 0x7)
  • It takes a while to puzzle out what the first version is doing; the second is shorter and clearer.
subkey >>= bitoff & 0x7;