I am Robert C. Martin (Uncle Bob). Ask me anything.

View original thread
Eric Lemes's photo

Thanks for this opportunity. I've read all your books, including some very old ones (like the C++ in Booch method) and they are all great. You influenced a lot my work and I'm really grateful for so many interesting ideas.

I wish I could ask one, but it will be a lot.

I've been working a lot with code metrics or any objective ways of measuring code quality based on static analysis. I've been getting some interesting data about this which I can discuss if you are interested. I've seen some suggested metrics, specially in Clean Code, about number of lines of code, number of arguments per method, coupling etc. and that's why a lot of my questions will be directed towards measuring code coverage and TDD (since there are loads of studies showing that TDD improves code quality).

  • Do you believe it is possible to objectively measure code quality analyzing code structure (number of lines, cyclomatic complexity, afferent and efferent coupling, code coverage)?
  • Do you believe good design can be measured objectively?
  • I've seen a lot of discussion in C++ about dynamic polymorphism being a performance issue (since it disables a lot of opportunities for compiler inlining, and since adds a pointer per class, can increase cache misses). What are your thoughts on this based on games or any other CPU intensive applications?
  • I know this is a curve ball, but, what do you think would be the ideal unit test code coverage (line and branch)? Why?
  • Knowing ideal code coverage can be tricky and sometimes irrelevant, what would be the lower limit? For examples, is 10% of code coverage relevant?
  • What would be the threshold when you start feeling improvement?
  • I've heard a lot of people stating that you can achieve high coverage numbers (for example 80%) and still have a pretty bad code. What are you thoughts on that?
Robert Martin's photo
  • Do you believe it is possible to objectively measure code quality analyzing code structure (number of lines, cyclomatic complexity, afferent and efferent coupling, code coverage)?

    You can get some information from these metrics. But you cannot determine code or design quality from them.

  • Do you believe good design can be measured objectively?

    Not with static analysis metrics. But I think good designers can pass appropriate judgements on good or bad design. In the end, there is only one metric that matters: Was the manpower required to build, deploy, and maintain the system appropriately minimized.

  • I've seen a lot of discussion in C++ about dynamic polymorphism being a performance issue (since it disables a lot of opportunities for compiler inlining, and since adds a pointer per class, can increase cache misses). What are your thoughts on this based on games or any other CPU intensive applications?

    When you need to save 3 nanoseconds, dynamic polymorphism is a factor. So in deep loops with tight real time deadlines, removing dynamic polymorphism is an option. In all other cases the cost is so small as to be nonexistent; and the advantages are so great as to be overriding.

  • I know this is a curve ball, but, what do you think would be the ideal unit test code coverage (line and branch)? Why?

    100%. Line and branch. Obviously. Of course you can probably never achieve this level; but it should still be the "ideal" (your word).

  • Knowing ideal code coverage can be tricky and sometimes irrelevant, what would be the lower limit? For examples, is 10% of code coverage relevant?

    Lower than 100% means you aren't done. Of course you 'll never really be done. But there is no stopping point lower than 100%.

  • What would be the threshold when you start feeling improvement?
    I've heard a lot of people stating that you can achieve high coverage numbers (for example 80%) and still have a pretty bad code. What are you thoughts on that?

    If you have 80% coverage, it means that 20% of the code might not work. That's not a good number. No one should be happy about 80% coverage.