CS111A is an Intro level course at CCSF (CIty College of San Francisco). I indulged in introducing DeMorgan's Law while getting the students started on Boolean operators. It didn't go down perfectly so I'm making a few corrections here.
DeMorgan's Law is a neat property of Boolean functions. Read about them in detail here on Wikipedia. Easier understood when written out as expressions than dictated in simple English, DeMorgan's Law basically says:
!(A & B) = !A | !B
!A & !B = !(A | B)
I had students verify this property by writing out Truth Tables in class. I had them write out AND and OR tables. Then, I had them write out XOR tables which one of the students presented in class. Finally, I had them translate a piece of code into two equivalent Boolean expressions:
For example, the following:
!(state.equals("CA") || (state.equals("HI"))
is equivalent to:
!state.equals("CA") && !state.equals("HI")
I asked students to write on paper what the Truth Tables for each of those expressions. I walked around the classroom and found one student who figured out how this worked and another who also arrived at the right solution. I asked them to each present their one column of their answer. The point was to show that thinking through each of the expressions will actually result in the same answer.
Even though the two approaches looked to be correct and seemed to arrive at the same correct answer on first glance, it turns out that there was actually a mistake (captured on camera!):
In class, I had only paid attention to the result of the two columns appearing the same. Looking under the hood, however, things weren't quite right. I just didn't catch it.
Unfortunately, neither did anyone in the class. I'll go over this again next class, maybe with a handout to fill in. Boolean logic tables are important to understand. After all, computers can only count on one finger. At this introductory level where the specific language doesn't make a terribly big difference in understanding the basics of programming, it's very important to understand the basic abstract principles. Not everyone is going to turn out to be a superstar software programmer a few years from now, but everyone will benefit from a little bit of logic. I'm convinced we need to slow down a bit to catch our own mistakes, even when the answer appears to be correct.