29 minutes ago · Tech · hide

In Design for Understandability, Jonathan Schuster argues that “[w]e can use ideas like design by contract, class invariants, modularity, and more to create systems that we can understand one piece at a time […]”. Fully agree. However, the author then suggests to implement this using plain text comments in code. That’s baffling: We have tools and languages to actually test, enforce or even prove such guarantees. Comments are not contracts. To follow up on the last point, the main example in the article is about this function: // Implements binary search int binarySearch(String[] list, String t) { ... } That’s the starting point, the “bad” code, which doesn’t provide any guarantees. The “good” code looks like this: // If the list is sorted, returns the index of the first // occurence of t in the list, or -1 if not found. // Behavior is undefined for unsorted lists. int binarySearch(String[] list, String t) { ... } Wat. The only difference is in the plain text informal English language…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town