English subtitles

← 01-19 Are Assertions Used In Production

01-19 Are Assertions Used In Production

Get Embed Code
1 Language

Showing Revision 2 created 07/16/2014 by Udacity Robot.

  1. Something you might be wondering is do real developers
  2. put assertions into the code that they write?
  3. It turns out that often they do.
  4. I took a quick look at the GCC and the LLVM code bases.
  5. GCC is the GNU compiler collection.
  6. It contains not only the well-known C compiler and C++ compiler,
  7. but also a Java compiler, and an Ada compiler and a number of other tools,
  8. and the GCC source code base contains more than 9000 assertions.
  9. Now, the LLVM compiler suite contains about 13,000 assertions,
  10. and that's over about 1.4 billion lines of code
  11. for a total of about 1 assertion per 110 lines of code.
  12. Here I'm just counting raw lines of code, not source lines of code.
  13. This includes blanks, comments, and everything.
  14. What this tells us is that the LLVM and GCC developers
  15. have made a pretty serious commitment to checking assumptions,
  16. preconditions, post conditions, and invariant in the code that they wrote.
  17. One thing that I've done personally is reported a lot of compiler bugs
  18. to both the GCC and LLVM products,
  19. and one thing I've learned is that much of the time
  20. these bugs show up as assertion violations.
  21. Not always--sometimes these compilers seg fall to have other problems.
  22. But most of the time they're assertion violations.
  23. These assertions are actually succeeding at accomplishing the goals
  24. that we talked about on the left side of the screen here.