Back to bookshelf

Observation, code equivalance, and bugs | CS 140E 

Appreciation
8
Importance
7
Date Added
1.8.26
TLDR
If an observer cannot tell the difference between two things (e.g., snippets of code) then they are effectively equivalent and can be substituted for one another. This causes many problems because of differing choices of what the observer is (the stronger the observer is, the less that can be changed and thus optimized!). Exercises and many further readings included here.
2 Cents
--
Tags
  • As-if substitution principle: if an observer cannot tell the difference between X and X' they can be substituted for one another.
    • This happens everywhere (e.g., hardware optimization) but is rarely talked about explicitly.
  • The compiler substitutes code too, but this is very bad if we have a different definition of an observer.
    • The strongest observer is good for correctness but bad for speed (and vice versa).
  • Specifically: “C does not know about threads, interrupts, or hardware devices!!!”
    • One method to handle this problem is to use volatile. We don't do this and there are many cases  against doing this.