6 ms·
Your example, though, outright assumes the claim is false because you have different error rates for different languages. I agree the metric is coarse, but I t
by scott_s 17y ago
Your example, though, outright assumes the claim is false because you have different error rates for different languages.
I agree the metric is coarse, but I think it's a decent stand-in for things that matter. More lines of code tend to mean more concepts unrelated to the problem you're solving, more assumptions and a greater cognitive load. All of these introduce more opportunities for error. Consider the problem of concatenating a sequence of text, and putting commas inbetween each distinct entry. In Python:
concat = ','.join(texts)
In C++, this would be
string concat;
for (list<string>::const_iterator i = texts.begin(); i < texts.begin(); ++i) {
concat += *i;
}
There are more opportunities for me to make mistakes in the C++ code. I've introduced more concepts (using iterators to access a sequence, using iterators to access a value, building a string) which increase my cognitive load. Hence, I'm more likely to have more bugs in this code, despite solving the same problem.
I don't even want to write the C code to do this right now, because I would have to deal with the following concepts: allocating sufficient memory for the C-style strings and ensuring I'm not accidentally overflowing that memory; determining what kind of sequence texts is (native array or my own linked list?); determining how to iterate over that sequence, and how to "add" strings.
- gdp 17y agoRight, so doesn't that example go back to my original assertion that error rates differ between languages in reasonably intuitive ways?
- scott_s 17y agoI think we're using different reference points. I'm assuming that in a fixed amount of program text, the number of bugs across all languages is relatively constant. More text means more concepts and more opportunities to be wrong. I think your point is that for a given problem, different programming languages will yield solutions with variable number of bugs. In a language that is simpler to express the solution, it's more likely to be correct. These two points are compatible. I'm fixing the amount of program text, you're fixing the problem.
- gdp 17y agoFrom Withrow (1990), on ADA: Module LoC | Error Rate per 1k LoC 63 | 1.5 100 | 1.4 158 | 0.9 251 | 0.5 398 | 1.1 630 | 1.9 1000 | 1.3 >1000 | 1.4 This appears to show no such linear relationship between error rate and LoC within a single language, with a fixed amount of program text. This report appears to suggest an observed average error rate of 18 defects per 1000 lines of code: http://www.lanl.gov/projects/CartaBlanca/webdocs/PhippsPaperOnJavaEfficiency.pdf http://www.lanl.gov/projects/CartaBlanca/webdocs/PhippsPaper... and the same programmer generated an average of 6 defects per 1000 lines of code in Java. This is just a random sampling of error rates I could find quickly with a google search and a paper I already had on my desk, however the fact that three samples from three projects (two of which were from the same programmer) suggests that there is likely to be variation both in terms of the (fixed) amount of program text, and the problem between languages.
- blub 17y agoQString str = (QStringList() << "aa" << "bb" << "cc").join(","); Although the equivalent of the Python code would be: QString str = texts.join(",");