mardi 3 mars 2015

Bad sign if nobody can comprehend one's code? [duplicate]



If a coder writes code that nobody other than he can understand, and code reviews always end with the reviewer scratching his head or holding their head in their hands, is this a clear sign that the coder is simply not cut-out for professional programming? Would this be enough to warrant a career change? How important is comprehensible code in this industry?


Consider these C examples, compare:



if (b)
return 42;
else
return 7;


versus:



return (b * 42) | (~(b - 1) * 7);


Is there ever an excuse to employ the latter example? if so, when and why?


EDIT: Leaving the original latter snippet for consideration, adding a correction:



return (b * 42) | ((b - 1) & 7);


I think the other interesting observation is that it requires that b is 1 for true and 0 for false, any other values would render strange results.





Aucun commentaire:

Enregistrer un commentaire