| Actually, this line: /* Set expansion level */ expansion = atoi(argv[++i]);
Is an example of ugly code. They're doing multiple things in one line, and in a confusing order.# Increment i by 1. # Grab the command line argument in position i # Convert from string to integer. # Assign to the variable expansion. Note that there's no error checking to handle strings that don't convert to ints. Arguably, any serious C developer can read this on the fly, but I seriously object to code with side-effects like the above ++i. It's often confusing to read and change. I'm not criticizing the original author, more nit-picking on this as an example of great code. |
The comment is the worst part. It is useless, it literally repeats the most obvious part of the code. A good comment would be something like "there is no error checking because arguments are already validated in the GUI, also 0 is an acceptable default".
For me, comments should not repeat what the code is doing. Comments are for expressing what is in the the mind of the developer that cannot be expressed in code. Example : "constant found using empirical testing", "Hermite spline formula" or "required on Windows". (Edit: the Hermite spline example is actually a bad one, a better idea would be to write a function called hermite_spline_formula instead)
If some coding rule require you to comment, find something to say about your code that isn't your code. It will also help you think more about what you just wrote.