C programming style

Eugene D. Brooks III brooks at lll-crg.ARPA
Thu Jul 18 15:26:27 AEST 1985


> I agree that "i++" is an abomination.  (I do use it, however, to be
> consistent with the rest of the code I work with.)  Actually, C has
> a third way to represent this operation: "i += 1".  Personally, I
> think this is the superior notation.  It is concise, yet easy enough
> for a person unfamiliar with the language to interpret.

The use of i++ when i+=1 will do is certainly an abomination!  I personally
always use i+=1 when i just want to increment i but an not going to use
its value in that expression.  For instance

	for(i = 0; i < DIM; i += 1)

People ask me WHY?  As it noted above everyone just uses i++.

I reserve the ++ and -- operators for when I an really doing something
special, incrementing or decrementing and using the value that existed BEFORE
the operation.  The occurence of ++ or -- in a program is a red flag telling the
reader that something very special is happening.

If you use ++ or -- when you simply want to decrement or increment then the
cases when its important to note the ordering of the operation and the returned
value of the expression get lost in the forest of ++s and --s an you get left
with buggy code.  Its the very much the crying wolf syndrome!



More information about the Comp.lang.c mailing list