Unused variables and bugs

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 22 16:32:53 PDT 2014


On 08/22/2014 11:46 PM, bearophile wrote:
> Timon Gehr:
>
>> http://xkcd.com/552/
> ...

My point is just that this correlation is not a strong data point 
supporting putting effort into elimination of unused variables. It is 
possible that all this will accomplish is that unused variables will no 
longer be an indicator of code quality.

> What better alternative do you suggest in practice?

Write the code carefully and convince yourself and possibly others that 
it is correct. Time is much more effectively spent attempting to improve 
code quality rather than attempting to improve metrics that have been 
shown to correlate with code quality in the past. Of course, the lint 
may prove useful during such endeavours as well; it's just the 
interpretation of the lint results that should be different. Given that 
one believes in the accuracy/generalizability/etc of the data from the 
OT, and if the lint gives many warnings, then this should indicate that 
maybe one should go over the surrounding code again carefully, not that 
one should just quickly fix the specific issues that the lint 
highlighted as you seemed to suggest in the OT.

The correlation only indicates that poor code tends to have more unused 
variables. If one eliminates unused variables just for the sake of 
eliminating unused variables, code quality will most likely not 
magically increase.


> The only better
> solution I remember that was used for a language design is the ":" added
> to Python after some controlled experiments done on users.
>
> Relying on experimental correlations (if the analysis is done well)

The experiment/analysis is done well if it would likely disprove a 
hypothesis that further reasoning will be based on if it was wrong, but 
hasn't done so.

> seems sometimes better than the usual beers&intuition-based

My own intuition is that 'no unused variables' and code quality might 
have a common cause in a setting where unused variables are not 
artificially eliminated, but this might be off as well. If reasoning is 
to be based on experiments, the experiments should be cleverly targeted 
at the right hypothesis. It does not suffice to say that past 
experiments gave results that were consistent with one's intuitive 
interpretation of reality in order to support this interpretation if the 
experimental results would also support a variety of other 
interpretations just the same way.

> ways most language features are chosen and designed :-)
>

Your source apparently also claims that code that has many comments has 
more errors:
https://kev.inburke.com/slides/errors/#error-correlations-2
I.e. to increase code quality one should delete comments?


More information about the Digitalmars-d mailing list