Mostly Linux & Python syntax notes and hyperlinks.

Monday, January 25, 2016

Quotes and Notes from 'Becoming a Better Programmer' - Chapters 9-10

From O'Reilly e-book:
Becoming a Better Programmer by Pete Goodliffe

Chapter 9 - Expect the Unexpected

Any function you call may not work as you expect.
• If you are lucky, it will return an error code to signal this.
(p.69)
p.70:
  •  understand basic concurrency principles
    • Understand mechanisms to reliably and quickly pass messages between thread contexts without introducing race conditions or blocking the threads unnecessarily
  •  Shutdown:
    • how to bring the code to a graceful halt without leaking resources, locking up, or crashing
    • especially hard in a multithreaded system
      • don't leave one object attempting to use or return to another that has been deleted

Chapter 10 - Bug Hunting

  • Lay Traps: Add assertions or tests to verify the system invariants—the facts that must hold for the state to be correct. (p.78)
  • Binary Chop: (p.78)
    • Work out the start of a chain of events.
    • Work out the end
    • Check middle point
      • if good, then start to middle is good, so check midpoint of here to end
      • if bad, then check midpoint of start to this point
  • Software Archaeology
    • Look thru your version control to find the last time this bug didn't exist
    • Binary chop through time to find where bug was introduced
  • Use a code coverage tool to inspect how much of your code is actually covered by tests. (p.79)
  • Once you find the bug:
    • Write a simple test that demonstrates the bug.
      • Add it to the test suite before you fix the code.
        • Use the test to:
        • prove bug is fixed
        • test to prevent bug from reoccurring
    •  Analyze/look for related bugs
      • Are there more bugs in the section where you found this one?
      • Was bug in a repeated code pattern that's used elsewhere?
    • Note in which parts of the code you're finding more bugs.
      • Part of code that's used most often?
      • Weakness in that particular section of the software? 
  • Non-Reproducible Bugs
  • Keep records that may eventually help you come up with theories you can test to possibly find the cause.
  • Add more assertions and log statements -- preferably into your beta or release builds.
  • Automate a test farm to run long-running soak tests.
  • Common situations leading to hard-to-reproduce bugs:
  • Threads
  • "Heisenbugs" - disappear when you add log statements
  • Network interacation
  • Speed to access database, disk, other storage can vary
  • Memory corruption
  • Global variables

No comments:

Post a Comment