CS 371p Fall 2024: Rob Mayoff

Rob Mayoff

Blog #3

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

I’m proud of finishing the class exercise quick enough to help other students finish it.

I used general programming skill and knowledge of prime numbers.

I helped them finish the exercise correctly.

It was a great, prescient, and influential paper in its time. It’s fun to see how much Fowler got right (ubiquitous version control, frequent syncing with the main branch, automated testing, virtual machines for build and test) and what Fowler didn’t predict at all (the almost complete domination of distributed version control, and Git in particular).

Fowler published an updated edition of the article in January 2024.

Assertions are great. I use plenty of them in my projects regardless of language. But they’re also more necessary in C++ than some other languages with stronger type systems. You don’t have to assert(ptr != nullptr) as much in a language that makes nullability part of the type system.

Unit tests are fine in general, but easily overdone. I didn’t feel a need for a unit test that converts my Grade enum values to string; it’s trivial code that and unit testing it is essentially just writing it twice. But to get 95% code coverage I was forced to add a unit test for it. I like integration tests much better, because in my experience a lot of bugs come from gluing components together. For example, I’ve written many bugs when hooking up the “core logic” to the UI. You’re not going to catch those bugs with unit tests. In my opinion, the best tests are usually the ones that act as much like the end user as possible, and end users aren’t calling my private helper functions directly.

Code coverage measurement is a useful tool for finding new tests to write, and I’ve used it on production code. It won’t force you to write every test you probably need, but it’s worth looking at. And as I said above, taking it too seriously may force you to write low-utility tests just to boost the number.

The is_prime function is a good exercise for a programming class, and you will never need to write it in your professional career. Unless your career is computer science professor.

Although Prof. Downing made some good arguments for passing arguments by reference, the danger is that you can’t tell at the call site that you’re passing the argument mutably: it’s not obvious that f(x) might mutate x, but it is obvious that f(&x) might.

One of my fellow students (whose name I have already forgotten, sorry!) told me that when she searched the web for more information about assertions and preconditions, she found a Stack Overflow answer and recognized me as the author. That was pretty cool.

My tip this week comes from the first Turing Award winner, Alan Perlis:

The best book on programming for the layman is “Alice in Wonderland”; but that’s because it’s the best book on anything for the layman.

See you next week!