CS 371p Fall 2024: Rob Mayoff

Rob Mayoff

Blog #9

Your blog entry must explicitly answer the following questions about the class (mark the questions in bold in your post):

I was the first to finish the vector exercise on Monday. I also taught Prof. Downing how to eliminate a compiler warning about an unused variable in one of the test cases, and I showed him that none of the test cases tested the destructor.

I relied on my experience programming in C++.

After I finished the exercise, I helped a few classmates with it.

I will reproduce one of the comments I left on the paper in Perusall:

I like the DI principle, but I think Martin didn’t focus on where it matters most.

Every abstract interface Martin came up with has something in common: they are all entirely about side effects. Reading from keyboards, writing to printers or files, detecting button presses and toggling lamps are all side effects. They involve some external state or system. You can get a different character every time you ask for input. You make a lasting change to the world when you write to a printer or a file or toggle a lamp. You don’t know when or how often the button will be pressed.

Dependency inversion is most useful for managing side effects. It’s much easier to test your code when you can replace real I/O with virtual I/O, when you can replace the real database with a mockup, and when you can simulate user input instead of requiring actual mouse clicks.

In modern terms, the idea is called “imperative shell, functional core”, or “hexagonal architecture”. Implement as much of your program as possible in a pure, side-effect-free way, and keep the side-effecting parts on the periphery.

I didn’t any trouble with the exercise. I did have trouble with Ed Lessons taking away my ability to run the tests when I tried to test with a syntax error. I also received a 1 on the exercise, which was a shock. Fortunately, I was able to complain so effectively that my grade was changed to a 3.

I have no strong feelings about them. They are neither offensive nor endearing.

I received a 1 on the exercise and was sad. I asked on Ed why I received a 1 and a TA changed it to a three. Then I was happy.

My tip this week comes from Donald Rumsfeld, former United States Secretary of Defense. Although I disagreed with his political views, I agree with this observation, which applies to programming as well as politics:

Reports that say that something hasn’t happened are always interesting to me, because as we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know. And if one looks throughout the history of our country and other free countries, it is the latter category that tends to be the difficult ones.

See you next week!